Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.azizsmod.aziz.events;
- import java.util.List;
- import com.azizsmod.aziz.init.BlockInit;
- import com.azizsmod.aziz.util.Reference;
- import ca.weblite.objc.Client;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.multiplayer.WorldClient;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.World;
- import net.minecraftforge.event.entity.player.PlayerInteractEvent;
- import net.minecraftforge.fml.common.Mod;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- @Mod.EventBusSubscriber(modid = Reference.MOD_ID)
- public class Oak_ChairSit
- {
- @SubscribeEvent
- public static final void OnInteractWithBlock(PlayerInteractEvent.RightClickBlock event)
- {
- EntityPlayer player =event.getEntityPlayer();
- if(player.getRidingEntity() != null)
- {
- return;
- }
- World worldIn = event.getWorld();
- BlockPos pos = event.getPos();
- Vec3d vec = new Vec3d(pos.getX() +0.5, pos.getY(), pos.getZ() + 0.5);
- double maxDist = 2.0D;
- 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)
- {
- return;
- }
- IBlockState state = worldIn.getBlockState(pos);
- ItemStack mainStack = player.getHeldItemMainhand();
- ItemStack offStack = player.getHeldItemOffhand();
- if(!mainStack.isEmpty() || !offStack.isEmpty())
- {
- return;
- }
- if(state.getBlock().equals(BlockInit.OAK_CHAIR))
- {
- List<SeatOak_Chair> seats = worldIn.getEntitiesWithinAABB(SeatOak_Chair.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)));
- SeatOak_Chair seat = new SeatOak_Chair(worldIn, pos);
- worldIn.spawnEntity(seat);
- player.startRiding(seat);
- }
- }
- public static class SeatOak_Chair extends Entity
- {
- public SeatOak_Chair(World worldIn, BlockPos pos)
- {
- this(worldIn);
- setPosition(pos.getX() + 0.5D, pos.getY() + 0.4D, pos.getZ() + 0.5D);
- }
- public SeatOak_Chair(World worldIn)
- {
- super(worldIn);
- setSize(0.0f, 0.0F);
- }
- @Override
- public void onUpdate()
- {
- super.onUpdate();
- BlockPos pos = getPosition();
- if(!(getEntityWorld().getBlockState(pos).getBlock().equals(BlockInit.OAK_CHAIR)))
- {
- setDead();
- return;
- }
- List<Entity> passengers = getPassengers();
- if(passengers.isEmpty())
- {
- setDead();
- }
- for(Entity entity : passengers)
- {
- if(entity.isSneaking())
- {
- setDead();
- }
- }
- }
- @Override
- protected void entityInit()
- {
- }
- @Override
- protected void readEntityFromNBT(NBTTagCompound compound)
- {
- }
- @Override
- protected void writeEntityToNBT(NBTTagCompound compound)
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment