Guest User

oak_ChairSit

a guest
Apr 29th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. package com.azizsmod.aziz.events;
  2.  
  3.  
  4.  
  5. import java.util.List;
  6.  
  7.  
  8.  
  9. import com.azizsmod.aziz.init.BlockInit;
  10.  
  11. import com.azizsmod.aziz.util.Reference;
  12.  
  13.  
  14.  
  15. import ca.weblite.objc.Client;
  16.  
  17. import net.minecraft.block.state.IBlockState;
  18.  
  19. import net.minecraft.client.multiplayer.WorldClient;
  20.  
  21. import net.minecraft.entity.Entity;
  22.  
  23. import net.minecraft.entity.player.EntityPlayer;
  24.  
  25. import net.minecraft.item.ItemStack;
  26.  
  27. import net.minecraft.nbt.NBTTagCompound;
  28.  
  29. import net.minecraft.util.math.AxisAlignedBB;
  30.  
  31. import net.minecraft.util.math.BlockPos;
  32.  
  33. import net.minecraft.util.math.Vec3d;
  34.  
  35. import net.minecraft.world.World;
  36.  
  37. import net.minecraftforge.event.entity.player.PlayerInteractEvent;
  38.  
  39. import net.minecraftforge.fml.common.Mod;
  40.  
  41. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  42.  
  43. import net.minecraftforge.fml.relauncher.Side;
  44.  
  45. import net.minecraftforge.fml.relauncher.SideOnly;
  46.  
  47.  
  48.  
  49.  
  50.  
  51. @Mod.EventBusSubscriber(modid = Reference.MOD_ID)
  52.  
  53. public class Oak_ChairSit
  54.  
  55. {
  56.  
  57. @SubscribeEvent
  58.  
  59. public static final void OnInteractWithBlock(PlayerInteractEvent.RightClickBlock event)
  60.  
  61. {
  62.  
  63. EntityPlayer player =event.getEntityPlayer();
  64.  
  65. if(player.getRidingEntity() != null)
  66.  
  67. {
  68.  
  69. return;
  70.  
  71. }
  72.  
  73.  
  74.  
  75. World worldIn = event.getWorld();
  76.  
  77. BlockPos pos = event.getPos();
  78.  
  79. Vec3d vec = new Vec3d(pos.getX() +0.5, pos.getY(), pos.getZ() + 0.5);
  80.  
  81. double maxDist = 2.0D;
  82.  
  83. if((vec.x - player.posX) * (vec.x - player.posX) + (vec.y - player.posY) * (vec.y - player.posY) + (vec.z - player.posZ) * (vec.z - player.posZ) > maxDist * maxDist)
  84.  
  85. {
  86.  
  87. return;
  88.  
  89. }
  90.  
  91.  
  92.  
  93. IBlockState state = worldIn.getBlockState(pos);
  94.  
  95. ItemStack mainStack = player.getHeldItemMainhand();
  96.  
  97. ItemStack offStack = player.getHeldItemOffhand();
  98.  
  99. if(!mainStack.isEmpty() || !offStack.isEmpty())
  100.  
  101. {
  102.  
  103. return;
  104.  
  105. }
  106.  
  107.  
  108.  
  109. if(state.getBlock().equals(BlockInit.OAK_CHAIR))
  110.  
  111. {
  112.  
  113. List<SeatOak_Chair> seats = worldIn.getEntitiesWithinAABB(SeatOak_Chair.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)));
  114.  
  115. SeatOak_Chair seat = new SeatOak_Chair(worldIn, pos);
  116.  
  117. worldIn.spawnEntity(seat);
  118.  
  119. player.startRiding(seat);
  120.  
  121. }
  122.  
  123. }
  124.  
  125. public static class SeatOak_Chair extends Entity
  126.  
  127. {
  128.  
  129. public SeatOak_Chair(World worldIn, BlockPos pos)
  130.  
  131. {
  132.  
  133. this(worldIn);
  134.  
  135. setPosition(pos.getX() + 0.5D, pos.getY() + 0.4D, pos.getZ() + 0.5D);
  136.  
  137. }
  138.  
  139.  
  140.  
  141. public SeatOak_Chair(World worldIn)
  142.  
  143. {
  144.  
  145. super(worldIn);
  146.  
  147. setSize(0.0f, 0.0F);
  148.  
  149. }
  150.  
  151.  
  152.  
  153. @Override
  154.  
  155. public void onUpdate()
  156.  
  157. {
  158.  
  159. super.onUpdate();
  160.  
  161. BlockPos pos = getPosition();
  162.  
  163. if(!(getEntityWorld().getBlockState(pos).getBlock().equals(BlockInit.OAK_CHAIR)))
  164.  
  165. {
  166.  
  167. setDead();
  168.  
  169. return;
  170.  
  171. }
  172.  
  173.  
  174.  
  175. List<Entity> passengers = getPassengers();
  176.  
  177. if(passengers.isEmpty())
  178.  
  179. {
  180.  
  181. setDead();
  182.  
  183. }
  184.  
  185. for(Entity entity : passengers)
  186.  
  187. {
  188.  
  189. if(entity.isSneaking())
  190.  
  191. {
  192.  
  193. setDead();
  194.  
  195. }
  196.  
  197. }
  198.  
  199. }
  200.  
  201.  
  202.  
  203.  
  204.  
  205. @Override
  206.  
  207. protected void entityInit()
  208.  
  209. {
  210.  
  211.  
  212.  
  213. }
  214.  
  215.  
  216.  
  217. @Override
  218.  
  219. protected void readEntityFromNBT(NBTTagCompound compound)
  220.  
  221. {
  222.  
  223.  
  224.  
  225. }
  226.  
  227.  
  228.  
  229. @Override
  230.  
  231. protected void writeEntityToNBT(NBTTagCompound compound)
  232.  
  233. {
  234.  
  235.  
  236.  
  237. }
  238.  
  239. }
  240.  
  241. }
Add Comment
Please, Sign In to add comment