Allow support for custom Shields and Shield disabling weapons.

This commit is contained in:
Madsthunder 2017-07-20 17:44:37 -04:00 committed by LexManos
parent df6b628140
commit ad15209f8d
8 changed files with 275 additions and 6 deletions

View File

@ -39,3 +39,12 @@
public float func_70603_bj()
{
return 1.0F;
@@ -1003,7 +1015,7 @@
}
else
{
- return p_184640_0_.func_77973_b() == Items.field_185159_cQ ? EntityEquipmentSlot.OFFHAND : EntityEquipmentSlot.MAINHAND;
+ return p_184640_0_.func_77973_b().isShield(p_184640_0_, null) ? EntityEquipmentSlot.OFFHAND : EntityEquipmentSlot.MAINHAND;
}
}
else

View File

@ -0,0 +1,18 @@
--- ../src-base/minecraft/net/minecraft/entity/monster/EntityMob.java
+++ ../src-work/minecraft/net/minecraft/entity/monster/EntityMob.java
@@ -120,13 +120,13 @@
ItemStack itemstack = this.func_184614_ca();
ItemStack itemstack1 = entityplayer.func_184587_cr() ? entityplayer.func_184607_cu() : ItemStack.field_190927_a;
- if (!itemstack.func_190926_b() && !itemstack1.func_190926_b() && itemstack.func_77973_b() instanceof ItemAxe && itemstack1.func_77973_b() == Items.field_185159_cQ)
+ if (!itemstack.func_190926_b() && !itemstack1.func_190926_b() && itemstack.func_77973_b().canDisableShield(itemstack, itemstack1, entityplayer, this) && itemstack1.func_77973_b().isShield(itemstack1, entityplayer))
{
float f1 = 0.25F + (float)EnchantmentHelper.func_185293_e(this) * 0.05F;
if (this.field_70146_Z.nextFloat() < f1)
{
- entityplayer.func_184811_cZ().func_185145_a(Items.field_185159_cQ, 100);
+ entityplayer.func_184811_cZ().func_185145_a(itemstack1.func_77973_b(), 100);
this.field_70170_p.func_72960_a(entityplayer, (byte)30);
}
}

View File

