SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.tardis.mod.common.entities;
  2.  
  3.  
  4. import net.minecraft.client.model.ModelBase;
  5. import net.minecraft.entity.*;
  6. import net.minecraft.entity.ai.*;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.inventory.IInventory;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.nbt.NBTBase;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.nbt.NBTTagList;
  13. import net.minecraft.network.datasync.DataParameter;
  14. import net.minecraft.network.datasync.DataSerializers;
  15. import net.minecraft.network.datasync.EntityDataManager;
  16. import net.minecraft.tileentity.TileEntity;
  17. import net.minecraft.util.NonNullList;
  18. import net.minecraft.util.ResourceLocation;
  19. import net.minecraft.util.text.ITextComponent;
  20. import net.minecraft.util.text.TextComponentString;
  21. import net.minecraft.world.World;
  22. import net.minecraftforge.common.util.Constants;
  23. import net.minecraftforge.fml.relauncher.Side;
  24. import net.minecraftforge.fml.relauncher.SideOnly;
  25. import net.tardis.mod.Tardis;
  26. import net.tardis.mod.common.dimensions.TDimensions;
  27. import net.tardis.mod.common.tileentity.TileEntityTardis;
  28. import java.util.UUID;
  29.  
  30. public class EntityRaider extends EntityCreature {
  31.  
  32.     public static final DataParameter<Boolean> SITTING = EntityDataManager.createKey(EntityRaider.class, DataSerializers.BOOLEAN);
  33.     public static final DataParameter<String> TYPE = EntityDataManager.createKey(EntityRaider.class, DataSerializers.STRING);
  34.  
  35.     UUID player;
  36.     private NonNullList<ItemStack> inv = NonNullList.withSize(27, ItemStack.EMPTY);
  37.  
  38.     public EntityRaider(World worldIn) {
  39.         super(worldIn);
  40.         this.stepHeight = 1;
  41.     }
  42.  
  43.  
  44.     @Override
  45.     protected void initEntityAI() {
  46.         super.initEntityAI();
  47.         this.tasks.addTask(3, new EntityAIWander(this, 0.5D));
  48.         this.tasks.addTask(0, new EntityAIWatchClosest(this, EntityPlayer.class, 30));
  49.         this.tasks.addTask(0, new EntityAISwimming(this));
  50.     }
  51.  
  52.  
  53.     @Override
  54.     protected void applyEntityAttributes() {
  55.         super.applyEntityAttributes();
  56.     }
  57.  
  58.     @Override
  59.     protected void entityInit() {
  60.         super.entityInit();
  61.         this.getDataManager().register(SITTING, false);
  62.         this.getDataManager().register(TYPE, EntityRaider.EnumRaiderType.values()[rand.nextInt(EntityRaider.EnumRaiderType.values().length - 1)].name());
  63.     }
  64.  
  65.     @Override
  66.     public void onUpdate() {
  67.         super.onUpdate();
  68.         if (!world.isRemote && this.dimension == TDimensions.TARDIS_ID && world.getWorldTime() % 20 == 0) {
  69.             TileEntityTardis tardis = null;
  70.             for (TileEntity te : world.loadedTileEntityList) {
  71.                 if (te instanceof TileEntityTardis && te.getPos().distanceSq(this.getPosition()) < Math.pow(16, 2)) {
  72.                     tardis = (TileEntityTardis) te;
  73.                     break;
  74.                 }
  75.             }
  76.         }
  77.         if (this.isWrongSize()) {
  78.             this.setSize(this.getType().size[0], this.getType().size[1]);
  79.         }
  80.     }
  81.  
  82.     @Override
  83.     protected boolean canDespawn() {
  84.         return false;
  85.     }
  86.  
  87.     public EntityRaider.EnumRaiderType getType() {
  88.         return Enum.valueOf(EntityRaider.EnumRaiderType.class, this.getDataManager().get(TYPE));
  89.     }
  90.  
  91.     public void setType(EntityRaider.EnumRaiderType type) {
  92.         this.getDataManager().set(TYPE, type.name());
  93.     }
  94.  
  95.  
  96.     @Override
  97.     public ITextComponent getDisplayName() {
  98.         return new TextComponentString(this.getType().getName());
  99.     }
  100.  
  101.     @Override
  102.     public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  103.         NBTTagList list = new NBTTagList();
  104.         for (ItemStack stack : inv) {
  105.             list.appendTag(stack.writeToNBT(new NBTTagCompound()));
  106.         }
  107.         compound.setTag("inv", list);
  108.         compound.setString("type", this.getType().name());
  109.         return super.writeToNBT(compound);
  110.     }
  111.  
  112.     @Override
  113.     public void readFromNBT(NBTTagCompound compound) {
  114.         super.readFromNBT(compound);
  115.         int id = 0;
  116.         NBTTagList list = compound.getTagList("inv", Constants.NBT.TAG_COMPOUND);
  117.         for (NBTBase base : list) {
  118.             inv.set(id, new ItemStack((NBTTagCompound) base));
  119.             ++id;
  120.         }
  121.         if (!compound.getString("owner").isEmpty()) player = UUID.fromString(compound.getString("owner"));
  122.         if (compound.getString("type") != null && !compound.getString("type").isEmpty())
  123.             this.setType(Enum.valueOf(EntityRaider.EnumRaiderType.class, compound.getString("type")));
  124.  
  125.     }
  126.  
  127.  
  128.     @Override
  129.     public boolean getAlwaysRenderNameTag() {
  130.         return false;
  131.     }
  132.  
  133.     public boolean isWrongSize() {
  134.         float[] size = this.getType().size;
  135.         return this.width != size[0] || this.height != size[1];
  136.     }
  137.  
  138.     public boolean getSit() {
  139.         return this.getDataManager().get(SITTING);
  140.     }
  141.  
  142.     public void setSit(boolean sit) {
  143.         this.getDataManager().set(SITTING, sit);
  144.     }
  145.  
  146.  
  147.     @Override
  148.     public boolean isChild() {
  149.         return false;
  150.     }
  151.  
  152.     public enum EnumRaiderType {
  153.         RICHARD("richard", "Richard"),
  154.         MATT("matt", "Matt"),
  155.         STEVEN("steven", "Steven"),
  156.         JESSIE("jessie", "Jessie");
  157.  
  158.         @SideOnly(Side.CLIENT)
  159.         public ModelBase model;
  160.         ResourceLocation skin;
  161.         String formattedName = "";
  162.         float[] size = {0.95F, 1.75F};
  163.  
  164.         EnumRaiderType(String name, String formatName) {
  165.             skin = new ResourceLocation(Tardis.MODID, "textures/entity/raider/" + name + ".png");
  166.             formattedName = formatName;
  167.         }
  168.  
  169.         EnumRaiderType(String name, String formattedName, float[] size) {
  170.             this(name, formattedName);
  171.             this.size = size;
  172.         }
  173.  
  174.         public ResourceLocation getTexture() {
  175.             return this.skin;
  176.         }
  177.  
  178.         public String getName() {
  179.             return this.formattedName;
  180.         }
  181.  
  182.         @SideOnly(Side.CLIENT)
  183.         public ModelBase getModel() {
  184.             model.isChild = false;
  185.             return model;
  186.         }
  187.  
  188.         @SideOnly(Side.CLIENT)
  189.         public void setModel(ModelBase model) {
  190.             this.model = model;
  191.         }
  192.     }
  193.  
  194.  
  195. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top