Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit fa1b318

Browse files
authored
Merge pull request #46 from Virtuoel/feature/iforgeitem
IForgeItem
2 parents 566f0d1 + 553068e commit fa1b318

17 files changed

Lines changed: 1645 additions & 0 deletions

File tree

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
**IForgeItem TODOs**
2+
3+
----
4+
5+
**NYI Classes**
6+
7+
ICapabilityProvider
8+
9+
ToolType
10+
11+
ITimeValue
12+
13+
----
14+
15+
**Misc**
16+
17+
Move temporary BEACON\_PAYMENT field to net.minecraftforge.common.Tags
18+
19+
Default impl of ForgeHooks.getDefaultCreatorModId
20+
21+
----
22+
23+
**Method call locations**
24+
25+
Call location classes in **bold** indicate the class is calling the ItemStack or IForgeItemStack version of the method instead of the IForgeItem one
26+
27+
Patches: LivingEntity, ItemStack
28+
Multimap<String, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack)
29+
30+
Patches: **PlayerEntity**
31+
Forge classes: IForgeItemStack
32+
boolean onDroppedByPlayer(ItemStack item, PlayerEntity player)
33+
34+
Patches: InGameHud
35+
String getHighlightTip(ItemStack item, String displayName)
36+
37+
Patches: **PlayerController**, ItemStack, **ServerPlayerInteractionManager**
38+
Forge classes: IForgeItemStack
39+
ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context)
40+
41+
Patches: **RepairItemRecipe**, **GrindstoneContainer**
42+
Forge classes: IForgeItemStack
43+
boolean isRepairable(ItemStack stack)
44+
45+
Patches: **ExperienceOrbEntity**
46+
Forge classes: IForgeItemStack
47+
float getXpRepairRatio(ItemStack stack)
48+
49+
Patches: **PacketByteBuf**
50+
Forge classes: IForgeItemStack
51+
CompoundTag getShareTag(ItemStack stack)
52+
53+
Patches: **PacketByteBuf**
54+
Forge classes: IForgeItemStack
55+
void readShareTag(ItemStack stack, @Nullable CompoundTag nbt)
56+
57+
Patches: **ClientPlayerInteractionManager**, **ServerPlayerInteractionManager**
58+
Forge classes: IForgeItemStack
59+
boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, PlayerEntity player)
60+
61+
Patches: **LivingEntity**
62+
Forge classes: IForgeItemStack
63+
void onUsingTick(ItemStack stack, LivingEntity player, int count)
64+
65+
Forge classes: ForgeHooks
66+
boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity entity)
67+
68+
Patches: **BannerDuplicateRecipe**, **BookCloningRecipe**, **Recipe**, **BrewingStandBlockEntity**, **AbstractFurnaceBlockEntity**
69+
Forge classes: IForgeItemStack, ForgeHooks
70+
ItemStack getContainerItem(ItemStack itemStack)
71+
72+
Patches: **BannerDuplicateRecipe**, **BookCloningRecipe**, **Recipe**, **BrewingStandBlockEntity**, **AbstractFurnaceBlockEntity**
73+
Forge classes: IForgeItemStack, ForgeHooks
74+
boolean hasContainerItem(ItemStack stack)
75+
76+
Patches: **ItemEntity**
77+
Forge classes: IForgeItemStack, ForgeEventFactory
78+
int getEntityLifespan(ItemStack itemStack, World world)
79+
80+
Forge classes: ForgeInternalHandler
81+
boolean hasCustomEntity(ItemStack stack)
82+
83+
Forge classes: ForgeInternalHandler
84+
Entity createEntity(World world, Entity location, ItemStack itemstack)
85+
86+
Patches: **ItemEntity**
87+
Forge classes: IForgeItemStack
88+
boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity)
89+
90+
Patches: PlayerController, **ClientPlayerInteractionManager**, **ServerPlayerInteractionManager**
91+
Forge classes: IForgeItemStack
92+
boolean doesSneakBypassUse(ItemStack stack, ViewableWorld world, BlockPos pos, PlayerEntity player)
93+
94+
Patches: PlayerInventory
95+
Forge classes: IForgeItemStack
96+
void onArmorTick(ItemStack stack, World world, PlayerEntity player)
97+
98+
Patches: **PlayerContainer**
99+
Forge classes: PlayerArmorInvWrapper, IForgeItemStack
100+
boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity)
101+
102+
Patches: **MobEntity**
103+
Forge classes: IForgeItemStack
104+
EquipmentSlot getEquipmentSlot(ItemStack stack)
105+
106+
Patches: **AnvilContainer**
107+
Forge classes: IForgeItemStack
108+
boolean isBookEnchantable(ItemStack stack, ItemStack book)
109+
110+
Patches: ArmorFeatureRenderer
111+
Forge classes: ForgeHooksClient
112+
String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type)
113+
114+
Patches: Screen, AbstractContainerScreen, CreativeInventoryScreen
115+
TextRenderer getFontRenderer(ItemStack stack)
116+
117+
Patches: ArmorBipedFeatureRenderer
118+
Forge classes: ForgeHooksClient
119+
<A extends BipedEntityModel<?>> A getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, A \_default)
120+
121+
Patches: **LivingEntity**
122+
Forge classes: IForgeItemStack
123+
boolean onEntitySwing(ItemStack stack, LivingEntity entity)
124+
125+
Forge classes: ForgeIngameGui
126+
void renderHelmetOverlay(ItemStack stack, PlayerEntity player, int width, int height, float partialTicks)
127+
128+
Patches: ItemStack
129+
int getDamage(ItemStack stack)
130+
131+
Patches: ItemRenderer
132+
boolean showDurabilityBar(ItemStack stack)
133+
134+
Patches: ItemRenderer
135+
double getDurabilityForDisplay(ItemStack stack)
136+
137+
Patches: ItemRenderer
138+
int getRGBDurabilityForDisplay(ItemStack stack)
139+
140+
Patches: **GrindstoneContainer**, **RepairItemRecipe**, **AnvilContainer**, ItemStack
141+
Forge classes: **ForgeHooks**
142+
int getMaxDamage(ItemStack stack)
143+
144+
Patches: ItemStack
145+
boolean isDamaged(ItemStack stack)
146+
147+
Patches: ItemStack
148+
void setDamage(ItemStack stack, int damage)
149+
150+
Patches: ItemStack
151+
boolean canHarvestBlock(ItemStack stack, BlockState state)
152+
153+
Patches: ItemStack
154+
int getItemStackLimit(ItemStack stack)
155+
156+
Patches: MiningToolItem
157+
Forge classes: IForgeItemStack, **ForgeHooks**
158+
Set<ToolType> getToolTypes(ItemStack stack);
159+
160+
Forge classes: IForgeItemStack, ForgeHooks
161+
int getHarvestLevel(ItemStack stack, ToolType tool, @Nullable PlayerEntity player, @Nullable BlockState blockState)
162+
163+
Patches: EnchantmentHelper
164+
Forge classes: IForgeItemStack
165+
int getItemEnchantability(ItemStack stack)
166+
167+
Patches: Enchantment, EnchantmentHelper
168+
Forge classes: IForgeItemStack
169+
boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
170+
171+
Patches: **BeaconContainer**
172+
Forge classes: IForgeItemStack
173+
boolean isBeaconPayment(ItemStack stack)
174+
175+
Forge classes: ForgeHooksClient
176+
boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
177+
178+
Patches: ClientPlayerInteractionManager
179+
Forge classes: IForgeItemStack
180+
boolean shouldCauseBlockBreakReset(ItemStack oldStack, ItemStack newStack)
181+
182+
Forge classes: ForgeHooks
183+
boolean canContinueUsing(ItemStack oldStack, ItemStack newStack)
184+
185+
Patches: ItemStack
186+
ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt)
187+
188+
Patches: MobEntity, PlayerEntity
189+
Forge classes: IForgeItemStack
190+
boolean canDisableShield(ItemStack stack, ItemStack shield, LivingEntity entity, LivingEntity attacker)
191+
192+
Patches: MobEntity, PlayerEntity
193+
Forge classes: IForgeItemStack
194+
boolean isShield(ItemStack stack, @Nullable LivingEntity entity)
195+
196+
Forge classes: IForgeItemStack, **ForgeHooks**
197+
int getBurnTime(ItemStack itemStack)
198+
199+
Patches: HorseEntity
200+
Forge classes: IForgeItemStack
201+
void onHorseArmorTick(ItemStack stack, World world, MobEntity horse)
202+
203+
Patches: ItemRenderer, DynamicBlockRenderer
204+
ItemDynamicRenderer getTileEntityItemStackRenderer()
205+
206+
Patches: MinecraftClient
207+
Set<Identifier> getTags()
208+
209+
Patches: ItemStack
210+
<T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken)
211+
212+
----
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
archivesBaseName = "patchwork-extensions-item"
2+
version = getSubprojectVersion(project, "0.1.0")
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.impl.extensions.item;
21+
22+
import java.util.Map;
23+
import java.util.concurrent.Callable;
24+
import java.util.function.Supplier;
25+
26+
import net.minecraft.client.render.item.ItemDynamicRenderer;
27+
import net.minecraft.item.Item;
28+
29+
import net.fabricmc.api.EnvType;
30+
import net.fabricmc.api.Environment;
31+
32+
/**
33+
* Forge does this through patching the constructor, we just add methods with
34+
* mixins instead.
35+
*/
36+
public interface PatchworkItemSettingsExtensions {
37+
Item.Settings setNoRepair();
38+
39+
Item.Settings addToolType(Object /* TODO: ToolType */ type, int level);
40+
41+
Item.Settings setTEISR(Supplier<Callable<ItemDynamicRenderer>> teisr);
42+
43+
boolean canRepair();
44+
45+
Map<Object /* TODO: ToolType */, Integer> getToolClasses();
46+
47+
@Environment(EnvType.CLIENT)
48+
ItemDynamicRenderer getTeisr();
49+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.extensions.item;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.gen.Accessor;
24+
25+
import net.minecraft.tag.ItemTags;
26+
27+
@Mixin(ItemTags.class)
28+
public class ItemTagsAccessor {
29+
@Accessor
30+
public static int getLatestVersion() {
31+
throw new UnsupportedOperationException();
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.extensions.item;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import net.minecraftforge.common.extensions.IForgeItem;
24+
25+
import net.minecraft.entity.LivingEntity;
26+
import net.minecraft.item.AxeItem;
27+
import net.minecraft.item.ItemStack;
28+
29+
@Mixin(AxeItem.class)
30+
public abstract class MixinAxeItem implements IForgeItem {
31+
@Override
32+
public boolean canDisableShield(ItemStack stack, ItemStack shield, LivingEntity entity, LivingEntity attacker) {
33+
return true;
34+
}
35+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.extensions.item;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import net.minecraftforge.common.extensions.IForgeItem;
24+
25+
import net.minecraft.item.EnchantedBookItem;
26+
import net.minecraft.item.Item;
27+
import net.minecraft.item.ItemStack;
28+
import net.minecraft.nbt.ListTag;
29+
import net.minecraft.util.Identifier;
30+
import net.minecraft.util.registry.Registry;
31+
32+
@Mixin(EnchantedBookItem.class)
33+
public abstract class MixinEnchantedBookItem implements IForgeItem {
34+
@Override
35+
public String getCreatorModId(ItemStack itemStack) {
36+
final Item item = itemStack.getItem();
37+
final Identifier defaultId = Registry.ITEM.getDefaultId();
38+
final Identifier id = Registry.ITEM.getId(item);
39+
40+
if (defaultId.equals(id) && item != Registry.ITEM.get(defaultId)) {
41+
return null;
42+
} else {
43+
final String namespace = id.getNamespace();
44+
45+
if ("minecraft".equals(namespace)) {
46+
final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack);
47+
48+
if (enchantments.size() == 1) {
49+
final Identifier enchantmentId = Identifier.tryParse(enchantments.getCompoundTag(0).getString("id"));
50+
51+
if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) {
52+
return enchantmentId.getNamespace();
53+
}
54+
}
55+
}
56+
57+
return namespace;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)