use of net.minecraft.item.ItemBlock in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method rightClickWithItem.
public void rightClickWithItem(@Nonnull World worldIn, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos, @Nonnull EnumFacing sideHit, float hitX, float hitY, float hitZ) {
ItemStack multiTool = player.getHeldItemMainhand();
if (multiTool.getItem() != this) {
return;
}
NBTTagCompound tagCompound = multiTool.getTagCompound();
if (tagCompound == null || !tagCompound.hasKey("Item")) {
player.sendStatusMessage(new TextComponentString("No block type selected to place."), true);
return;
}
NBTTagCompound itemTag = tagCompound.getCompoundTag("Item");
ItemStack blockStack = new ItemStack(itemTag);
if (!(blockStack.getItem() instanceof ItemBlock)) {
player.sendStatusMessage(new TextComponentString("No valid block type selected to place."), true);
return;
}
IEnergyStorage energy = multiTool.getCapability(ENERGY, null);
Vec3i sideVector = sideHit.getDirectionVec();
BlockPos.MutableBlockPos newPosition = new BlockPos.MutableBlockPos(pos.add(sideVector));
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
return;
if (player.isSneaking()) {
BlockPos playerPos = player.getPosition();
switch(sideHit) {
case UP:
while (newPosition.getY() < playerPos.getY()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case DOWN:
while (newPosition.getY() > playerPos.getY()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case NORTH:
while (newPosition.getZ() > playerPos.getZ()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case SOUTH:
while (newPosition.getZ() < playerPos.getZ()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case EAST:
while (newPosition.getX() < playerPos.getX()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case WEST:
while (newPosition.getX() > playerPos.getX()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
}
}
}
use of net.minecraft.item.ItemBlock in project LogisticsPipes by RS485.
the class LogisticsRenderPipe method renderItemStackOnSign.
public void renderItemStackOnSign(ItemStack itemstack) {
if (itemstack == null || itemstack.getItem() == null) {
// Only happens on false configuration
return;
}
Item item = itemstack.getItem();
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack, ItemRenderType.INVENTORY);
Minecraft.getMinecraft().renderEngine.bindTexture(itemstack.getItemSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture);
GL11.glPushMatrix();
if (customRenderer != null) {
if (customRenderer.shouldUseRenderHelper(ItemRenderType.INVENTORY, itemstack, ItemRendererHelper.INVENTORY_BLOCK)) {
GL11.glScalef(0.20F, -0.20F, -0.01F);
GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(-45.0F, 0.0F, 1.0F, 0.0F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
customRenderer.renderItem(ItemRenderType.INVENTORY, itemstack, renderBlocks);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
} else {
GL11.glScalef(0.018F, -0.018F, -0.01F);
GL11.glTranslatef(-7F, -8F, 0F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
customRenderer.renderItem(ItemRenderType.INVENTORY, itemstack, renderBlocks);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
}
} else if (item instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(item).getRenderType())) {
GL11.glScalef(0.20F, -0.20F, -0.01F);
GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(-45.0F, 0.0F, 1.0F, 0.0F);
renderBlocks.useInventoryTint = false;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
renderBlocks.renderBlockAsItem(Block.getBlockFromItem(item), itemstack.getItemDamage(), 1.0F);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
} else {
GL11.glScalef(0.02F, -0.02F, -0.01F);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
GL11.glTranslatef(-8F, -8F, 0.0F);
if (item.requiresMultipleRenderPasses()) {
for (int var14 = 0; var14 < item.getRenderPasses(itemstack.getItemDamage()); ++var14) {
IIcon var15 = item.getIconFromDamageForRenderPass(itemstack.getItemDamage(), var14);
renderItem(var15);
}
} else {
renderItem(item.getIconIndex(itemstack));
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
}
GL11.glPopMatrix();
}
use of net.minecraft.item.ItemBlock in project LogisticsPipes by RS485.
the class ItemStackRenderer method renderInWorld.
public void renderInWorld() {
assert renderManager != null;
assert renderItem != null;
assert scaleX != 0.0F;
assert scaleY != 0.0F;
assert scaleZ != 0.0F;
if (entityitem == null || !ItemStack.areItemStacksEqual(entityitem.getEntityItem(), itemstack)) {
if (itemstack == null) {
throw new RuntimeException("No EntityItem and no ItemStack, I do not know what to render!");
} else {
if (worldObj == null) {
throw new NullPointerException("World object is null");
}
entityitem = new EntityItem(worldObj, 0.0D, 0.0D, 0.0D, itemstack);
entityitem.getEntityItem().stackSize = 1;
entityitem.hoverStart = 0.0F;
}
}
boolean changeColor = renderItem.renderWithColor != renderInColor;
if (changeColor) {
renderItem.renderWithColor = renderInColor;
}
Item item = itemstack.getItem();
if (item instanceof ItemBlock) {
Block block = ((ItemBlock) item).field_150939_a;
if (block instanceof BlockPane) {
GL11.glScalef(0.5F, 0.5F, 0.5F);
}
} else if (item == LogisticsPipes.logisticsRequestTable) {
GL11.glScalef(0.5F, 0.5F, 0.5F);
}
renderManager.renderEntityWithPosYaw(entityitem, posX, posY, zLevel, 0.0F, partialTickTime);
if (changeColor) {
renderItem.renderWithColor = !renderInColor;
}
}
use of net.minecraft.item.ItemBlock in project LogisticsPipes by RS485.
the class ModuleCrafter method openAttachedGui.
public void openAttachedGui(EntityPlayer player) {
if (MainProxy.isClient(player.worldObj)) {
if (player instanceof EntityPlayerMP) {
player.closeScreen();
} else if (player instanceof EntityPlayerSP) {
player.closeScreen();
}
MainProxy.sendPacketToServer(PacketHandler.getPacket(CraftingPipeOpenConnectedGuiPacket.class).setModulePos(this));
return;
}
// hack to avoid wrenching blocks
int savedEquipped = player.inventory.currentItem;
boolean foundSlot = false;
// try to find a empty slot
for (int i = 0; i < 9; i++) {
if (player.inventory.getStackInSlot(i) == null) {
foundSlot = true;
player.inventory.currentItem = i;
break;
}
}
// okay, anything that's a block?
if (!foundSlot) {
for (int i = 0; i < 9; i++) {
ItemStack is = player.inventory.getStackInSlot(i);
if (is.getItem() instanceof ItemBlock) {
foundSlot = true;
player.inventory.currentItem = i;
break;
}
}
}
// give up and select whatever is right of the current slot
if (!foundSlot) {
player.inventory.currentItem = (player.inventory.currentItem + 1) % 9;
}
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), getX(), getY(), getZ());
worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).anyMatch(adjacent -> {
boolean found = SimpleServiceLocator.craftingRecipeProviders.stream().anyMatch(provider -> provider.canOpenGui(adjacent.tileEntity));
if (!found) {
found = (adjacent.tileEntity instanceof IInventory);
}
if (found) {
Block block = getWorld().getBlock(adjacent.tileEntity.xCoord, adjacent.tileEntity.yCoord, adjacent.tileEntity.zCoord);
if (block != null && block.onBlockActivated(getWorld(), adjacent.tileEntity.xCoord, adjacent.tileEntity.yCoord, adjacent.tileEntity.zCoord, player, 0, 0, 0, 0)) {
return true;
}
}
return false;
});
player.inventory.currentItem = savedEquipped;
}
use of net.minecraft.item.ItemBlock in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockTurretBase method clOnBlockActivated.
@Override
protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
ItemStack heldItem = player.getHeldItemMainhand();
TurretBase base = (TurretBase) world.getTileEntity(pos);
if (player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem == ItemStackTools.getEmptyStack()) {
if (base != null) {
if (player.getUniqueID().toString().equals(base.getOwner())) {
base.setCamoState(state);
world.notifyBlockUpdate(pos, state, state, 3);
} else {
addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
}
}
}
Block heldItemBlock = null;
if (heldItem != ItemStackTools.getEmptyStack()) {
heldItemBlock = Block.getBlockFromItem(heldItem.getItem());
}
if (!player.isSneaking() && ConfigHandler.isAllowBaseCamo() && heldItem != ItemStackTools.getEmptyStack() && heldItem.getItem() instanceof ItemBlock && heldItemBlock.isNormalCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && Block.getBlockFromItem(heldItem.getItem()).isOpaqueCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && !(Block.getBlockFromItem(heldItem.getItem()) instanceof BlockTurretBase)) {
if (base != null) {
if (player.getUniqueID().toString().equals(base.getOwner())) {
base.setCamoState(heldItemBlock.getStateFromMeta(heldItem.getItemDamage()));
world.notifyBlockUpdate(pos, state, state, 3);
} else {
addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
}
}
} else if (player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2) {
((UsableMetaItem) player.getHeldItemMainhand().getItem()).setDataStored(player.getHeldItemMainhand(), base.writeMemoryCardNBT());
} else if (!player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStackTools.getEmptyStack() && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2 && ((UsableMetaItem) player.getHeldItemMainhand().getItem()).hasDataStored(player.getHeldItemMainhand())) {
base.readMemoryCardNBT(((UsableMetaItem) player.getHeldItemMainhand().getItem()).getDataStored(player.getHeldItemMainhand()));
} else if (!player.isSneaking() && base != null) {
TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
if (trustedPlayer != null && trustedPlayer.canOpenGUI) {
world.notifyBlockUpdate(pos, state, state, 6);
player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
return true;
} else if (PlayerUtil.isPlayerOwner(player, base)) {
world.notifyBlockUpdate(pos, state, state, 6);
player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
} else {
addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
}
}
}
return true;
}
Aggregations