/** * Force loot generation, as this is required on the client side to peek inside inventories. * The client is not able to generate the loot. * @param te */ private void forceLootGeneration(TileEntity te){ if(te instanceof TileEntityLockableLoot){ TileEntityLockableLoot teLoot = (TileEntityLockableLoot)te; teLoot.fillWithLoot(null); } }
protected void DrawPrimitive( DrawContainer c, World w ) throws Exception { // First, draw the container block: String cType = c.getType().value(); BlockType bType = BlockType.fromValue(cType); // Safe - ContainerType is a subset of BlockType XMLBlockState blockType = new XMLBlockState(bType, c.getColour(), c.getFace(), c.getVariant()); if (!blockType.isValid()) throw new Exception("Unrecogised item type: " + c.getType().value()); BlockPos pos = new BlockPos( c.getX(), c.getY(), c.getZ() ); setBlockState(w, pos, blockType ); // Now fill the container: TileEntity tileentity = w.getTileEntity(pos); if (tileentity instanceof TileEntityLockableLoot) { // First clear out any leftovers: ((TileEntityLockableLoot)tileentity).clear(); int index = 0; for (ContainedObjectType cot : c.getObject()) { DrawItem di = new DrawItem(); di.setColour(cot.getColour()); di.setType(cot.getType()); di.setVariant(cot.getVariant()); ItemStack stack = MinecraftTypeHelper.getItemStackFromDrawItem(di); stack.setCount(cot.getQuantity()); ((TileEntityLockableLoot)tileentity).setInventorySlotContents(index, stack); index++; } } }
public void generateTower(WorldServer world, BlockPos pos, Random rand) { MinecraftServer server = world.getMinecraftServer(); Template template = world.getStructureTemplateManager().getTemplate(server, TOWER_STRUCTURE); PlacementSettings settings = new PlacementSettings(); settings.setRotation(Rotation.values()[rand.nextInt(Rotation.values().length)]); BlockPos size = template.getSize(); int airBlocks = 0; for(int x = 0; x < size.getX(); x++) { for (int z = 0; z < size.getZ(); z++) { if (world.isAirBlock(pos.add(template.transformedBlockPos(settings, new BlockPos(x, 0, z))))) { airBlocks++; if (airBlocks > 0.33 * (size.getX() * size.getZ())) { return; } } } } for (int x = 0; x < size.getX(); x++) { for (int z = 0; z < size.getZ(); z++) { if (x == 0 || x == size.getX() - 1 || z == 0 || z == size.getZ() - 1) { for (int y = 0; y < size.getY(); y++) { BlockPos checkPos = pos.add(template.transformedBlockPos(settings, new BlockPos(x, y, z))); IBlockState checkState = world.getBlockState(checkPos); if (!checkState.getBlock().isAir(checkState, world, checkPos)) { if (!(y <= 3 && (checkState.getBlock() == Blocks.NETHERRACK || checkState.getBlock() == Blocks.QUARTZ_ORE || checkState.getBlock() == Blocks.MAGMA))) { return; } } } } } } template.addBlocksToWorld(world, pos, settings); Map<BlockPos, String> dataBlocks = template.getDataBlocks(pos, settings); for (Entry<BlockPos, String> entry : dataBlocks.entrySet()) { String[] tokens = entry.getValue().split(" "); if (tokens.length == 0) return; BlockPos dataPos = entry.getKey(); EntityPigMage pigMage; switch (tokens[0]) { case "pigman_mage": pigMage = new EntityPigMage(world); pigMage.setPosition(dataPos.getX() + 0.5, dataPos.getY(), dataPos.getZ() + 0.5); pigMage.onInitialSpawn(world.getDifficultyForLocation(dataPos), null); world.spawnEntity(pigMage); break; case "fortress_chest": IBlockState chestState = Blocks.CHEST.getDefaultState().withRotation(settings.getRotation()); chestState = chestState.withMirror(Mirror.FRONT_BACK); world.setBlockState(dataPos, chestState); TileEntity tile = world.getTileEntity(dataPos); if (tile != null && tile instanceof TileEntityLockableLoot) ((TileEntityLockableLoot) tile).setLootTable(NETHER_BRIDGE_LOOT_TABLE, rand.nextLong()); break; } } }
static ItemStack[] swapSlots(EntityPlayerMP player, String lhsInv, int lhs, String rhsInv, int rhs, BlockPos containerPos) { IInventory container = null; String containerName = ""; if (containerPos != null) { TileEntity te = player.world.getTileEntity(containerPos); if (te != null && te instanceof TileEntityLockableLoot) { containerName = ObservationFromFullInventoryImplementation.getInventoryName((IInventory)te); container = (IInventory)te; } else if (te != null && te instanceof TileEntityEnderChest) { containerName = ObservationFromFullInventoryImplementation.getInventoryName(player.getInventoryEnderChest()); container = player.getInventoryEnderChest(); } } IInventory lhsInventory = lhsInv.equals("inventory") ? player.inventory : (lhsInv.equals(containerName) ? container : null); IInventory rhsInventory = rhsInv.equals("inventory") ? player.inventory : (rhsInv.equals(containerName) ? container : null); if (lhsInventory == null || rhsInventory == null) return null; // Source or dest container not available. if (rhs < 0 || lhs < 0) return null; // Out of bounds. if (lhs >= lhsInventory.getSizeInventory() || rhs >= rhsInventory.getSizeInventory()) return null; // Out of bounds. ItemStack srcStack = lhsInventory.getStackInSlot(lhs); ItemStack dstStack = rhsInventory.getStackInSlot(rhs); lhsInventory.setInventorySlotContents(lhs, dstStack); rhsInventory.setInventorySlotContents(rhs, srcStack); if (lhsInventory != rhsInventory) { // Items have moved between our inventory and the foreign inventory - may need to trigger // rewards for collecting / discarding. ItemStack[] returnStacks = new ItemStack[2]; ItemStack stackBeingLost = (lhsInventory == player.inventory) ? srcStack : dstStack; ItemStack stackBeingGained = (lhsInventory == player.inventory) ? dstStack : srcStack; if (stackBeingGained != null) returnStacks[0] = stackBeingGained.copy(); if (stackBeingLost != null) returnStacks[1] = stackBeingLost.copy(); return returnStacks; } return null; }