Add function to add items with the same behavior as the pumpkin for enderman (#6890)

This commit is contained in:
Mysterious_Dev 2020-07-06 22:34:01 +02:00 committed by GitHub
parent 68e71009f3
commit a567ddaa10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 1 deletions

View file

@ -16,6 +16,15 @@
} }
protected void func_70088_a() { protected void func_70088_a() {
@@ -188,7 +188,7 @@
private boolean func_70821_d(PlayerEntity p_70821_1_) {
ItemStack itemstack = p_70821_1_.field_71071_by.field_70460_b.get(3);
- if (itemstack.func_77973_b() == Blocks.field_196625_cS.func_199767_j()) {
+ if (itemstack.isEnderMask(p_70821_1_, this)) {
return false;
} else {
Vector3d vector3d = p_70821_1_.func_70676_i(1.0F).func_72432_b();
@@ -267,7 +267,9 @@ @@ -267,7 +267,9 @@
boolean flag = blockstate.func_185904_a().func_76230_c(); boolean flag = blockstate.func_185904_a().func_76230_c();
boolean flag1 = blockstate.func_204520_s().func_206884_a(FluidTags.field_206959_a); boolean flag1 = blockstate.func_204520_s().func_206884_a(FluidTags.field_206959_a);

View file

@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.entity.model.BipedModel; import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -36,6 +37,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.Attribute; import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.monster.EndermanEntity;
import net.minecraft.entity.monster.piglin.PiglinTasks; import net.minecraft.entity.monster.piglin.PiglinTasks;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorItem; import net.minecraft.item.ArmorItem;
@ -814,4 +816,18 @@ public interface IForgeItem
default <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) { default <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) {
return amount; return amount;
} }
/**
* Whether this Item can be used to hide player head for enderman.
*
* @param stack the ItemStack
* @param player The player watching the enderman
* @param endermanEntity The enderman that the player look
* @return true if this Item can be used to hide player head for enderman
*/
default boolean isEnderMask(ItemStack stack, PlayerEntity player, EndermanEntity endermanEntity)
{
return stack.getItem() == Blocks.CARVED_PUMPKIN.asItem();
}
} }

View file

@ -23,6 +23,7 @@ import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.entity.monster.EndermanEntity;
import net.minecraft.util.CachedBlockInfo; import net.minecraft.util.CachedBlockInfo;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
@ -473,4 +474,16 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundNBT>
{ {
return getStack().getItem().makesPiglinsNeutral(getStack(), wearer); return getStack().getItem().makesPiglinsNeutral(getStack(), wearer);
} }
/**
* Whether this Item can be used to hide player head for enderman.
*
* @param player The player watching the enderman
* @param endermanEntity The enderman that the player look
* @return true if this Item can be used.
*/
default boolean isEnderMask(PlayerEntity player, EndermanEntity endermanEntity)
{
return getStack().getItem().isEnderMask(getStack(), player, endermanEntity);
}
} }

View file

@ -0,0 +1,36 @@
package net.minecraftforge.debug.item;
import net.minecraft.entity.monster.EndermanEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
@Mod(EnderMaskTest.MODID)
public class EnderMaskTest
{
public static final String MODID = "ender_mask_test";
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static RegistryObject<Item> ender_mask = ITEMS.register("ender_mask", () ->
new ArmorItem(ArmorMaterial.LEATHER, EquipmentSlotType.HEAD, (new Item.Properties().group(ItemGroup.MISC)))
{
@Override
public boolean isEnderMask(ItemStack stack, PlayerEntity player, EndermanEntity endermanEntity)
{
return player.experienceLevel > 10;
}
}
);
public EnderMaskTest()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ITEMS.register(modEventBus);
}
}

View file

@ -68,3 +68,5 @@ loaderVersion="[28,)"
modId="deferred_registry_test" modId="deferred_registry_test"
[[mods]] [[mods]]
modId="create_entity_classification_test" modId="create_entity_classification_test"
[[mods]]
modId="ender_mask_test"