@ -197,9 +197,21 @@
if (this.func_180431_b(p_70097_1_))
{
return false;
@@ -1004,12 +1072,14 @@
@@ -974,7 +1042,7 @@
{
if (p_184590_1_ >= 3.0F && this.field_184627_bm.func_77973_b() == Items.field_185159_cQ)
super.func_190629_c(p_190629_1_);
- if (p_190629_1_.func_184614_ca().func_77973_b() instanceof ItemAxe)
+ if (p_190629_1_.func_184614_ca().func_77973_b().canDisableShield(p_190629_1_.func_184614_ca(), this.func_184607_cu(), this, p_190629_1_))
{
this.func_190777_m(true);
}
@@ -1002,14 +1070,16 @@
protected void func_184590_k(float p_184590_1_)
{
- if (p_184590_1_ >= 3.0F && this.field_184627_bm.func_77973_b() == Items.field_185159_cQ)
+ if (p_184590_1_ >= 3.0F && this.field_184627_bm.func_77973_b().isShield(this.field_184627_bm, this))
{
+ ItemStack copyBeforeUse = this.field_184627_bm.func_77946_l();
int i = 1 + MathHelper.func_76141_d(p_184590_1_);
@ -274,6 +286,15 @@
this.func_184611_a(EnumHand.MAIN_HAND, ItemStack.field_190927_a);
}
}
@@ -1384,7 +1466,7 @@
if (this.field_70146_Z.nextFloat() < f)
{
- this.func_184811_cZ().func_185145_a(Items.field_185159_cQ, 100);
+ this.func_184811_cZ().func_185145_a(this.func_184607_cu().func_77973_b(), 100);
this.func_184602_cy();
this.field_70170_p.func_72960_a(this, (byte)30);
}
@@ -1442,6 +1524,8 @@
public EntityPlayer.SleepResult func_180469_a(BlockPos p_180469_1_)

View File

@ -87,7 +87,7 @@
public CreativeTabs func_77640_w()
{
return this.field_77701_a;
@@ -438,11 +445,642 @@
@@ -438,11 +445,666 @@
return false;
}
@ -714,6 +714,30 @@
+ }
+ return builder.build();
+ }
+
+ /**
+ * Can this Item disable a shield
+ * @param stack The ItemStack
+ * @param shield The shield in question
+ * @param entity The EntityLivingBase holding the shield
+ * @param attacker The EntityLivingBase holding the ItemStack
+ * @retrun True if this ItemStack can disable the shield in question.
+ */
+ public boolean canDisableShield(ItemStack stack, ItemStack shield, EntityLivingBase entity, EntityLivingBase attacker)
+ {
+ return this instanceof ItemAxe;
+ }
+
+ /**
+ * Is this Item a shield
+ * @param stack The ItemStack
+ * @param entity The Entity holding the ItemStack
+ * @return True if the ItemStack is considered a shield
+ */
+ public boolean isShield(ItemStack stack, @Nullable EntityLivingBase entity)
+ {
+ return stack.func_77973_b() == Items.field_185159_cQ;
+ }
+
+ /**
+ * @return the fuel burn time for this itemStack in a furnace.
@ -730,7 +754,7 @@
public static void func_150900_l()
{
func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a));
@@ -1002,6 +1640,8 @@
@@ -1002,6 +1664,8 @@
private final float field_78010_h;
private final float field_78011_i;
private final int field_78008_j;
@ -739,7 +763,7 @@
private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_)
{
@@ -1037,6 +1677,7 @@
@@ -1037,6 +1701,7 @@
return this.field_78008_j;
}
@ -747,7 +771,7 @@
public Item func_150995_f()
{
if (this == WOOD)
@@ -1060,5 +1701,21 @@
@@ -1060,5 +1725,21 @@
return this == DIAMOND ? Items.field_151045_i : null;
}
}

View File

@ -0,0 +1,87 @@
package net.minecraftforge.debug;
import com.google.common.collect.Multimap;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemShield;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ObjectHolder("shield_test")
@EventBusSubscriber
@Mod(modid = "shield_test", name = "Shield Test", version = "0.0.0", acceptableRemoteVersions = "*")
public class ShieldTest
{
public static final ItemShield DIAMOND_SHIELD = null;
public static final ItemSword HEAVY_DIAMOND_SWORD = null;
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
{
class ItemCustomShield extends ItemShield
{
@Override
public String getItemStackDisplayName(ItemStack stack)
{
return I18n.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name").trim();
}
@Override
public boolean isShield(ItemStack stack, EntityLivingBase entity)
{
return true;
}
}
class ItemHeavyDiamondSword extends ItemSword
{
public ItemHeavyDiamondSword()
{
super(ToolMaterial.DIAMOND);
}
@Override
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot slot)
{
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(slot);
if(slot == EntityEquipmentSlot.MAINHAND)
{
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 12.0F, 0));
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -5D, 0));
}
return multimap;
}
@Override
public boolean canDisableShield(ItemStack stack, ItemStack shield, EntityLivingBase entity, EntityLivingBase attacker)
{
return shield.getItem() != DIAMOND_SHIELD;
}
}
event.getRegistry().register(new ItemCustomShield().setMaxDamage(2098).setUnlocalizedName("diamond_shield").setRegistryName("diamond_shield"));
event.getRegistry().register(new ItemHeavyDiamondSword().setUnlocalizedName("heavy_diamond_sword").setRegistryName("heavy_diamond_sword"));
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event)
{
ModelLoader.setCustomModelResourceLocation(DIAMOND_SHIELD, 0, new ModelResourceLocation("shield_test:diamond_shield", "inventory"));
ModelLoader.setCustomModelResourceLocation(HEAVY_DIAMOND_SWORD, 0, new ModelResourceLocation("minecraft:diamond_sword", "inventory"));
}
}

View File

@ -0,0 +1,2 @@
item.diamond_shield.name=Diamond Shield
item.heavy_diamond_sword.name=Heavy Diamond Sword

View File

@ -0,0 +1,78 @@
{
"display": {
"thirdperson_righthand": {
"rotation": [ 0, 90, 0 ],
"translation": [ 10.51, 6, -4 ],
"scale": [ 1, 1, 1 ]
},
"thirdperson_lefthand": {
"rotation": [ 0, 90, 0 ],
"translation": [ 10.51, 6, 12 ],
"scale": [ 1, 1, 1 ]
},
"firstperson_righthand": {
"rotation": [ 0, 180, 5 ],
"translation": [ -10, 2, -10 ],
"scale": [ 1.25, 1.25, 1.25 ]
},
"firstperson_lefthand": {
"rotation": [ 0, 180, 5 ],
"translation": [ 10, 0, -10 ],
"scale": [ 1.25, 1.25, 1.25 ]
},
"gui": {
"rotation": [ 15, -25, -5 ],
"translation": [ 2, 3, 0 ],
"scale": [ 0.65, 0.65, 0.65 ]
},
"fixed": {
"rotation": [ 0, 180, 0 ],
"translation": [ -2, 4, -5],
"scale":[ 0.5, 0.5, 0.5]
},
"ground": {
"rotation": [ 0, 0, 0 ],
"translation": [ 4, 4, 2],
"scale":[ 0.25, 0.25, 0.25]
}
},
"overrides": [
{
"predicate": {
"blocking": 1
},
"model": "shield_test:item/diamond_shield_blocking"
}
],
"textures": {
"shield": "minecraft:entity/shield_base_nopattern"
},
"elements": [
{
"_comment": "plate",
"from": [ -6, -11, 1 ],
"to": [ 6, 11, 2 ],
"faces": {
"down": { "texture": "#shield", "uv": [ 3.25, 0.00, 25, 0.25 ] },
"up": { "texture": "#shield", "uv": [ 0.25, 0.00, 3.25, 0.25 ] },
"north": { "texture": "#shield", "uv": [ 3.50, 0.25, 6.50, 5.75 ] },
"south": { "texture": "#shield", "uv": [ 0.25, 0.25, 3.25, 5.75 ] },
"west": { "texture": "#shield", "uv": [ 0.00, 0.25, 0.25, 5.75 ] },
"east": { "texture": "#shield", "uv": [ 3.25, 0.25, 3.50, 5.75 ] }
}
},
{
"_comment": "handle",
"from": [ -1, -3, -5 ],
"to": [ 1, 3, 1 ],
"faces": {
"down": { "texture": "#shield", "uv": [ 8.50, 0.00, 9.00, 1.50 ] },
"up": { "texture": "#shield", "uv": [ 8.00, 0.00, 8.50, 1.50 ] },
"north": { "texture": "#shield", "uv": [ 10.00, 1.50, 10.50, 3.00 ] },
"south": { "texture": "#shield", "uv": [ 8.00, 1.50, 8.50, 3.00 ] },
"west": { "texture": "#shield", "uv": [ 8.50, 1.50, 10.00, 3.00 ] },
"east": { "texture": "#shield", "uv": [ 6.50, 1.50, 8.00, 3.00 ] }
}
}
]
}

View File

@ -0,0 +1,30 @@
{
"parent": "shield_test:item/diamond_shield",
"display": {
"thirdperson_righthand": {
"rotation": [ 45, 135, 0 ],
"translation": [ 3.51, 11, -2 ],
"scale": [ 1, 1, 1 ]
},
"thirdperson_lefthand": {
"rotation": [ 45, 135, 0 ],
"translation": [ 13.51, 3, 5 ],
"scale": [ 1, 1, 1 ]
},
"firstperson_righthand": {
"rotation": [ 0, 180, -5 ],
"translation": [ -15, 5, -11 ],
"scale": [ 1.25, 1.25, 1.25 ]
},
"firstperson_lefthand": {
"rotation": [ 0, 180, -5 ],
"translation": [ 5, 5, -11 ],
"scale": [ 1.25, 1.25, 1.25 ]
},
"gui": {
"rotation": [ 15, -25, -5 ],
"translation": [ 2, 3, 0 ],
"scale": [ 0.65, 0.65, 0.65 ]
}
}
}