Advertisement
Guest User

TestE

a guest
Mar 15th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.49 KB | None | 0 0
  1. package mod.mcreator;
  2.  
  3. import com.google.common.collect.Lists;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import javax.annotation.Nullable;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.EntityHanging;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.init.Items;
  11. import net.minecraft.init.SoundEvents;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.util.EnumFacing;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.World;
  17.  
  18. public class TestE extends EntityHanging
  19. {
  20.     public TestE.EnumArt art;
  21.  
  22.     public TestE(World worldIn)
  23.     {
  24.         super(worldIn);
  25.     }
  26.  
  27.     public TestE(World worldIn, BlockPos pos, EnumFacing facing)
  28.     {
  29.         super(worldIn, pos);
  30.         List<TestE.EnumArt> list = Lists.<TestE.EnumArt>newArrayList();
  31.         int i = 0;
  32.  
  33.         for (TestE.EnumArt entitypainting$enumart : TestE.EnumArt.values())
  34.         {
  35.             this.art = entitypainting$enumart;
  36.             this.updateFacingWithBoundingBox(facing);
  37.  
  38.             if (this.onValidSurface())
  39.             {
  40.                 list.add(entitypainting$enumart);
  41.                 int j = entitypainting$enumart.sizeX * entitypainting$enumart.sizeY;
  42.  
  43.                 if (j > i)
  44.                 {
  45.                     i = j;
  46.                 }
  47.             }
  48.         }
  49.  
  50.         if (!list.isEmpty())
  51.         {
  52.             Iterator<TestE.EnumArt> iterator = list.iterator();
  53.  
  54.             while (iterator.hasNext())
  55.             {
  56.                 TestE.EnumArt entitypainting$enumart1 = iterator.next();
  57.  
  58.                 if (entitypainting$enumart1.sizeX * entitypainting$enumart1.sizeY < i)
  59.                 {
  60.                     iterator.remove();
  61.                 }
  62.             }
  63.  
  64.             this.art = list.get(this.rand.nextInt(list.size()));
  65.         }
  66.  
  67.         this.updateFacingWithBoundingBox(facing);
  68.     }
  69.  
  70.     /**
  71.      * (abstract) Protected helper method to write subclass entity data to NBT.
  72.      */
  73.     public void writeEntityToNBT(NBTTagCompound compound)
  74.     {
  75.         compound.setString("Motive", this.art.title);
  76.         super.writeEntityToNBT(compound);
  77.     }
  78.  
  79.     /**
  80.      * (abstract) Protected helper method to read subclass entity data from NBT.
  81.      */
  82.     public void readEntityFromNBT(NBTTagCompound compound)
  83.     {
  84.         String s = compound.getString("Motive");
  85.  
  86.         for (TestE.EnumArt entitypainting$enumart : TestE.EnumArt.values())
  87.         {
  88.             if (entitypainting$enumart.title.equals(s))
  89.             {
  90.                 this.art = entitypainting$enumart;
  91.             }
  92.         }
  93.  
  94.         if (this.art == null)
  95.         {
  96.             this.art = TestE.EnumArt.KEBAB;
  97.         }
  98.  
  99.         super.readEntityFromNBT(compound);
  100.     }
  101.  
  102.     public int getWidthPixels()
  103.     {
  104.         return this.art.sizeX;
  105.     }
  106.  
  107.     public int getHeightPixels()
  108.     {
  109.         return this.art.sizeY;
  110.     }
  111.  
  112.     /**
  113.      * Called when this entity is broken. Entity parameter may be null.
  114.      */
  115.     public void onBroken(@Nullable Entity brokenEntity)
  116.     {
  117.         if (this.world.getGameRules().getBoolean("doEntityDrops"))
  118.         {
  119.             this.playSound(SoundEvents.ENTITY_PAINTING_BREAK, 1.0F, 1.0F);
  120.  
  121.             if (brokenEntity instanceof EntityPlayer)
  122.             {
  123.                 EntityPlayer entityplayer = (EntityPlayer)brokenEntity;
  124.  
  125.                 if (entityplayer.capabilities.isCreativeMode)
  126.                 {
  127.                     return;
  128.                 }
  129.             }
  130.  
  131.             this.entityDropItem(new ItemStack(Items.PAINTING), 0.0F);
  132.         }
  133.     }
  134.  
  135.     public void playPlaceSound()
  136.     {
  137.         this.playSound(SoundEvents.ENTITY_PAINTING_PLACE, 1.0F, 1.0F);
  138.     }
  139.  
  140.     /**
  141.      * Sets the location and Yaw/Pitch of an entity in the world
  142.      */
  143.     public void setLocationAndAngles(double x, double y, double z, float yaw, float pitch)
  144.     {
  145.         this.setPosition(x, y, z);
  146.     }
  147.  
  148.     public static enum EnumArt
  149.     {
  150.         KEBAB("Kebab", 16, 16, 0, 0),
  151.         AZTEC("Aztec", 16, 16, 16, 0),
  152.         ALBAN("Alban", 16, 16, 32, 0),
  153.         AZTEC_2("Aztec2", 16, 16, 48, 0),
  154.         BOMB("Bomb", 16, 16, 64, 0),
  155.         PLANT("Plant", 16, 16, 80, 0),
  156.         WASTELAND("Wasteland", 16, 16, 96, 0),
  157.         POOL("Pool", 32, 16, 0, 32),
  158.         COURBET("Courbet", 32, 16, 32, 32),
  159.         SEA("Sea", 32, 16, 64, 32),
  160.         SUNSET("Sunset", 32, 16, 96, 32),
  161.         CREEBET("Creebet", 32, 16, 128, 32),
  162.         WANDERER("Wanderer", 16, 32, 0, 64),
  163.         GRAHAM("Graham", 16, 32, 16, 64),
  164.         MATCH("Match", 32, 32, 0, 128),
  165.         BUST("Bust", 32, 32, 32, 128),
  166.         STAGE("Stage", 32, 32, 64, 128),
  167.         VOID("Void", 32, 32, 96, 128),
  168.         SKULL_AND_ROSES("SkullAndRoses", 32, 32, 128, 128),
  169.         WITHER("Wither", 32, 32, 160, 128),
  170.         FIGHTERS("Fighters", 64, 32, 0, 96),
  171.         POINTER("Pointer", 64, 64, 0, 192),
  172.         PIGSCENE("Pigscene", 64, 64, 64, 192),
  173.         BURNING_SKULL("BurningSkull", 64, 64, 128, 192),
  174.         SKELETON("Skeleton", 64, 48, 192, 64),
  175.         DONKEY_KONG("DonkeyKong", 64, 48, 192, 112);
  176.  
  177.         public static final int MAX_NAME_LENGTH = "SkullAndRoses".length();
  178.         public final String title;
  179.         public final int sizeX;
  180.         public final int sizeY;
  181.         public final int offsetX;
  182.         public final int offsetY;
  183.  
  184.         private EnumArt(String titleIn, int width, int height, int textureU, int textureV)
  185.         {
  186.             this.title = titleIn;
  187.             this.sizeX = width;
  188.             this.sizeY = height;
  189.             this.offsetX = textureU;
  190.             this.offsetY = textureV;
  191.         }
  192.     }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement