Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.75 KB | None | 0 0
  1. package com.JV.WTTI.GearBed.Block;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5.  
  6. import java.util.Iterator;
  7. import java.util.Random;
  8. import java.util.UUID;
  9.  
  10. import com.JV.WTTI.WTTI;
  11. import com.JV.WTTI.GearBed.GearBedPlayerVariables;
  12. import com.JV.WTTI.GearBed.Gui.GuiHandler;
  13.  
  14. import net.minecraft.block.Block;
  15. import net.minecraft.block.BlockDirectional;
  16. import net.minecraft.block.ITileEntityProvider;
  17. import net.minecraft.block.material.Material;
  18. import net.minecraft.client.renderer.texture.IIconRegister;
  19. import net.minecraft.entity.Entity;
  20. import net.minecraft.entity.EntityLivingBase;
  21. import net.minecraft.entity.player.EntityPlayer;
  22. import net.minecraft.init.Blocks;
  23. import net.minecraft.init.Items;
  24. import net.minecraft.item.Item;
  25. import net.minecraft.item.ItemStack;
  26. import net.minecraft.server.MinecraftServer;
  27. import net.minecraft.tileentity.TileEntity;
  28. import net.minecraft.util.ChatComponentText;
  29. import net.minecraft.util.ChatComponentTranslation;
  30. import net.minecraft.util.ChunkCoordinates;
  31. import net.minecraft.util.Direction;
  32. import net.minecraft.util.IIcon;
  33. import net.minecraft.world.IBlockAccess;
  34. import net.minecraft.world.World;
  35. import net.minecraft.world.biome.BiomeGenBase;
  36.  
  37. public class BlockGearBed extends BlockDirectional implements ITileEntityProvider
  38. {
  39.     public static final int[][] field_149981_a = new int[][] {{0, 1}, { -1, 0}, {0, -1}, {1, 0}};
  40.     @SideOnly(Side.CLIENT)
  41.     private IIcon[] field_149980_b;
  42.     @SideOnly(Side.CLIENT)
  43.     private IIcon[] field_149982_M;
  44.     @SideOnly(Side.CLIENT)
  45.     private IIcon[] field_149983_N;
  46.     private static final String __OBFID = "CL_00000198";
  47.    
  48.  
  49.     public BlockGearBed()
  50.     {
  51.         super(Material.cloth);
  52.         this.func_149978_e();
  53.         this.isBlockContainer = true;
  54.     }
  55.  
  56.     @Override
  57.     public TileEntity createNewTileEntity(World worldIn, int meta) {
  58.         return new GearBedTileEntity();
  59.     }
  60. //    @Override
  61. //    public int onBlockPlaced(World p_149660_1_, int p_149660_2_, int p_149660_3_, int p_149660_4_, int p_149660_5_, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_){
  62. //     
  63. //      String S = "this is firing1";
  64. //      MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(S));    
  65. //     
  66. //      return p_149660_9_;
  67. //     
  68. //    }
  69. //    @Override
  70. //    public void onPostBlockPlaced(World p_149714_1_, int p_149714_2_, int p_149714_3_, int p_149714_4_, int p_149714_5_)
  71. //    {
  72. //      String S = "this is firing2";
  73. //      MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(S));
  74. //      }
  75.  
  76.     @Override
  77.     public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) {
  78.         super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
  79.         p_149749_1_.removeTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
  80.     }
  81.  
  82.     @Override
  83.     public boolean onBlockEventReceived(World p_149696_1_, int p_149696_2_, int p_149696_3_, int p_149696_4_, int p_149696_5_, int p_149696_6_) {
  84.         super.onBlockEventReceived(p_149696_1_, p_149696_2_, p_149696_3_, p_149696_4_, p_149696_5_, p_149696_6_);
  85.         TileEntity tileentity = p_149696_1_.getTileEntity(p_149696_2_, p_149696_3_,  p_149696_4_);
  86.         return tileentity == null ? false : tileentity.receiveClientEvent(p_149696_5_, p_149696_6_);
  87.     }
  88. //@Override
  89. //public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
  90. //{String S = "this is firing";
  91. //MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(S));
  92. //  if(p_149689_5_ instanceof EntityPlayer){
  93. //  EntityPlayer E = (EntityPlayer) p_149689_5_;
  94. //   ((GearBedTileEntity) p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)).SetOwner("four");
  95. //     GearBedPlayerVariables.get(E).SetGearBedNumber(1);}
  96. //}    
  97.  
  98.     /**
  99.      * Called upon block activation (right click on the block.)
  100.      */
  101.     public boolean onBlockActivated(World world, int BlockX, int BlockY, int BlockZ, EntityPlayer player, int intA, float fA, float FB, float FC)
  102.    {
  103.         UUID U;
  104.         if( ((GearBedTileEntity) world.getTileEntity(BlockX, BlockY, BlockZ)).GetOwner() == null){
  105.          ((GearBedTileEntity) world.getTileEntity(BlockX, BlockY, BlockZ)).SetOwner(player.getUniqueID().toString());
  106.          U = UUID.fromString(((GearBedTileEntity) world.getTileEntity(BlockX, BlockY, BlockZ)).GetOwner());}
  107.         else{U = UUID.fromString(((GearBedTileEntity) world.getTileEntity(BlockX, BlockY, BlockZ)).GetOwner());}
  108.        
  109.         if(world.func_152378_a(U) == world.func_152378_a(player.getUniqueID()
  110.                 )){
  111.         if (world.isRemote) {
  112.             player.openGui(WTTI.instance,
  113.                     0, world, (int) player.posX, (int) player.posY, (int) player.posZ);
  114.         }}
  115.         else{
  116.              String S = "this is not yours";
  117.              String Y = "this is" + U.toString() + "'s";
  118.              String Z = "You are" + player.getUniqueID().toString();
  119.              if (!world.isRemote) {
  120.         MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(S));
  121.         MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(Y));
  122.         MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(Z));}
  123.         }
  124.         return true;
  125. //        if (world.isRemote)
  126. //        {
  127. //            return true;
  128. //        }
  129. //        else
  130. //        {
  131. //            int i1 = world.getBlockMetadata(BlockX, BlockY, BlockZ);
  132. //
  133. //            if (!isBlockHeadOfBed(i1))
  134. //            {
  135. //                int j1 = getDirection(i1);
  136. //                BlockX += field_149981_a[j1][0];
  137. //                BlockZ += field_149981_a[j1][1];
  138. //
  139. //                if (world.getBlock(BlockX, BlockY, BlockZ) != this)
  140. //                {
  141. //                    return true;
  142. //                }
  143. //
  144. //                i1 = world.getBlockMetadata(BlockX, BlockY, BlockZ);
  145. //            }
  146. //
  147. //            if (world.provider.canRespawnHere())
  148. //            {
  149. //                if (func_149976_c(i1))
  150. //                {
  151. //                    EntityPlayer entityplayer1 = null;
  152. //                    Iterator iterator = world.playerEntities.iterator();
  153. //
  154. //                    while (iterator.hasNext())
  155. //                    {
  156. //                        EntityPlayer entityplayer2 = (EntityPlayer)iterator.next();
  157. //
  158. //                        if (entityplayer2.isPlayerSleeping())
  159. //                        {
  160. //                            ChunkCoordinates chunkcoordinates = entityplayer2.playerLocation;
  161. //
  162. //                            if (chunkcoordinates.posX == BlockX && chunkcoordinates.posY == BlockY && chunkcoordinates.posZ == BlockZ)
  163. //                            {
  164. //                                entityplayer1 = entityplayer2;
  165. //                            }
  166. //                        }
  167. //                    }
  168. //
  169. //                    if (entityplayer1 != null)
  170. //                    {
  171. //                        player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.occupied", new Object[0]));
  172. //                        return true;
  173. //                    }
  174. //
  175. //                    func_149979_a(world, BlockX, BlockY, BlockZ, false);
  176. //                }
  177. //
  178. //                EntityPlayer.EnumStatus enumstatus = player.sleepInBedAt(BlockX, BlockY, BlockZ);
  179. //
  180. //                if (enumstatus == EntityPlayer.EnumStatus.OK)
  181. //                {
  182. //                    func_149979_a(world, BlockX, BlockY, BlockZ, true);
  183. //                    return true;
  184. //                }
  185. //                else
  186. //                {
  187. //                    if (enumstatus == EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW)
  188. //                    {
  189. //                      player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.noSleep", new Object[0]));
  190. //                    }
  191. //                    else if (enumstatus == EntityPlayer.EnumStatus.NOT_SAFE)
  192. //                    {
  193. //                      player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.notSafe", new Object[0]));
  194. //                    }
  195. //
  196. //                    return true;
  197. //                }
  198. //            }
  199. //            else
  200. //            {
  201. //                double d2 = (double)BlockX + 0.5D;
  202. //                double d0 = (double)BlockY + 0.5D;
  203. //                double d1 = (double)BlockZ + 0.5D;
  204. //                world.setBlockToAir(BlockX, BlockY, BlockZ);
  205. //                int k1 = getDirection(i1);
  206. //                BlockX += field_149981_a[k1][0];
  207. //                BlockZ += field_149981_a[k1][1];
  208. //
  209. //                if (world.getBlock(BlockX, BlockY, BlockZ) == this)
  210. //                {
  211. //                    world.setBlockToAir(BlockX, BlockY, BlockZ);
  212. //                    d2 = (d2 + (double)BlockX + 0.5D) / 2.0D;
  213. //                    d0 = (d0 + (double)BlockY + 0.5D) / 2.0D;
  214. //                    d1 = (d1 + (double)BlockZ + 0.5D) / 2.0D;
  215. //                }
  216. //
  217. //                world.newExplosion((Entity)null, (double)((float)BlockX + 0.5F), (double)((float)BlockY + 0.5F), (double)((float)BlockZ + 0.5F), 5.0F, true, true);
  218. //                return true;
  219. //            }
  220. //        }
  221.     }
  222.  
  223.     /**
  224.      * Gets the block's texture. Args: side, meta
  225.      */
  226.     @SideOnly(Side.CLIENT)
  227.     public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  228.     {
  229.         if (p_149691_1_ == 0)
  230.         {
  231.             return Blocks.planks.getBlockTextureFromSide(p_149691_1_);
  232.         }
  233.         else
  234.         {
  235.             int k = getDirection(p_149691_2_);
  236.             int l = Direction.bedDirection[k][p_149691_1_];
  237.             int i1 = isBlockHeadOfBed(p_149691_2_) ? 1 : 0;
  238.             return (i1 != 1 || l != 2) && (i1 != 0 || l != 3) ? (l != 5 && l != 4 ? this.field_149983_N[i1] : this.field_149982_M[i1]) : this.field_149980_b[i1];
  239.         }
  240.     }
  241.  
  242.     @SideOnly(Side.CLIENT)
  243.     public void registerBlockIcons(IIconRegister p_149651_1_)
  244.     {
  245.         this.field_149983_N = new IIcon[] {p_149651_1_.registerIcon("wtti" +":" + "gearbedmod/gearbed/gearbed_feet_top"), p_149651_1_.registerIcon("wtti" +":" + "gearbedmod/gearbed/gearbed_head_top")};
  246.         this.field_149980_b = new IIcon[] {p_149651_1_.registerIcon("wtti" +":" + "gearbedmod/gearbed/gearbed_feet_end"), p_149651_1_.registerIcon("wtti" +":" + "gearbedmod/gearbed/gearbed_head_end")};
  247.         this.field_149982_M = new IIcon[] {p_149651_1_.registerIcon("wtti" +":" + "gearbedmod/gearbed/gearbed_feet_side"), p_149651_1_.registerIcon("wtti" +":" + "gearbedmod/gearbed/gearbed_head_side")};
  248.     }
  249.  
  250.     /**
  251.      * The type of render function that is called for this block
  252.      */
  253.     public int getRenderType()
  254.     {
  255.         return 14;
  256.     }
  257.  
  258.     /**
  259.      * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  260.      */
  261.     public boolean renderAsNormalBlock()
  262.     {
  263.         return false;
  264.     }
  265.  
  266.  
  267.    
  268.    
  269.     /**
  270.      * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
  271.      * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  272.      */
  273.     public boolean isOpaqueCube()
  274.     {
  275.         return false;
  276.     }
  277.  
  278.     /**
  279.      * Updates the blocks bounds based on its current state. Args: world, x, y, z
  280.      */
  281.     public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_)
  282.     {
  283.         this.func_149978_e();
  284.     }
  285.  
  286.     /**
  287.      * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  288.      * their own) Args: x, y, z, neighbor Block
  289.      */
  290.     public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
  291.     {
  292.         int l = p_149695_1_.getBlockMetadata(p_149695_2_, p_149695_3_, p_149695_4_);
  293.         int i1 = getDirection(l);
  294.  
  295.         if (isBlockHeadOfBed(l))
  296.         {
  297.             if (p_149695_1_.getBlock(p_149695_2_ - field_149981_a[i1][0], p_149695_3_, p_149695_4_ - field_149981_a[i1][1]) != this)
  298.             {
  299.                 p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  300.             }
  301.         }
  302.         else if (p_149695_1_.getBlock(p_149695_2_ + field_149981_a[i1][0], p_149695_3_, p_149695_4_ + field_149981_a[i1][1]) != this)
  303.         {
  304.             p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  305.  
  306.             if (!p_149695_1_.isRemote)
  307.             {
  308.                 this.dropBlockAsItem(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, l, 0);
  309.             }
  310.         }
  311.     }
  312.  
  313.     public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
  314.     {
  315.         /**
  316.          * Returns whether or not this bed block is the head of the bed.
  317.          */
  318.         return isBlockHeadOfBed(p_149650_1_) ? Item.getItemById(0) : Items.bed;
  319.     }
  320.  
  321.     private void func_149978_e()
  322.     {
  323.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5625F, 1.0F);
  324.     }
  325.  
  326.     /**
  327.      * Returns whether or not this bed block is the head of the bed.
  328.      */
  329.     public static boolean isBlockHeadOfBed(int p_149975_0_)
  330.     {
  331.         return (p_149975_0_ & 8) != 0;
  332.     }
  333.  
  334.     public static boolean func_149976_c(int p_149976_0_)
  335.     {
  336.         return (p_149976_0_ & 4) != 0;
  337.     }
  338.  
  339.     public static void func_149979_a(World p_149979_0_, int p_149979_1_, int p_149979_2_, int p_149979_3_, boolean p_149979_4_)
  340.     {
  341.         int l = p_149979_0_.getBlockMetadata(p_149979_1_, p_149979_2_, p_149979_3_);
  342.  
  343.         if (p_149979_4_)
  344.         {
  345.             l |= 4;
  346.         }
  347.         else
  348.         {
  349.             l &= -5;
  350.         }
  351.  
  352.         p_149979_0_.setBlockMetadataWithNotify(p_149979_1_, p_149979_2_, p_149979_3_, l, 4);
  353.     }
  354.  
  355.     public static ChunkCoordinates func_149977_a(World p_149977_0_, int p_149977_1_, int p_149977_2_, int p_149977_3_, int p_149977_4_)
  356.     {
  357.         int i1 = p_149977_0_.getBlockMetadata(p_149977_1_, p_149977_2_, p_149977_3_);
  358.         int j1 = BlockDirectional.getDirection(i1);
  359.  
  360.         for (int k1 = 0; k1 <= 1; ++k1)
  361.         {
  362.             int l1 = p_149977_1_ - field_149981_a[j1][0] * k1 - 1;
  363.             int i2 = p_149977_3_ - field_149981_a[j1][1] * k1 - 1;
  364.             int j2 = l1 + 2;
  365.             int k2 = i2 + 2;
  366.  
  367.             for (int l2 = l1; l2 <= j2; ++l2)
  368.             {
  369.                 for (int i3 = i2; i3 <= k2; ++i3)
  370.                 {
  371.                     if (World.doesBlockHaveSolidTopSurface(p_149977_0_, l2, p_149977_2_ - 1, i3) && !p_149977_0_.getBlock(l2, p_149977_2_, i3).getMaterial().isOpaque() && !p_149977_0_.getBlock(l2, p_149977_2_ + 1, i3).getMaterial().isOpaque())
  372.                     {
  373.                         if (p_149977_4_ <= 0)
  374.                         {
  375.                             return new ChunkCoordinates(l2, p_149977_2_, i3);
  376.                         }
  377.  
  378.                         --p_149977_4_;
  379.                     }
  380.                 }
  381.             }
  382.         }
  383.  
  384.         return null;
  385.     }
  386.  
  387.     /**
  388.      * Drops the block items with a specified chance of dropping the specified items
  389.      */
  390.     public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
  391.     {
  392.         if (!isBlockHeadOfBed(p_149690_5_))
  393.         {
  394.             super.dropBlockAsItemWithChance(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, 0);
  395.         }
  396.     }
  397.  
  398.     /**
  399.      * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
  400.      * and stop pistons
  401.      */
  402.     public int getMobilityFlag()
  403.     {
  404.         return 1;
  405.     }
  406.  
  407.     /**
  408.      * Gets an item for the block being called on. Args: world, x, y, z
  409.      */
  410.     @SideOnly(Side.CLIENT)
  411.     public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
  412.     {
  413.         return Items.bed;
  414.     }
  415.  
  416.     /**
  417.      * Called when the block is attempted to be harvested
  418.      */
  419.     public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_)
  420.     {
  421.         if (p_149681_6_.capabilities.isCreativeMode && isBlockHeadOfBed(p_149681_5_))
  422.         {
  423.             int i1 = getDirection(p_149681_5_);
  424.             p_149681_2_ -= field_149981_a[i1][0];
  425.             p_149681_4_ -= field_149981_a[i1][1];
  426.  
  427.             if (p_149681_1_.getBlock(p_149681_2_, p_149681_3_, p_149681_4_) == this)
  428.             {
  429.                 p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_, p_149681_4_);
  430.             }
  431.         }
  432.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement