net.minecraft.util.WeightedRandomChestContent#net.minecraft.tileentity.TileEntityChest源码实例Demo

下面列出了net.minecraft.util.WeightedRandomChestContent#net.minecraft.tileentity.TileEntityChest 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: CommunityMod   文件: TileEntityGnomeCache.java
/**
 * 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;
}
 
源代码2 项目: PneumaticCraft   文件: BlockTrackEntryInventory.java
@Override
public boolean shouldTrackWithThisEntry(IBlockAccess world, int x, int y, int z, Block block, TileEntity te){
    if(tileEntityClassToNameMapping == null) {
        try {
            tileEntityClassToNameMapping = (Map)ReflectionHelper.findField(TileEntity.class, "field_145853_j", "classToNameMap").get(null);
        } catch(Exception e) {
            Log.error("[BlockTrackEntryInventory.class] Uhm reflection failed here!");
            e.printStackTrace();
        }
    }
    if(te instanceof TileEntityChest) {
        TileEntityChest chest = (TileEntityChest)te;
        if(chest.adjacentChestXNeg != null || chest.adjacentChestZNeg != null) return false;
    }
    return te != null && !invBlackList.contains(tileEntityClassToNameMapping.get(te.getClass())) && te instanceof IInventory && ((IInventory)te).getSizeInventory() > 0 && !MinecraftForge.EVENT_BUS.post(new InventoryTrackEvent(te));
}
 
源代码3 项目: minecraft-roguelike   文件: TreasureChest.java
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;
	}
 
源代码4 项目: CommunityMod   文件: JobChestSteal.java
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();
	}
}
 
源代码5 项目: ehacks-pro   文件: Debug.java
public static boolean isDoubleChest(TileEntity tile) {
    int y;
    int z;
    int[] pos;
    int x;
    return tile instanceof TileEntityChest && (getTileEntity((x = (pos = getCoords(tile))[0]) - 1, y = pos[1], z = pos[2]) instanceof TileEntityChest || getTileEntity(x + 1, y, z) instanceof TileEntityChest || getTileEntity(x, y, z - 1) instanceof TileEntityChest || getTileEntity(x, y, z + 1) instanceof TileEntityChest);
}
 
源代码6 项目: ForgeHax   文件: StorageESPMod.java
private int getTileEntityColor(TileEntity tileEntity) {
  if (tileEntity instanceof TileEntityChest
      || tileEntity instanceof TileEntityDispenser
      || tileEntity instanceof TileEntityShulkerBox) {
    return Colors.ORANGE.toBuffer();
  } else if (tileEntity instanceof TileEntityEnderChest) {
    return Colors.PURPLE.toBuffer();
  } else if (tileEntity instanceof TileEntityFurnace) {
    return Colors.GRAY.toBuffer();
  } else if (tileEntity instanceof TileEntityHopper) {
    return Colors.DARK_RED.toBuffer();
  } else {
    return -1;
  }
}
 
源代码7 项目: ToroQuest   文件: MageTowerGenerator.java
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());
		}
	}
}
 
源代码8 项目: ToroQuest   文件: MonolithGenerator.java
protected void placeChest(World world, BlockPos placementPos) {
	setBlockAndNotifyAdequately(world, placementPos, Blocks.CHEST.getDefaultState());
	TileEntity tileentity = world.getTileEntity(placementPos);
	if (tileentity instanceof TileEntityChest) {
		((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_END_CITY_TREASURE, world.rand.nextLong());
	}
}
 
源代码9 项目: ToroQuest   文件: BastionsLairGenerator.java
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());
		}
	}
}
 
源代码10 项目: BetterChests   文件: ItemChestPickup.java
protected boolean canDoDrop(EntityPlayer player, World world, BlockPos pos) {
	TileEntity te = world.getTileEntity(pos);
	return te != null &&
			(
			te instanceof IUpgradableBlock //Betterchest
			|| te instanceof TileEntityChest //Vanilla chest
			|| te.getClass().getCanonicalName().startsWith("cpw.mods.ironchest") //IronChest
			);
}
 
源代码11 项目: BetterChests   文件: ItemChestUpgrade.java
@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;
}
 
源代码12 项目: CodeChickenLib   文件: InventoryUtils.java
/**
 * Gets an IInventory from a coordinate with support for double chests
 */
