Search in sources :

Example 1 with TileEntityFurnace

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;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace)

Example 2 with TileEntityFurnace

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);
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace)

Example 3 with TileEntityFurnace

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);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Burnable(com.minecolonies.api.colony.requestsystem.requestable.Burnable) AIState(com.minecolonies.coremod.entity.ai.util.AIState) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with TileEntityFurnace

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) BlockPos(net.minecraft.util.math.BlockPos) AbstractBuildingFurnaceUser(com.minecolonies.coremod.colony.buildings.AbstractBuildingFurnaceUser)

Example 5 with TileEntityFurnace

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)));
        }
    }
}
Also used : BlockFurnace(net.minecraft.block.BlockFurnace) IBlockState(net.minecraft.block.state.IBlockState) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) BakingProduct(com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct)

Aggregations

TileEntityFurnace (net.minecraft.tileentity.TileEntityFurnace)15 TileEntity (net.minecraft.tileentity.TileEntity)9 BlockPos (net.minecraft.util.math.BlockPos)7 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumFacing (net.minecraft.util.EnumFacing)3 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)3 World (net.minecraft.world.World)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 Burnable (com.minecolonies.api.colony.requestsystem.requestable.Burnable)1 AbstractBuildingFurnaceUser (com.minecolonies.coremod.colony.buildings.AbstractBuildingFurnaceUser)1 BakingProduct (com.minecolonies.coremod.entity.ai.citizen.baker.BakingProduct)1 AIState (com.minecolonies.coremod.entity.ai.util.AIState)1 EntityPlayerConfiguration (com.wuest.prefab.Config.EntityPlayerConfiguration)1 HouseConfiguration (com.wuest.prefab.Config.Structures.HouseConfiguration)1 ModerateHouseConfiguration (com.wuest.prefab.Config.Structures.ModerateHouseConfiguration)1 TileEntityKeypadFurnace (net.geforcemods.securitycraft.tileentity.TileEntityKeypadFurnace)1 Block (net.minecraft.block.Block)1 EnumPartType (net.minecraft.block.BlockBed.EnumPartType)1 EnumDoorHalf (net.minecraft.block.BlockDoor.EnumDoorHalf)1