use of net.mcft.copy.betterstorage.attachment.IHasAttachments in project BetterStorage by copygirl.
the class ClientProxy method drawBlockHighlight.
@SubscribeEvent
public void drawBlockHighlight(DrawBlockHighlightEvent event) {
EntityPlayer player = event.player;
World world = player.worldObj;
MovingObjectPosition target = WorldUtils.rayTrace(player, event.partialTicks);
if ((target == null) || (target.typeOfHit != MovingObjectType.BLOCK))
return;
int x = target.blockX;
int y = target.blockY;
int z = target.blockZ;
AxisAlignedBB box = null;
Block block = world.getBlock(x, y, z);
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (block instanceof TileArmorStand)
box = getArmorStandHighlightBox(player, world, x, y, z, target.hitVec);
else if (block == Blocks.iron_door)
box = getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block);
else if (tileEntity instanceof IHasAttachments)
box = getAttachmentPointsHighlightBox(player, tileEntity, target);
if (box == null)
return;
double xOff = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
double yOff = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
double zOff = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;
box.offset(-xOff, -yOff, -zOff);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
GL11.glLineWidth(2.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDepthMask(false);
RenderGlobal.drawOutlinedBoundingBox(box, -1);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
event.setCanceled(true);
}
use of net.mcft.copy.betterstorage.attachment.IHasAttachments in project BetterStorage by copygirl.
the class ClientProxy method getAttachmentPointsHighlightBox.
private AxisAlignedBB getAttachmentPointsHighlightBox(EntityPlayer player, TileEntity tileEntity, MovingObjectPosition target) {
Attachments attachments = ((IHasAttachments) tileEntity).getAttachments();
Attachment attachment = attachments.get(target.subHit);
if (attachment == null)
return null;
return attachment.getHighlightBox();
}
use of net.mcft.copy.betterstorage.attachment.IHasAttachments in project BetterStorage by copygirl.
the class TileLockableDoor method collisionRayTrace.
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 start, Vec3 end) {
int metadata = world.getBlockMetadata(x, y, z);
IHasAttachments te = WorldUtils.get(world, x, y - (metadata > 0 ? 1 : 0), z, IHasAttachments.class);
if (te == null)
return super.collisionRayTrace(world, x, y, z, start, end);
MovingObjectPosition pos = te.getAttachments().rayTrace(world, x, y - (metadata > 0 ? 1 : 0), z, start, end);
return pos != null ? pos : super.collisionRayTrace(world, x, y, z, start, end);
}
use of net.mcft.copy.betterstorage.attachment.IHasAttachments in project BetterStorage by copygirl.
the class CommonProxy method onPlayerInteract.
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
World world = event.entity.worldObj;
int x = event.x;
int y = event.y;
int z = event.z;
EntityPlayer player = event.entityPlayer;
ItemStack holding = player.getCurrentEquippedItem();
Block block = world.getBlock(x, y, z);
boolean leftClick = (event.action == Action.LEFT_CLICK_BLOCK);
boolean rightClick = (event.action == Action.RIGHT_CLICK_BLOCK);
// Interact with attachments.
if (leftClick || rightClick) {
IHasAttachments hasAttachments = WorldUtils.get(world, x, y, z, IHasAttachments.class);
if (hasAttachments != null) {
EnumAttachmentInteraction interactionType = ((event.action == Action.LEFT_CLICK_BLOCK) ? EnumAttachmentInteraction.attack : EnumAttachmentInteraction.use);
if (hasAttachments.getAttachments().interact(WorldUtils.rayTrace(player, 1.0F), player, interactionType)) {
event.useBlock = Result.DENY;
event.useItem = Result.DENY;
}
}
}
// Use cauldron to remove color from dyable items
if (rightClick && (block == Blocks.cauldron)) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata > 0) {
IDyeableItem dyeable = (((holding != null) && (holding.getItem() instanceof IDyeableItem)) ? (IDyeableItem) holding.getItem() : null);
if ((dyeable != null) && (dyeable.canDye(holding))) {
StackUtils.remove(holding, "display", "color");
world.setBlockMetadataWithNotify(x, y, z, metadata - 1, 2);
world.func_147453_f(x, y, z, block);
event.useBlock = Result.DENY;
event.useItem = Result.DENY;
}
}
}
// Prevent players from breaking blocks with broken cardboard items.
if (leftClick && (holding != null) && (holding.getItem() instanceof ICardboardItem) && !ItemCardboardSheet.isEffective(holding))
event.useItem = Result.DENY;
// Attach locks to iron doors.
if (!world.isRemote && BetterStorageTiles.lockableDoor != null && rightClick && block == Blocks.iron_door) {
MovingObjectPosition target = WorldUtils.rayTrace(player, 1F);
if (target != null && getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block) != null) {
int meta = world.getBlockMetadata(x, y, z);
boolean isMirrored;
if (meta >= 8) {
isMirrored = meta == 9;
y -= 1;
meta = world.getBlockMetadata(x, y, z);
} else
isMirrored = world.getBlockMetadata(x, y + 1, z) == 9;
int rotation = meta & 3;
ForgeDirection orientation = rotation == 0 ? ForgeDirection.WEST : rotation == 1 ? ForgeDirection.NORTH : rotation == 2 ? ForgeDirection.EAST : ForgeDirection.SOUTH;
orientation = isMirrored ? (orientation == ForgeDirection.WEST ? ForgeDirection.SOUTH : orientation == ForgeDirection.NORTH ? ForgeDirection.WEST : orientation == ForgeDirection.EAST ? ForgeDirection.NORTH : ForgeDirection.EAST) : orientation;
world.setBlock(x, y, z, BetterStorageTiles.lockableDoor, 0, SetBlockFlag.SEND_TO_CLIENT);
world.setBlock(x, y + 1, z, BetterStorageTiles.lockableDoor, 8, SetBlockFlag.SEND_TO_CLIENT);
TileEntityLockableDoor te = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
te.orientation = orientation;
te.isOpen = isMirrored;
te.isMirrored = isMirrored;
te.setLock(holding);
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
// Prevent eating of slime buckets after capturing them.
if (preventSlimeBucketUse) {
event.setCanceled(true);
preventSlimeBucketUse = false;
}
}
use of net.mcft.copy.betterstorage.attachment.IHasAttachments in project BetterStorage by copygirl.
the class TileContainerBetterStorage method getPickBlock.
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileEntityContainer container = getContainer(world, x, y, z);
if (container instanceof IHasAttachments) {
ItemStack pick = ((IHasAttachments) container).getAttachments().pick(target);
if (pick != null)
return pick;
}
ItemStack pick = super.getPickBlock(target, world, x, y, z);
return container.onPickBlock(pick, target);
}
Aggregations