Skip to content

Commit

Permalink
Add bottled moth
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Oct 12, 2020
1 parent 1b78d6f commit 9c8ada1
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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<? extends EntityAnimalWithTypesAndSizeContainable> 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"));
}
}

}
29 changes: 27 additions & 2 deletions src/main/java/dev/itsmeow/whisperwoods/entity/EntityMoth.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<Integer> LANDED = EntityDataManager.createKey(EntityMoth.class, DataSerializers.VARINT);
private static final EntityPredicate playerPredicate = (new EntityPredicate()).setDistance(4.0D).allowFriendlyFire().allowInvulnerable();
Expand All @@ -38,7 +50,7 @@ public EntityMoth(World worldIn) {
this(ModEntities.MOTH.entityType, worldIn);
}

protected EntityMoth(EntityType<? extends EntityAnimalWithTypesAndSize> type, World worldIn) {
protected EntityMoth(EntityType<? extends EntityAnimalWithTypesAndSizeContainable> type, World worldIn) {
super(type, worldIn);
}

Expand Down Expand Up @@ -267,4 +279,17 @@ protected EntityAnimalWithTypes getBaseChild() {
return null;
}

@Override
public EntityTypeContainerContainable<?, ?> getContainableContainer() {
return ModEntities.MOTH;
}

public static void bottleTooltip(EntityTypeContainer<? extends MobEntity> container, ItemStack stack, @Nullable World worldIn, List<ITextComponent> 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 })));
}
}
}
}
14 changes: 12 additions & 2 deletions src/main/java/dev/itsmeow/whisperwoods/init/ModEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -29,7 +35,7 @@ public class ModEntities {

public static final EntityRegistrarHandler H = IMDLib.entityHandler(WhisperwoodsMod.MODID);

public static final EntityTypeContainer<EntityMoth> MOTH = H.add(entity(EntityMoth.class, EntityMoth::new, "moth", () -> MobEntity.func_233666_p_().createMutableAttribute(Attributes.MAX_HEALTH, 2.0D))
public static final EntityTypeContainerContainable<EntityMoth, ItemModEntityContainer<EntityMoth>> MOTH = H.add(ModEntities.<EntityMoth, ItemModEntityContainer<EntityMoth>>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)
Expand All @@ -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<EntityHidebehind> 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)
Expand Down Expand Up @@ -109,4 +116,7 @@ private static <T extends MobEntity> Builder<T> entity(Class<T> entityClass, Fun
return EntityTypeContainer.Builder.create(entityClass, func, entityNameIn, attributes, WhisperwoodsMod.MODID);
}

private static <T extends MobEntity & IContainable, I extends Item & IContainerItem<T>> EntityTypeContainerContainable.Builder<T, I> entityContainable(Class<T> EntityClass, Function<World, T> func, String entityNameIn, Supplier<AttributeModifierMap.MutableAttribute> attributes) {
return EntityTypeContainerContainable.Builder.create(EntityClass, func, entityNameIn, attributes, WhisperwoodsMod.MODID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,6 +18,15 @@ public class WhisperwoodsRegistrar {
public static void registerItems(RegistryEvent.Register<Item> 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());
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/assets/whisperwoods/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "whisperwoods:items/bottled_moth"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9c8ada1

Please sign in to comment.