use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.
the class DroneAIPlace method isValidPosition.
@Override
protected boolean isValidPosition(ChunkPosition pos) {
if (drone.getWorld().isAirBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
boolean failedOnPlacement = false;
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack droneStack = drone.getInventory().getStackInSlot(i);
if (droneStack != null && droneStack.getItem() instanceof ItemBlock) {
if (widget.isItemValidForFilters(droneStack)) {
if (((ItemBlock) droneStack.getItem()).field_150939_a.canPlaceBlockOnSide(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()).ordinal())) {
if (drone instanceof EntityDrone) {
EntityDrone entity = (EntityDrone) drone;
//Teleport the drone to make sure it isn't in the way of placing a block.
entity.setPosition(entity.posX, entity.posY + 200, entity.posZ);
}
if (drone.getWorld().canPlaceEntityOnSide(((ItemBlock) droneStack.getItem()).field_150939_a, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, false, 0, null, droneStack)) {
if (drone instanceof EntityDrone) {
EntityDrone entity = (EntityDrone) drone;
entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
}
return true;
} else {
if (drone instanceof EntityDrone) {
EntityDrone entity = (EntityDrone) drone;
entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
}
drone.addDebugEntry("gui.progWidget.place.debug.entityInWay", pos);
failedOnPlacement = true;
}
} else {
failedOnPlacement = true;
drone.addDebugEntry("gui.progWidget.place.debug.cantPlaceBlock", pos);
}
}
}
}
if (!failedOnPlacement)
abort();
}
return false;
}
use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.
the class BlockChargingStation method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
if (!world.isRemote && player.isSneaking()) {
TileEntityChargingStation station = (TileEntityChargingStation) world.getTileEntity(x, y, z);
station.setCamoStack(player.getCurrentEquippedItem());
return player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemBlock;
} else
return super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
}
use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.
the class EventHandlerPneumaticCraft method onPlayerClick.
@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event) {
Block interactedBlock = event.world.getBlock(event.x, event.y, event.z);
if (!event.entityPlayer.capabilities.isCreativeMode || !event.entityPlayer.canCommandSenderUseCommand(2, "securityStation")) {
if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_AIR && event.world != null && !event.world.isRemote) {
if (interactedBlock != Blockss.securityStation || event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
ItemStack heldItem = event.entityPlayer.getCurrentEquippedItem();
boolean tryingToPlaceSecurityStation = heldItem != null && heldItem.getItem() instanceof ItemBlock && ((ItemBlock) heldItem.getItem()).field_150939_a == Blockss.securityStation;
int blockingStations = PneumaticCraftUtils.getProtectingSecurityStations(event.entity.worldObj, event.x, event.y, event.z, event.entityPlayer, true, tryingToPlaceSecurityStation);
if (blockingStations > 0) {
event.setCanceled(true);
event.entityPlayer.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(tryingToPlaceSecurityStation ? "message.securityStation.stationPlacementPrevented" : "message.securityStation.accessPrevented", blockingStations)));
}
}
}
}
/**
* Due to some weird quirk that causes Block#onBlockActivated not getting called on the server when the player is sneaking, this is a workaround.
*/
if (!event.isCanceled() && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !event.world.isRemote) {
if (event.entityPlayer.isSneaking() && (interactedBlock == Blockss.elevatorCaller || interactedBlock == Blockss.chargingStation)) {
event.setCanceled(interactedBlock.onBlockActivated(event.world, event.x, event.y, event.z, event.entityPlayer, event.face, 0, 0, 0));
} else if (event.entityPlayer.getCurrentEquippedItem() != null && ModInteractionUtilImplementation.getInstance().isModdedWrench(event.entityPlayer.getCurrentEquippedItem().getItem())) {
if (interactedBlock instanceof IPneumaticWrenchable) {
((IPneumaticWrenchable) interactedBlock).rotateBlock(event.world, event.entityPlayer, event.x, event.y, event.z, ForgeDirection.getOrientation(event.face));
}
}
}
if (!event.isCanceled() && interactedBlock == Blocks.cobblestone) {
AchievementHandler.checkFor9x9(event.entityPlayer, event.x, event.y, event.z);
}
}
use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.
the class BlockPneumaticDoorBase method shouldSideBeRendered.
@Override
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) {
ForgeDirection d = ForgeDirection.getOrientation(side);
TileEntityPneumaticDoorBase te = (TileEntityPneumaticDoorBase) world.getTileEntity(x - d.offsetX, y - d.offsetY, z - d.offsetZ);
ItemStack camoStack = te.getStackInSlot(TileEntityPneumaticDoorBase.CAMO_SLOT);
if (camoStack != null && camoStack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) camoStack.getItem()).field_150939_a;
if (PneumaticCraftUtils.isRenderIDCamo(block.getRenderType())) {
return true;
}
}
return false;
}
use of net.minecraft.item.ItemBlock in project PneumaticCraft by MineMaarten.
the class TileEntityElevatorCaller method onDescUpdate.
@Override
public void onDescUpdate() {
Block newCamo = camoStack != null && camoStack.getItem() instanceof ItemBlock ? ((ItemBlock) camoStack.getItem()).field_150939_a : null;
if (newCamo != camoBlock) {
camoBlock = newCamo;
rerenderChunk();
}
}
Aggregations