public static IInventory getInventory(World world, BlockPos pos) {
    TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof IInventory))
        return null;

    if (tile instanceof TileEntityChest)
        return getChest((TileEntityChest) tile);
    return (IInventory) tile;

}
 
源代码13 项目: CodeChickenLib   文件: InventoryUtils.java
public static IInventory getChest(TileEntityChest chest) {
    for (EnumFacing fside : Plane.HORIZONTAL) {
        if (chest.getWorld().getBlockState(chest.getPos().offset(fside)).getBlock() == chest.getBlockType())
            return new InventoryLargeChest("container.chestDouble",
                    (TileEntityChest) chest.getWorld().getTileEntity(chest.getPos().offset(fside)), chest);
    }
    return chest;
}
 
源代码14 项目: PneumaticCraft   文件: BlockTrackEntryInventory.java
@Override
public boolean shouldBeUpdatedFromServer(TileEntity te){
    if(te instanceof TileEntityChest) {
        TileEntityChest chest = (TileEntityChest)te;
        if(chest.adjacentChestXPos != null) NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(chest.adjacentChestXPos.xCoord, chest.adjacentChestXPos.yCoord, chest.adjacentChestXPos.zCoord));
        if(chest.adjacentChestZPos != null) NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(chest.adjacentChestZPos.xCoord, chest.adjacentChestZPos.yCoord, chest.adjacentChestZPos.zCoord));
    }
    return true;
}
 
源代码15 项目: minecraft-roguelike   文件: Inventory.java
public Inventory(Random rand, TileEntityChest chest){
	this.chest = chest;
	this.shuffledSlots = new ArrayList<Integer>();
	for(int i = 0; i < this.getInventorySize(); ++i){
		shuffledSlots.add(i);
	}
	
	Collections.shuffle(shuffledSlots, rand);
}
 
源代码16 项目: Kettle   文件: CraftChest.java
public CraftChest(final Block block) {
    super(block, TileEntityChest.class);
}
 
源代码17 项目: Kettle   文件: CraftChest.java
public CraftChest(final Material material, final TileEntityChest te) {
    super(material, te);
}
 
源代码18 项目: ToroQuest   文件: GraveyardGenerator.java
protected void addLootToChest(BlockPos placementPos) {
	TileEntity tileentity = world.getTileEntity(placementPos);
	if (tileentity instanceof TileEntityChest) {
		addLootToChest((TileEntityChest) tileentity);
	}
}
 
源代码19 项目: Thermos   文件: CraftChest.java
public CraftChest(final Block block) {
    super(block);

    world = (CraftWorld) block.getWorld();
    chest = (TileEntityChest) world.getTileEntityAt(getX(), getY(), getZ());
}
 
源代码20 项目: minecraft-roguelike   文件: MockChest.java
public MockChest(Treasure type, int level){
	this.type = type;
	this.level = level;
	this.chest = new TileEntityChest();
	this.inv = new Inventory(new Random(), chest);
}
 
