mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-26 13:18:34 +01:00
blast furnace booster, part 1
This commit is contained in:
parent
7330809178
commit
ef257e7f80
5 changed files with 80 additions and 10 deletions
|
@ -0,0 +1,11 @@
|
||||||
|
package de.ellpeck.naturesaura.blocks;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityBlastFurnaceBooster;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
|
||||||
|
public class BlockBlastFurnaceBooster extends BlockContainerImpl {
|
||||||
|
public BlockBlastFurnaceBooster() {
|
||||||
|
super("blast_furnace_booster", TileEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE));
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,4 +34,5 @@ public final class ModTileEntities {
|
||||||
public static TileEntityType<TileEntitySpawnLamp> SPAWN_LAMP;
|
public static TileEntityType<TileEntitySpawnLamp> SPAWN_LAMP;
|
||||||
public static TileEntityType<TileEntityTimeChanger> TIME_CHANGER;
|
public static TileEntityType<TileEntityTimeChanger> TIME_CHANGER;
|
||||||
public static TileEntityType<TileEntityWoodStand> WOOD_STAND;
|
public static TileEntityType<TileEntityWoodStand> WOOD_STAND;
|
||||||
|
public static TileEntityType<TileEntityBlastFurnaceBooster> BLAST_FURNACE_BOOSTER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package de.ellpeck.naturesaura.blocks.tiles;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraft.tileentity.BlastFurnaceTileEntity;
|
||||||
|
import net.minecraft.tileentity.ITickableTileEntity;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.IIntArray;
|
||||||
|
|
||||||
|
public class TileEntityBlastFurnaceBooster extends TileEntityImpl implements ITickableTileEntity {
|
||||||
|
|
||||||
|
private int waitTime;
|
||||||
|
|
||||||
|
public TileEntityBlastFurnaceBooster() {
|
||||||
|
super(ModTileEntities.BLAST_FURNACE_BOOSTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (this.world.isRemote)
|
||||||
|
return;
|
||||||
|
if (this.waitTime > 0) {
|
||||||
|
this.waitTime--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEntity below = this.world.getTileEntity(this.pos.down());
|
||||||
|
if (!(below instanceof BlastFurnaceTileEntity))
|
||||||
|
return;
|
||||||
|
BlastFurnaceTileEntity tile = (BlastFurnaceTileEntity) below;
|
||||||
|
IRecipe<?> recipe = this.world.getRecipeManager().getRecipe(TileEntityFurnaceHeater.getRecipeType(tile), tile, this.world).orElse(null);
|
||||||
|
if (recipe == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IIntArray data = TileEntityFurnaceHeater.getFurnaceData(tile);
|
||||||
|
int doneDiff = data.get(3) - data.get(2);
|
||||||
|
if (doneDiff > 1) {
|
||||||
|
this.waitTime = doneDiff - 2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.world.rand.nextFloat() > 0.35F)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack output = tile.getStackInSlot(2);
|
||||||
|
if (output.getCount() >= output.getMaxStackSize())
|
||||||
|
return;
|
||||||
|
if (output.isEmpty()) {
|
||||||
|
ItemStack result = recipe.getRecipeOutput();
|
||||||
|
tile.setInventorySlotContents(2, result.copy());
|
||||||
|
} else {
|
||||||
|
output.grow(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,14 +41,7 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
|
||||||
if (tile instanceof AbstractFurnaceTileEntity) {
|
if (tile instanceof AbstractFurnaceTileEntity) {
|
||||||
AbstractFurnaceTileEntity furnace = (AbstractFurnaceTileEntity) tile;
|
AbstractFurnaceTileEntity furnace = (AbstractFurnaceTileEntity) tile;
|
||||||
if (this.isReady(furnace)) {
|
if (this.isReady(furnace)) {
|
||||||
IIntArray data;
|
IIntArray data = getFurnaceData(furnace);
|
||||||
try {
|
|
||||||
data = (IIntArray) FURNACE_DATA_FIELD.get(furnace);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
NaturesAura.LOGGER.fatal("Couldn't reflect furnace field", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int burnTime = data.get(0);
|
int burnTime = data.get(0);
|
||||||
if (burnTime <= 0)
|
if (burnTime <= 0)
|
||||||
this.world.setBlockState(tilePos, this.world.getBlockState(tilePos).with(AbstractFurnaceBlock.LIT, true));
|
this.world.setBlockState(tilePos, this.world.getBlockState(tilePos).with(AbstractFurnaceBlock.LIT, true));
|
||||||
|
@ -84,6 +77,15 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IIntArray getFurnaceData(AbstractFurnaceTileEntity tile) {
|
||||||
|
try {
|
||||||
|
return (IIntArray) FURNACE_DATA_FIELD.get(tile);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
NaturesAura.LOGGER.fatal("Couldn't reflect furnace field", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isReady(AbstractFurnaceTileEntity furnace) {
|
private boolean isReady(AbstractFurnaceTileEntity furnace) {
|
||||||
if (!furnace.getStackInSlot(1).isEmpty())
|
if (!furnace.getStackInSlot(1).isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
@ -100,7 +102,7 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRecipeType<? extends AbstractCookingRecipe> getRecipeType(AbstractFurnaceTileEntity furnace) {
|
public static IRecipeType<? extends AbstractCookingRecipe> getRecipeType(AbstractFurnaceTileEntity furnace) {
|
||||||
if (furnace instanceof BlastFurnaceTileEntity) {
|
if (furnace instanceof BlastFurnaceTileEntity) {
|
||||||
return IRecipeType.BLASTING;
|
return IRecipeType.BLASTING;
|
||||||
} else if (furnace instanceof SmokerTileEntity) {
|
} else if (furnace instanceof SmokerTileEntity) {
|
||||||
|
|
|
@ -109,7 +109,8 @@ public final class ModRegistry {
|
||||||
new BlockProjectileGenerator(),
|
new BlockProjectileGenerator(),
|
||||||
new BlockDimensionRail("overworld", DimensionType.OVERWORLD, DimensionType.THE_NETHER, DimensionType.THE_END),
|
new BlockDimensionRail("overworld", DimensionType.OVERWORLD, DimensionType.THE_NETHER, DimensionType.THE_END),
|
||||||
new BlockDimensionRail("nether", DimensionType.THE_NETHER, DimensionType.OVERWORLD),
|
new BlockDimensionRail("nether", DimensionType.THE_NETHER, DimensionType.OVERWORLD),
|
||||||
new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD)
|
new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD),
|
||||||
|
new BlockBlastFurnaceBooster()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ModConfig.instance.rfConverter.get())
|
if (ModConfig.instance.rfConverter.get())
|
||||||
|
|
Loading…
Reference in a new issue