Skip to content

Commit

Permalink
Completely rewrite entity types and config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Nov 22, 2019
1 parent 5e41df9 commit 5814a28
Show file tree
Hide file tree
Showing 42 changed files with 575 additions and 522 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
import its_meow.betteranimalsplus.common.entity.projectile.EntityPheasantEgg;
import its_meow.betteranimalsplus.common.world.gen.TrilliumGenerator;
import its_meow.betteranimalsplus.config.BetterAnimalsPlusConfig;
import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.init.ModItems;
import its_meow.betteranimalsplus.init.ModTriggers;
import its_meow.betteranimalsplus.network.ClientConfigurationPacket;
import its_meow.betteranimalsplus.network.ClientRequestBAMPacket;
import its_meow.betteranimalsplus.network.ServerNoBAMPacket;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.block.DispenserBlock;
import net.minecraft.dispenser.IPosition;
import net.minecraft.dispenser.ProjectileDispenseBehavior;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
Expand Down Expand Up @@ -81,8 +82,8 @@ public ItemStack createIcon() {
@Override
public void fill(NonNullList<ItemStack> toDisplay) {
super.fill(toDisplay);
for (SpawnEggItem egg : ModItems.eggs.keySet()) {
ItemStack stack = new ItemStack(egg);
for(EntityTypeContainer<?> cont : ModEntities.ENTITIES.values()) {
ItemStack stack = new ItemStack(cont.egg);
toDisplay.add(stack);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import javax.annotation.Nullable;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ILivingEntityData;
Expand Down Expand Up @@ -80,11 +80,11 @@ public DataParameter<Integer> getDataKey() {
return TYPE_NUMBER;
}

protected abstract String getContainerName();
protected abstract EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer();

@Override
public boolean canDespawn(double range) {
return ModEntities.entityMap.containsKey(this.getContainerName()) ? ModEntities.entityMap.get(this.getContainerName()).despawn : false;
return getContainer().despawn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import its_meow.betteranimalsplus.common.entity.projectile.EntityBadgerDirt;
import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -38,7 +39,7 @@
public class EntityBadger extends EntityAnimalWithSelectiveTypes implements IMob {

public EntityBadger(World worldIn) {
super(ModEntities.getEntityType("badger"), worldIn);
super(ModEntities.BADGER.entityType, worldIn);
}

@Override
Expand Down Expand Up @@ -222,8 +223,8 @@ protected int[] getTypesFor(Set<BiomeDictionary.Type> types) {
}

@Override
protected String getContainerName() {
return "badger";
protected EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer() {
return ModEntities.BADGER;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package its_meow.betteranimalsplus.common.entity;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.passive.WaterMobEntity;
Expand Down Expand Up @@ -46,12 +46,11 @@ public void tick() {
}
}

protected abstract String getContainerName();
protected abstract EntityTypeContainer<? extends EntityBasicWaterCreature> getContainer();

@Override
public boolean canDespawn(double range) {
return ModEntities.entityMap.containsKey(this.getContainerName()) ? ModEntities.entityMap.get(this.getContainerName()).despawn : false;
return getContainer().despawn;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class EntityBear extends MonsterEntity {
private int warningSoundTicks;

public EntityBear(World worldIn) {
super(ModEntities.getEntityType("brownbear"), worldIn);
super(ModEntities.BROWN_BEAR.entityType, worldIn);
}

public EntityBear(EntityType<? extends EntityBear> type, World worldIn) {
Expand Down Expand Up @@ -205,7 +205,7 @@ protected double getAttackReachSqr(LivingEntity attackTarget) {

@Override
public boolean canDespawn(double range) {
return ModEntities.entityMap.containsKey("brownbear") ? ModEntities.entityMap.get("brownbear").despawn : false;
return ModEntities.ENTITIES.containsKey("brownbear") ? ModEntities.ENTITIES.get("brownbear").despawn : false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class EntityBearNeutral extends EntityBear implements IVariantTypes {
protected static final DataParameter<Integer> TYPE_NUMBER = EntityDataManager.<Integer>createKey(EntityBearNeutral.class, DataSerializers.VARINT);

public EntityBearNeutral(World worldIn) {
super(ModEntities.getEntityType("blackbear"), worldIn);
super(ModEntities.BLACK_BEAR.entityType, worldIn);
}

@Override
Expand Down Expand Up @@ -134,7 +134,7 @@ protected ResourceLocation getLootTable() {

@Override
public boolean canDespawn(double range) {
return ModEntities.entityMap.containsKey("blackbear") ? ModEntities.entityMap.get("blackbear").despawn : false;
return ModEntities.ENTITIES.containsKey("blackbear") ? ModEntities.ENTITIES.get("blackbear").despawn : false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.annotation.Nullable;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import its_meow.betteranimalsplus.util.HeadTypes;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -47,7 +48,7 @@
public class EntityBoar extends EntityAnimalWithSelectiveTypes implements IMob {

public EntityBoar(World worldIn) {
super(ModEntities.getEntityType("boar"), worldIn);
super(ModEntities.BOAR.entityType, worldIn);
}

@Override
Expand Down Expand Up @@ -276,8 +277,8 @@ protected int[] getTypesFor(Set<BiomeDictionary.Type> types) {
}

@Override
protected String getContainerName() {
return "boar";
protected EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer() {
return ModEntities.BOAR;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import its_meow.betteranimalsplus.config.BetterAnimalsPlusConfig;
import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainerTameable;
import its_meow.betteranimalsplus.util.HeadTypes;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.FollowOwnerGoal;
Expand Down Expand Up @@ -43,7 +44,7 @@
public class EntityCoyote extends EntityFeralWolf {

public EntityCoyote(World worldIn) {
super(ModEntities.getEntityType("coyote"), worldIn);
super(ModEntities.COYOTE.entityType, worldIn);
this.setTamed(false);
}

Expand Down Expand Up @@ -188,8 +189,8 @@ public boolean processInteract(PlayerEntity player, Hand hand) {
}

@Override
protected String getContainerName() {
return "coyote";
protected EntityTypeContainerTameable<? extends EntityTameableBetterAnimalsPlus> getContainer() {
return ModEntities.COYOTE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package its_meow.betteranimalsplus.common.entity;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.goal.AvoidEntityGoal;
Expand All @@ -19,7 +20,7 @@ public class EntityCrab extends EntityCrabLikeBase {
protected static final DataParameter<Integer> CRAB_RAVE = EntityDataManager.<Integer>createKey(EntityCrab.class, DataSerializers.VARINT);

public EntityCrab(World world) {
super(ModEntities.getEntityType("crab"), world);
super(ModEntities.CRAB.entityType, world);
this.setPathPriority(PathNodeType.WATER, 10F);
}

Expand Down Expand Up @@ -118,8 +119,8 @@ protected void setAttackTarget(MobEntity mob, LivingEntity living) {
}

@Override
protected String getContainerName() {
return "crab";
protected EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer() {
return ModEntities.CRAB;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package its_meow.betteranimalsplus.common.entity;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.init.ModLootTables;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -113,12 +112,10 @@ public boolean isPushedByWater() {
protected ResourceLocation getLootTable() {
return ModLootTables.CRAB;
}

protected abstract String getContainerName();

@Override
public boolean canDespawn(double range) {
return !this.hasCustomName() && ModEntities.entityMap.containsKey(this.getContainerName()) ? ModEntities.entityMap.get(this.getContainerName()).despawn : false;
return !this.hasCustomName() && super.canDespawn(range);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.annotation.Nullable;

import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.entity.CreatureEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ILivingEntityData;
Expand Down Expand Up @@ -70,4 +71,11 @@ public DataParameter<Integer> getDataKey() {
return TYPE_NUMBER;
}

protected abstract EntityTypeContainer<? extends EntityCreatureWithTypes> getContainer();

@Override
public boolean canDespawn(double range) {
return getContainer().despawn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.init.ModLootTables;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import its_meow.betteranimalsplus.util.HeadTypes;
import net.minecraft.block.BlockState;
import net.minecraft.entity.SharedMonsterAttributes;
Expand Down Expand Up @@ -32,7 +33,7 @@
public class EntityDeer extends EntityAnimalEatsGrassWithTypes {

public EntityDeer(World worldIn) {
super(ModEntities.getEntityType("deer"), worldIn, 5);
super(ModEntities.DEER.entityType, worldIn, 5);
}

public int getEatTime() {
Expand Down Expand Up @@ -144,8 +145,8 @@ protected IVariantTypes getBaseChild() {
}

@Override
protected String getContainerName() {
return "deer";
protected EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer() {
return ModEntities.DEER;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.init.ModItems;
import its_meow.betteranimalsplus.init.ModLootTables;
import its_meow.betteranimalsplus.util.EntityTypeContainerTameable;
import its_meow.betteranimalsplus.util.HeadTypes;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -87,7 +88,7 @@ public class EntityFeralWolf extends EntityTameableWithSelectiveTypes implements
public SitGoal aiSit;

public EntityFeralWolf(World worldIn) {
super(ModEntities.getEntityType("feralwolf"), worldIn);
super(ModEntities.FERAL_WOLF.entityType, worldIn);
this.world = worldIn;
this.setTamed(false);
}
Expand Down Expand Up @@ -527,8 +528,8 @@ protected ResourceLocation getLootTable() {
}

@Override
protected String getContainerName() {
return "feralwolf";
protected EntityTypeContainerTameable<? extends EntityTameableBetterAnimalsPlus> getContainer() {
return ModEntities.FERAL_WOLF;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import its_meow.betteranimalsplus.init.ModItems;
import its_meow.betteranimalsplus.init.ModLootTables;
import its_meow.betteranimalsplus.init.ModTriggers;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class EntityGoat extends EntityAnimalEatsGrassWithTypes {
private ArrayList<Item> temptItems = null;

public EntityGoat(World worldIn) {
super(ModEntities.getEntityType("goat"), worldIn, 5);
super(ModEntities.GOAT.entityType, worldIn, 5);
this.world = worldIn;
this.addTemptItems();
}
Expand Down Expand Up @@ -322,8 +323,8 @@ protected IVariantTypes getBaseChild() {
}

@Override
protected String getContainerName() {
return "goat";
protected EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer() {
return ModEntities.GOAT;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package its_meow.betteranimalsplus.common.entity;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.util.EntityTypeContainer;
import net.minecraft.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.entity.ai.goal.RandomWalkingGoal;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -10,7 +11,7 @@
public class EntityHorseshoeCrab extends EntityCrabLikeBase {

public EntityHorseshoeCrab(World world) {
super(ModEntities.getEntityType("horseshoecrab"), world);
super(ModEntities.HORSESHOE_CRAB.entityType, world);
}

@Override
Expand All @@ -35,8 +36,8 @@ protected ResourceLocation getLootTable() {
}

@Override
protected String getContainerName() {
return "horseshoecrab";
protected EntityTypeContainer<? extends EntityAnimalWithTypes> getContainer() {
return ModEntities.HORSESHOE_CRAB;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class EntityJellyfish extends WaterMobEntity implements IVariantTypes {
private float randomMotionVecZ;

public EntityJellyfish(World worldIn) {
super(ModEntities.getEntityType("jellyfish"), worldIn);
super(ModEntities.JELLYFISH.entityType, worldIn);
this.setSize(0.8F, 0.8F);
rotationVelocity = (1.0F / (rand.nextFloat() + 1.0F) * 0.2F);
}
Expand Down Expand Up @@ -299,7 +299,7 @@ public EntityDataManager getDataManagerI() {

@Override
public boolean canDespawn(double range) {
return ModEntities.entityMap.containsKey("jellyfish") ? ModEntities.entityMap.get("jellyfish").despawn : false;
return ModEntities.ENTITIES.containsKey("jellyfish") ? ModEntities.ENTITIES.get("jellyfish").despawn : false;
}

}
Loading

0 comments on commit 5814a28

Please sign in to comment.