源代码21 项目: HoloInventory   文件: TileRequest.java
@Override
public ResponseMessage onMessage(TileRequest message, MessageContext ctx)
{
    World world = DimensionManager.getWorld(message.dim);
    if (world == null) return null;
    TileEntity te = world.getTileEntity(message.pos);
    if (te == null) return null;

    if (Helper.banned.contains(te.getClass().getCanonicalName())) return null;
    if (te instanceof ILockableContainer && !ctx.getServerHandler().player.canOpen(((ILockableContainer) te).getLockCode())) return null;

    if (te instanceof TileEntityEnderChest)
    {
        return new PlainInventory(message.pos, ctx.getServerHandler().player.getInventoryEnderChest());
    }
    else if (te instanceof BlockJukebox.TileEntityJukebox)
    {
        InventoryBasic ib = new InventoryBasic("minecraft:jukebox", false, 1);
        ib.setInventorySlotContents(0, ((BlockJukebox.TileEntityJukebox) te).getRecord());
        return new PlainInventory(message.pos, ib).setName(Blocks.JUKEBOX.getUnlocalizedName());
    }
    else if (te instanceof TileEntityChest)
    {
        Block b = world.getBlockState(message.pos).getBlock();
        if (b instanceof BlockChest)
        {
            IInventory i = ((BlockChest) b).getLockableContainer(world, message.pos);
            if (i != null) return new PlainInventory(message.pos, i);
            return null;
        }
        return new PlainInventory(message.pos, ((TileEntityChest) te));
    }
    else if (te instanceof IInventory)
    {
        return new PlainInventory(message.pos, (IInventory) te);
    }
    else if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
    {
        IItemHandler iih = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (iih == null)
        {
            HoloInventory.getLogger().warn("Error: Block at {} (Class: {} Te: {} Block: {}) returned null after indicating the capability is available.", message.pos, te.getClass().getName(), te, te.getBlockType());
            return null;
        }
        if (te instanceof INamedItemHandler) {
        	INamedItemHandler namedHandler = (INamedItemHandler) te;
        	return new PlainInventory(message.pos, namedHandler.getItemHandlerName(), iih);
        }
        return new PlainInventory(message.pos, te.getBlockType().getUnlocalizedName(), iih);
    }

    return null;
}
 
源代码22 项目: Artifacts   文件: StructureJourneymanTower.java
private static void basement(World world, int i, int j, int k, Random rand) {
	boolean noair = false;
	int y = -1;
	do {
		noair = false;
		for(int x = 1; x <= 9; x++) {
			for(int z = 0; z <= 8; z++) {
				//5,y,4
				int d = (x-5)*(x-5)+(z-4)*(z-4);
				if(d <= 17) {
					if(!world.getBlock(i+x, j+y, z+k).isOpaqueCube() || world.getBlock(i+x, j+y, z+k) == Blocks.leaves) {
						noair=true;
						world.setBlock(i+x, j+y, z+k, StructureGenHelper.cobbleOrMossy(rand), 0, 2);
					}
				}
			}
		}
		y--;
	} while(noair && (j+y) >= 0);
	if(y >= -7 && world.rand.nextBoolean()) {
		y = -8;
	}
	if(y < -7) {
		y++;
		int yy = 3;
		for(; yy <= 5; yy++) {
			for(int x = 3; x <= 7; x++) {
				for(int z = 2; z <= 6; z++) {
					world.setBlockToAir(i+x, j+y+yy, k+z);
				}
			}
		}
		world.setBlock(i+5, j+y+5, k+4, Blocks.mob_spawner, 0, 2);
		TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)world.getTileEntity(i+5, j+y+5, k+4);

           if (tileentitymobspawner != null)
           {
               tileentitymobspawner.func_145881_a/*getSpawnerLogic*/().setEntityName("ClayGolem");
               NBTTagCompound nbt = new NBTTagCompound();
               tileentitymobspawner.writeToNBT(nbt);
               nbt.setShort("MinSpawnDelay",(short)100);
               nbt.setShort("MaxSpawnDelay",(short)600);
               tileentitymobspawner.readFromNBT(nbt);
           }
           
           world.setBlock(i+5, j+y+4, k+4, StructureGenHelper.randomBlock(rand, new Block[]{Blocks.chest, Blocks.chest, Blocks.air}), 2, 2);
   		TileEntity te = world.getTileEntity(i+5, j+y+4, k+4);
   		if(te != null && te instanceof TileEntityChest) {
   			TileEntityChest tec = (TileEntityChest)te;
   			ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
               WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), tec, info.getCount(rand));
   		}
   		
   		world.setBlock(i+5, j+y+3, k+4, StructureGenHelper.cobbleOrMossy(rand), 0, 2);
           
		for(yy=3;yy*-1>y;yy++) {
			world.setBlock(i+7, j+y+yy, k+6, Blocks.ladder, 2, 2);
		}
		world.setBlock(i+7, j+y+yy, k+6, Blocks.ladder, 2, 2);
		world.setBlock(i+7, j+y+yy+1, k+6, Blocks.trapdoor, 2, 2);
	}
}