Java Code Examples for net.minecraft.init.Blocks#CHEST
The following examples show how to use
net.minecraft.init.Blocks#CHEST .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileEntityGnomeCache.java From CommunityMod with GNU Lesser General Public License v2.1 | 6 votes |
/** * Iterates over the list of loaded tile entities once per tick to find a chest * Returns a position of the chest if a chest is found with at least one item in it * @return */ public BlockPos findTargetChest() { List<TileEntity> list = this.world.loadedTileEntityList; if (this.target_chest_iter >= list.size()) { this.target_chest_iter = 0; } TileEntity potential_entity = (TileEntity) list.get(this.target_chest_iter); BlockPos tepos = potential_entity.getPos(); this.target_chest_iter++; if (potential_entity != null && this.world.getBlockState(tepos).getBlock() == Blocks.CHEST) { // TODO maybe put a try/catch here? (life should go on) TileEntityChest chestent = (TileEntityChest)potential_entity; for (int i = 0; i < chestent.getSizeInventory(); i++) { if (chestent.getStackInSlot(i) != null) { return tepos; } } } return null; }
Example 2
Source File: TreasureChest.java From minecraft-roguelike with GNU General Public License v3.0 | 6 votes |
public ITreasureChest generate(IWorldEditor editor, Random rand, Coord pos, int level, boolean trapped) throws ChestPlacementException { this.rand = rand; this.level = level; MetaBlock chestType = new MetaBlock(trapped ? Blocks.TRAPPED_CHEST : Blocks.CHEST); boolean success = chestType.set(editor, pos); if(!success){ throw new ChestPlacementException("Failed to place chest in world"); } this.chest = (TileEntityChest) editor.getTileEntity(pos); this.inventory = new Inventory(rand, chest); this.seed = (long)Objects.hash(pos.hashCode(), editor.getSeed()); editor.addChest(this); return this; }
Example 3
Source File: JobChestSteal.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
public void finishJob(boolean near) { EntityGnomeWood gnomewood = (EntityGnomeWood)this.gnome; TileEntityGnomeCache cache = (TileEntityGnomeCache) gnomewood.gnode; if (near && gnomewood.gnode != null) { // if this is still a chest IBlockState state = gnomewood.world.getBlockState(this.pos); if (state.getBlock() == Blocks.CHEST) { TileEntityChest te = (TileEntityChest)gnomewood.world.getTileEntity(this.pos); if (te.numPlayersUsing == 0) { // move contents of chest from chest to gnome for (int i = 0; i < 27; i++) { gnomewood.inventory[i] = te.getStackInSlot(i); te.setInventorySlotContents(i, ItemStack.EMPTY); } if (!gnomewood.world.isRemote) { gnomewood.world.setBlockToAir(this.pos); gnomewood.setCarriedState(state); } } } cache.resetChestTracker(); } }
Example 4
Source File: EntityGnomeWood.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void onDeath(DamageSource damage) { if (this.getCarried().getBlock() == Blocks.CHEST) { this.dropChest(); } if (this.gnode != null) { //this.gnode.denizen = null; this.gnode.onGnomeDeath(); this.gnode.selfDestruct(); } }
Example 5
Source File: MageTowerGenerator.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
protected void addLootToChest(World world, IBlockState block, BlockPos placementPos) { if (block.getBlock() == Blocks.CHEST) { TileEntity tileentity = world.getTileEntity(placementPos); if (tileentity instanceof TileEntityChest) { ((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_END_CITY_TREASURE, world.rand.nextLong()); } } }
Example 6
Source File: BastionsLairGenerator.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
protected void addLootToChest() { if (block == null) { return; } if (block.getBlock() == Blocks.CHEST) { TileEntity tileentity = world.getTileEntity(origin.add(x, y, z)); if (tileentity instanceof TileEntityChest) { ((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_END_CITY_TREASURE, world.rand.nextLong()); } } }
Example 7
Source File: ItemChestUpgrade.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { if (world.isRemote) { return EnumActionResult.PASS; } IBlockState state = world.getBlockState(pos); TileEntity te = world.getTileEntity(pos); if (state.getBlock() == Blocks.CHEST && te instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) te; ItemStack[] items = new ItemStack[chest.getSizeInventory()]; for (int i = 0; i < items.length; i++) { items[i] = chest.getStackInSlot(i); chest.setInventorySlotContents(i, ItemStack.EMPTY); } IBlockState newState = BlocksItemsBetterChests.betterchest.getDefaultState().withProperty(BlockBetterChest.directions, state.getValue(BlockChest.FACING)); world.setBlockState(pos, newState, 2); TileEntityBChest newte = new TileEntityBChest(); world.setTileEntity(pos, newte); for (int i = 0; i < items.length; i++) { newte.getChestPart().setInventorySlotContents(i, items[i]); } world.notifyBlockUpdate(pos, state, newState, 1); ItemStack heldItem = player.getHeldItem(hand); heldItem.setCount(heldItem.getCount() - 1); return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
Example 8
Source File: WorldEditor.java From minecraft-roguelike with GNU General Public License v3.0 | 5 votes |
private boolean setBlock(Coord pos, MetaBlock block, int flags, boolean fillAir, boolean replaceSolid){ MetaBlock currentBlock = getBlock(pos); if(currentBlock.getBlock() == Blocks.CHEST) return false; if(currentBlock.getBlock() == Blocks.TRAPPED_CHEST) return false; if(currentBlock.getBlock() == Blocks.MOB_SPAWNER) return false; //boolean isAir = world.isAirBlock(pos.getBlockPos()); boolean isAir = currentBlock.getBlock() == Blocks.AIR; if(!fillAir && isAir) return false; if(!replaceSolid && !isAir) return false; try{ world.setBlockState(pos.getBlockPos(), block.getState(), flags); } catch(NullPointerException npe){ //ignore it. } Block type = block.getBlock(); Integer count = stats.get(type); if(count == null){ stats.put(type, 1); } else { stats.put(type, count + 1); } return true; }