diff --git a/gradle.properties b/gradle.properties index 770fb3b..8cbc780 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,5 +22,5 @@ org.gradle.jvmargs=-Xmx6G org.gradle.daemon=true jei_version=7.3.2.36 - imdlib_version=1.16.3-6507216297fb4002f26639a7f06e96ed7a9bad28 + imdlib_version=1.16.3-fe62adbeaca3eb6320f109a154209ffa8f415b62 at_file = accesstransformer \ No newline at end of file diff --git a/src/main/java/dev/itsmeow/whisperwoods/entity/EntityAnimalWithTypesAndSizeContainable.java b/src/main/java/dev/itsmeow/whisperwoods/entity/EntityAnimalWithTypesAndSizeContainable.java new file mode 100644 index 0000000..800fddf --- /dev/null +++ b/src/main/java/dev/itsmeow/whisperwoods/entity/EntityAnimalWithTypesAndSizeContainable.java @@ -0,0 +1,76 @@ +package dev.itsmeow.whisperwoods.entity; + +import dev.itsmeow.imdlib.entity.util.IContainable; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; +import net.minecraft.world.World; + +public abstract class EntityAnimalWithTypesAndSizeContainable extends EntityAnimalWithTypesAndSize implements IContainable { + + public EntityAnimalWithTypesAndSizeContainable(EntityType entityType, World worldIn) { + super(entityType, worldIn); + } + + @Override + protected void registerData() { + super.registerData(); + this.registerFromContainerKey(); + } + + @Override + public void writeAdditional(CompoundNBT compound) { + super.writeAdditional(compound); + this.writeFromContainerToEntity(compound); + } + + @Override + public void readAdditional(CompoundNBT compound) { + super.readAdditional(compound); + this.readFromContainerToEntity(compound); + } + + @Override + public boolean canDespawn(double distanceToClosestPlayer) { + return !this.isFromContainer() && despawn(distanceToClosestPlayer); + } + + @Override + public boolean preventDespawn() { + return this.isFromContainer(); + } + + @Override + public void setContainerData(ItemStack bucket) { + IContainable.super.setContainerData(bucket); + CompoundNBT tag = bucket.getTag(); + if(bucket.getTag() == null) { + tag = new CompoundNBT(); + } + tag.putString("BucketVariantTag", this.getVariantNameOrEmpty()); + tag.putFloat("SizeTag", this.dataManager.get(SIZE)); + bucket.setTag(tag); + } + + @Override + public ActionResultType func_230254_b_(PlayerEntity player, Hand hand) { + if(this.processContainerInteract(player, hand)) { + return ActionResultType.SUCCESS; + } + return super.func_230254_b_(player, hand); + } + + @Override + public void readFromContainerTag(CompoundNBT tag) { + if(tag.contains("BucketVariantTag")) { + this.setType(tag.getString("BucketVariantTag")); + } + if(tag.contains("SizeTag")) { + this.setSize(tag.getFloat("SizeTag")); + } + } + +} \ No newline at end of file diff --git a/src/main/java/dev/itsmeow/whisperwoods/entity/EntityMoth.java b/src/main/java/dev/itsmeow/whisperwoods/entity/EntityMoth.java index 566f3b4..f186eac 100644 --- a/src/main/java/dev/itsmeow/whisperwoods/entity/EntityMoth.java +++ b/src/main/java/dev/itsmeow/whisperwoods/entity/EntityMoth.java @@ -1,6 +1,11 @@ package dev.itsmeow.whisperwoods.entity; +import java.util.List; + +import javax.annotation.Nullable; + import dev.itsmeow.imdlib.entity.util.EntityTypeContainer; +import dev.itsmeow.imdlib.entity.util.EntityTypeContainerContainable; import dev.itsmeow.whisperwoods.init.ModEntities; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -11,8 +16,10 @@ import net.minecraft.entity.EntityPredicate; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.datasync.DataParameter; @@ -24,10 +31,15 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextFormatting; import net.minecraft.world.LightType; import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; -public class EntityMoth extends EntityAnimalWithTypesAndSize { +public class EntityMoth extends EntityAnimalWithTypesAndSizeContainable { private static final DataParameter LANDED = EntityDataManager.createKey(EntityMoth.class, DataSerializers.VARINT); private static final EntityPredicate playerPredicate = (new EntityPredicate()).setDistance(4.0D).allowFriendlyFire().allowInvulnerable(); @@ -38,7 +50,7 @@ public EntityMoth(World worldIn) { this(ModEntities.MOTH.entityType, worldIn); } - protected EntityMoth(EntityType type, World worldIn) { + protected EntityMoth(EntityType type, World worldIn) { super(type, worldIn); } @@ -267,4 +279,17 @@ protected EntityAnimalWithTypes getBaseChild() { return null; } + @Override + public EntityTypeContainerContainable getContainableContainer() { + return ModEntities.MOTH; + } + + public static void bottleTooltip(EntityTypeContainer container, ItemStack stack, @Nullable World worldIn, List tooltip) { + CompoundNBT tag = stack.getTag(); + if(tag != null) { + if(tag.contains("SizeTag", Constants.NBT.TAG_FLOAT)) { + tooltip.add(new StringTextComponent("Size: " + tag.getFloat("SizeTag")).setStyle(Style.EMPTY.createStyleFromFormattings(new TextFormatting[] { TextFormatting.ITALIC, TextFormatting.GRAY }))); + } + } + } } diff --git a/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java b/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java index 43922e1..d990f1a 100644 --- a/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java +++ b/src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java @@ -9,6 +9,10 @@ import dev.itsmeow.imdlib.entity.util.EntityTypeContainer; import dev.itsmeow.imdlib.entity.util.EntityTypeContainer.Builder; import dev.itsmeow.imdlib.entity.util.EntityTypeContainer.CustomConfigurationHolder; +import dev.itsmeow.imdlib.entity.util.EntityTypeContainerContainable; +import dev.itsmeow.imdlib.entity.util.IContainable; +import dev.itsmeow.imdlib.item.IContainerItem; +import dev.itsmeow.imdlib.item.ItemModEntityContainer; import dev.itsmeow.imdlib.util.BiomeDictionary.Type; import dev.itsmeow.whisperwoods.WhisperwoodsMod; import dev.itsmeow.whisperwoods.entity.EntityHidebehind; @@ -21,6 +25,8 @@ import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.entity.monster.MonsterEntity; +import net.minecraft.item.Item; +import net.minecraft.item.Items; import net.minecraft.world.Difficulty; import net.minecraft.world.World; import net.minecraftforge.common.ForgeConfigSpec; @@ -29,7 +35,7 @@ public class ModEntities { public static final EntityRegistrarHandler H = IMDLib.entityHandler(WhisperwoodsMod.MODID); - public static final EntityTypeContainer MOTH = H.add(entity(EntityMoth.class, EntityMoth::new, "moth", () -> MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 2.0D)) + public static final EntityTypeContainerContainable> MOTH = H.add(ModEntities.>entityContainable(EntityMoth.class, EntityMoth::new, "moth", () -> MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 2.0D)) .spawn(EntityClassification.AMBIENT, 10, 1, 3) .egg(0x442516, 0xc66121) .size(0.35F, 0.35F) @@ -56,7 +62,8 @@ public void customConfigurationLoad() { "black_white_deaths_head", "brown_grey_deaths_head", "brown_orange_deaths_head") - .biomes(Type.FOREST, Type.SWAMP)); + .biomes(Type.FOREST, Type.SWAMP) + .containers(ItemModEntityContainer.get("bottled_%s", WhisperwoodsMod.TAB), c -> Items.GLASS_BOTTLE, EntityMoth::bottleTooltip)); public static final EntityTypeContainer HIDEBEHIND = H.add(entity(EntityHidebehind.class, EntityHidebehind::new, "hidebehind", () -> MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 20D).createMutableAttribute(Attributes.ATTACK_DAMAGE).createMutableAttribute(Attributes.ATTACK_DAMAGE, 15D)) .spawn(EntityClassification.CREATURE, 5, 1, 1) @@ -109,4 +116,7 @@ private static Builder entity(Class entityClass, Fun return EntityTypeContainer.Builder.create(entityClass, func, entityNameIn, attributes, WhisperwoodsMod.MODID); } + private static > EntityTypeContainerContainable.Builder entityContainable(Class EntityClass, Function func, String entityNameIn, Supplier attributes) { + return EntityTypeContainerContainable.Builder.create(EntityClass, func, entityNameIn, attributes, WhisperwoodsMod.MODID); + } } diff --git a/src/main/java/dev/itsmeow/whisperwoods/init/WhisperwoodsRegistrar.java b/src/main/java/dev/itsmeow/whisperwoods/init/WhisperwoodsRegistrar.java index 297056a..de1e8ef 100644 --- a/src/main/java/dev/itsmeow/whisperwoods/init/WhisperwoodsRegistrar.java +++ b/src/main/java/dev/itsmeow/whisperwoods/init/WhisperwoodsRegistrar.java @@ -2,12 +2,14 @@ package dev.itsmeow.whisperwoods.init; import dev.itsmeow.imdlib.entity.util.EntityTypeContainer; +import dev.itsmeow.imdlib.entity.util.EntityTypeContainerContainable; import dev.itsmeow.whisperwoods.WhisperwoodsMod; import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.registries.ForgeRegistries; @Mod.EventBusSubscriber(modid = WhisperwoodsMod.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class WhisperwoodsRegistrar { @@ -16,6 +18,15 @@ public class WhisperwoodsRegistrar { public static void registerItems(RegistryEvent.Register event) { for(EntityTypeContainer container : ModEntities.getEntities().values()) { event.getRegistry().register(container.egg); + if(container instanceof EntityTypeContainerContainable) { + EntityTypeContainerContainable c = (EntityTypeContainerContainable) container; + if(!ForgeRegistries.ITEMS.containsValue(c.getContainerItem()) && c.getContainerItem().getRegistryName().getNamespace().equals(WhisperwoodsMod.MODID)) { + event.getRegistry().register(c.getContainerItem()); + } + if(!ForgeRegistries.ITEMS.containsValue(c.getEmptyContainerItem()) && c.getEmptyContainerItem().getRegistryName().getNamespace().equals(WhisperwoodsMod.MODID)) { + event.getRegistry().register(c.getEmptyContainerItem()); + } + } } } diff --git a/src/main/resources/assets/whisperwoods/lang/en_us.json b/src/main/resources/assets/whisperwoods/lang/en_us.json index 3ed8cf9..71c366f 100644 --- a/src/main/resources/assets/whisperwoods/lang/en_us.json +++ b/src/main/resources/assets/whisperwoods/lang/en_us.json @@ -1,6 +1,14 @@ { "itemGroup.whisperwoods": "Whisperwoods", "entity.whisperwoods.moth": "Moth", + "entity.whisperwoods.moth.type.garden_tiger": "Garden Tiger", + "entity.whisperwoods.moth.type.luna": "Luna", + "entity.whisperwoods.moth.type.creeper_sphinx": "Creeper Sphinx", + "entity.whisperwoods.moth.type.grey_spotted_hawk": "Grey Spotted Hawk", + "entity.whisperwoods.moth.type.brown_spotted_hawk": "Brown Spotted Hawk", + "entity.whisperwoods.moth.type.black_white_deaths_head": "Black/White Death's Head", + "entity.whisperwoods.moth.type.brown_grey_deaths_head": "Brown/Grey Death's Head", + "entity.whisperwoods.moth.type.brown_orange_deaths_head": "Brown/Orange Death's Head", "entity.whisperwoods.hidebehind": "Hidebehind", "entity.whisperwoods.wisp": "Wisp", "entity.whisperwoods.hirschgeist": "Hirschgeist", @@ -12,6 +20,7 @@ "block.whisperwoods.ghost_light_toxic_green": "Toxic Green Ghost Light", "block.whisperwoods.ghost_light_magic_purple": "Magic Purple Ghost Light", "block.whisperwoods.hirschgeist_skull": "Hirschgeist Skull", + "item.whisperwoods.bottled_moth": "Bottled Moth", "misc.whisperwoods.eggorder": "Spawn %s" } \ No newline at end of file diff --git a/src/main/resources/assets/whisperwoods/models/item/bottled_moth.json b/src/main/resources/assets/whisperwoods/models/item/bottled_moth.json new file mode 100644 index 0000000..c8d3a57 --- /dev/null +++ b/src/main/resources/assets/whisperwoods/models/item/bottled_moth.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "whisperwoods:items/bottled_moth" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/whisperwoods/textures/items/bottled_moth.png b/src/main/resources/assets/whisperwoods/textures/items/bottled_moth.png new file mode 100644 index 0000000..44727b2 Binary files /dev/null and b/src/main/resources/assets/whisperwoods/textures/items/bottled_moth.png differ