use of net.minecraft.tileentity.TileEntityFurnace in project SecurityCraft by Geforce132.
the class BlockKeypadFurnace method convert.
@Override
public boolean convert(EntityPlayer player, World world, int x, int y, int z) {
TileEntityFurnace furnace = (TileEntityFurnace) world.getTileEntity(x, y, z);
NBTTagCompound tag = new NBTTagCompound();
int newMeta = 3;
furnace.writeToNBT(tag);
for (int i = 0; i < furnace.getSizeInventory(); i++) {
furnace.setInventorySlotContents(i, null);
}
switch(world.getBlockMetadata(x, y, z)) {
case 5:
newMeta = 4;
break;
case 4:
newMeta = 2;
break;
case 2:
newMeta = 1;
break;
}
world.setBlock(x, y, z, SCContent.keypadFurnace, newMeta, 3);
((IOwnable) world.getTileEntity(x, y, z)).getOwner().set(player.getCommandSenderName(), player.getUniqueID().toString());
((TileEntityFurnace) world.getTileEntity(x, y, z)).readFromNBT(tag);
return true;
}
use of net.minecraft.tileentity.TileEntityFurnace in project SpongeCommon by SpongePowered.
the class SpongeFurnaceBuilder method buildContent.
@Override
protected Optional<Furnace> buildContent(DataView container) throws InvalidDataException {
return super.buildContent(container).flatMap(furnace -> {
final TileEntityFurnace tileEntityFurnace = (TileEntityFurnace) furnace;
if (container.contains(DataQueries.CUSTOM_NAME)) {
tileEntityFurnace.setCustomInventoryName(container.getString(DataQueries.CUSTOM_NAME).get());
}
if (!container.contains(Keys.PASSED_BURN_TIME.getQuery(), Keys.MAX_BURN_TIME.getQuery(), Keys.PASSED_COOK_TIME.getQuery(), Keys.MAX_COOK_TIME.getQuery())) {
((TileEntity) furnace).invalidate();
return Optional.empty();
}
final int burnTime = container.getInt(Keys.PASSED_BURN_TIME.getQuery()).get();
final int maxBurnTime = container.getInt(Keys.MAX_BURN_TIME.getQuery()).get();
final int passedCookTime = container.getInt(Keys.PASSED_COOK_TIME.getQuery()).get();
final int maxCookTime = container.getInt(Keys.MAX_COOK_TIME.getQuery()).get();
tileEntityFurnace.setField(0, maxBurnTime - burnTime);
tileEntityFurnace.setField(1, maxBurnTime);
tileEntityFurnace.setField(2, passedCookTime);
tileEntityFurnace.setField(3, maxCookTime);
tileEntityFurnace.markDirty();
return Optional.of(furnace);
});
}
use of net.minecraft.tileentity.TileEntityFurnace in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method startWorking.
/**
* Central method of the furnace user, he decides about what to do next from here.
* First check if any of the workers has important tasks to handle first.
* If not check if there is an oven with an item which has to be retrieved.
* If not check if fuel and smeltable are available and request if necessary and get into inventory.
* Then check if able to smelt already.
* @return the next state to go to.
*/
private AIState startWorking() {
worker.setLatestStatus(new TextComponentTranslation(COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
final AIState nextState = checkForImportantJobs();
if (nextState != START_WORKING) {
return nextState;
}
final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
if (posOfOven != null) {
walkTo = posOfOven;
worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
final int amountOfSmeltableInBuilding = InventoryUtils.getItemCountInProvider(getOwnBuilding(), this::isSmeltable);
final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), this::isSmeltable);
final int amountOfFuelInBuilding = InventoryUtils.getItemCountInProvider(getOwnBuilding(), TileEntityFurnace::isItemFuel);
final int amountOfFuelInInv = InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), TileEntityFurnace::isItemFuel);
if (amountOfSmeltableInBuilding + amountOfSmeltableInInv <= 0 && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData(), TypeToken.of(getSmeltAbleClass().getClass()))) {
worker.getCitizenData().createRequestAsync(getSmeltAbleClass());
} else if (amountOfFuelInBuilding + amountOfFuelInInv <= 0 && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData(), TypeToken.of(Burnable.class))) {
worker.getCitizenData().createRequestAsync(new Burnable(STACKSIZE));
}
if (amountOfSmeltableInBuilding > 0 && amountOfFuelInInv == 0) {
needsCurrently = this::isSmeltable;
return GATHERING_REQUIRED_MATERIALS;
} else if (amountOfFuelInBuilding > 0 && amountOfFuelInInv == 0) {
needsCurrently = TileEntityFurnace::isItemFuel;
return GATHERING_REQUIRED_MATERIALS;
}
return checkIfAbleToSmelt(amountOfFuelInBuilding + amountOfFuelInInv, amountOfSmeltableInBuilding + amountOfSmeltableInInv);
}
use of net.minecraft.tileentity.TileEntityFurnace in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method getPositionOfOvenToRetrieveFrom.
/**
* Get the furnace which has finished smeltables.
* For this check each furnace which has been registered to the building.
* Check if the furnace is turned off and has something in the result slot
* or check if the furnace has more than x results.
* @return the position of the furnace.
*/
protected BlockPos getPositionOfOvenToRetrieveFrom() {
for (final BlockPos pos : ((AbstractBuildingFurnaceUser) getOwnBuilding()).getFurnaces()) {
final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityFurnace) {
final TileEntityFurnace furnace = (TileEntityFurnace) entity;
final int countInResultSlot = ItemStackUtils.isEmpty(furnace.getStackInSlot(RESULT_SLOT)) ? 0 : furnace.getStackInSlot(RESULT_SLOT).getCount();
if ((!furnace.isBurning() && countInResultSlot > 0) || countInResultSlot > RETRIEVE_SMELTABLE_IF_MORE_THAN) {
worker.setLatestStatus(new TextComponentTranslation(COM_MINECOLONIES_COREMOD_STATUS_RETRIEVING));
return pos;
}
}
}
return null;
}
use of net.minecraft.tileentity.TileEntityFurnace in project minecolonies by Minecolonies.
the class BuildingBaker method checkFurnaces.
/**
* Checks the furnaces of the baker if they're ready.
*/
private void checkFurnaces() {
final World worldObj = getColony().getWorld();
if (worldObj == null) {
return;
}
final List<Map.Entry<BlockPos, BakingProduct>> copyOfList = new ArrayList<>(this.getFurnacesWithProduct().entrySet());
for (final Map.Entry<BlockPos, BakingProduct> entry : copyOfList) {
if (!worldObj.isBlockLoaded(entry.getKey())) {
return;
}
final IBlockState furnace = worldObj.getBlockState(entry.getKey());
if (!(furnace.getBlock() instanceof BlockFurnace)) {
if (worldObj.getTileEntity(entry.getKey()) instanceof TileEntityFurnace) {
return;
}
Log.getLogger().warn(getColony().getName() + " Removed furnace at: " + entry.getKey() + " because it went missing!");
this.removeFromFurnaces(entry.getKey());
continue;
}
final BakingProduct bakingProduct = entry.getValue();
if (bakingProduct != null && bakingProduct.getState() == ProductState.BAKING) {
bakingProduct.increaseBakingProgress();
worldObj.setBlockState(entry.getKey(), Blocks.LIT_FURNACE.getDefaultState().withProperty(BlockFurnace.FACING, furnace.getValue(BlockFurnace.FACING)));
} else {
worldObj.setBlockState(entry.getKey(), Blocks.FURNACE.getDefaultState().withProperty(BlockFurnace.FACING, furnace.getValue(BlockFurnace.FACING)));
}
}
}
Aggregations