Refactoring for Iron Furnace
This commit is contained in:
parent
2cd8183c12
commit
026dedd2e6
8 changed files with 167 additions and 197 deletions
|
@ -130,7 +130,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
private boolean canSmelt() {
|
||||
if (inventory.getInvStack(this.input1).isEmpty() || inventory.getInvStack(this.input2).isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
ItemStack itemstack = null;
|
||||
for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) {
|
||||
if (this.hasAllInputs(recipeType)) {
|
||||
|
@ -146,15 +146,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack))
|
||||
return false;
|
||||
final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount();
|
||||
return result <= inventory.getStackLimit() && result <= inventory.getInvStack(this.output).getMaxCount(); // Forge
|
||||
// BugFix:
|
||||
// Make
|
||||
// it
|
||||
// respect
|
||||
// stack
|
||||
// sizes
|
||||
// properly.
|
||||
}
|
||||
return result <= inventory.getStackLimit() && result <= inventory.getInvStack(this.output).getMaxCount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -232,16 +224,11 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
return TRContent.Machine.IRON_ALLOY_FURNACE.getStack();
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebornInventory<IronAlloyFurnaceBlockEntity> getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
|
||||
public int getBurnTime() {
|
||||
return this.burnTime;
|
||||
}
|
||||
|
|
|
@ -82,9 +82,9 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
final boolean burning = this.isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (this.fuel > 0) {
|
||||
this.fuel--;
|
||||
this.updateState();
|
||||
fuel--;
|
||||
}
|
||||
updateState();
|
||||
if (this.fuel <= 0 && this.canSmelt()) {
|
||||
this.fuel = this.fuelGague = (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(this.fuelslot).getItem(), 0) * 1.25);
|
||||
if (this.fuel > 0) {
|
||||
|
@ -162,10 +162,10 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
|
|||
}
|
||||
|
||||
public void updateState() {
|
||||
final BlockState BlockStateContainer = this.world.getBlockState(this.pos);
|
||||
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
|
||||
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
|
||||
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != this.fuel > 0)
|
||||
BlockState state = world.getBlockState(this.pos);
|
||||
if (state.getBlock() instanceof BlockMachineBase) {
|
||||
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
|
||||
if (state.get(BlockMachineBase.ACTIVE) != this.fuel > 0)
|
||||
blockMachineBase.setActive(this.fuel > 0, this.world, this.pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blocks.tier0;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import techreborn.client.EGui;
|
||||
import techreborn.blockentity.machine.iron.IronAlloyFurnaceBlockEntity;
|
||||
|
||||
public class BlockIronAlloyFurnace extends BlockMachineBase {
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView worldIn) {
|
||||
return new IronAlloyFurnaceBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineGuiHandler getGui() {
|
||||
return EGui.ALLOY_FURNACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(BlockState state, DefaultedList<ItemStack> drops, World world, BlockPos pos, int fortune) {
|
||||
drops.add(new ItemStack(this));
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blocks.tier0;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import techreborn.client.EGui;
|
||||
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockIronFurnace extends BlockMachineBase {
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
||||
if (this.isActive(stateIn)) {
|
||||
|
||||
final double d0 = pos.getX() + 0.5D;
|
||||
final double d1 = pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
|
||||
final double d2 = pos.getZ() + 0.5D;
|
||||
if (rand.nextDouble() < 0.1D) {
|
||||
worldIn.playSound(d0, d1, d2, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F,
|
||||
false);
|
||||
}
|
||||
|
||||
final Direction enumfacing = stateIn.get(BlockMachineBase.FACING);
|
||||
final double d3 = 0.52D;
|
||||
final double d4 = rand.nextDouble() * 0.6D - 0.3D;
|
||||
|
||||
switch (enumfacing) {
|
||||
case WEST:
|
||||
worldIn.addParticle(ParticleTypes.SMOKE, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
|
||||
worldIn.addParticle(ParticleTypes.FLAME, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
|
||||
break;
|
||||
case EAST:
|
||||
worldIn.addParticle(ParticleTypes.SMOKE, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
|
||||
worldIn.addParticle(ParticleTypes.FLAME, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
|
||||
break;
|
||||
case NORTH:
|
||||
worldIn.addParticle(ParticleTypes.SMOKE, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D);
|
||||
worldIn.addParticle(ParticleTypes.FLAME, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D);
|
||||
break;
|
||||
case SOUTH:
|
||||
worldIn.addParticle(ParticleTypes.SMOKE, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D);
|
||||
worldIn.addParticle(ParticleTypes.FLAME, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BlockMachineBase
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView worldIn) {
|
||||
return new IronFurnaceBlockEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineGuiHandler getGui() {
|
||||
return EGui.IRON_FURNACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(BlockState state, DefaultedList<ItemStack> drops, World world, BlockPos pos, int fortune) {
|
||||
drops.add(new ItemStack(this));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blocks.tier0;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.client.EGui;
|
||||
import techreborn.blockentity.machine.iron.IronAlloyFurnaceBlockEntity;
|
||||
import techreborn.blocks.GenericMachineBlock;
|
||||
|
||||
public class IronAlloyFurnaceBlock extends GenericMachineBlock {
|
||||
|
||||
public IronAlloyFurnaceBlock() {
|
||||
super(EGui.ALLOY_FURNACE, IronAlloyFurnaceBlockEntity::new);
|
||||
}
|
||||
|
||||
// Block
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
||||
if (!isActive(stateIn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final double x = (double) pos.getX() + 0.5D;
|
||||
final double y = (double) pos.getY() + 2.0D / 16.0D + rand.nextDouble() * 5.0D / 16.0D;
|
||||
final double z = (double) pos.getZ() + 0.5D;
|
||||
if (rand.nextDouble() < 0.1D) {
|
||||
worldIn.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
|
||||
}
|
||||
|
||||
Direction facing = (Direction) stateIn.get(FACING);
|
||||
Direction.Axis facing$Axis = facing.getAxis();
|
||||
double double_5 = rand.nextDouble() * 0.6D - 0.3D;
|
||||
double deltaX = facing$Axis == Direction.Axis.X ? (double) facing.getOffsetX() * 0.52D : double_5;
|
||||
double deltaZ = facing$Axis == Direction.Axis.Z ? (double) facing.getOffsetZ() * 0.52D : double_5;
|
||||
worldIn.addParticle(ParticleTypes.SMOKE, x + deltaX, y, z + deltaZ, 0.0D, 0.0D, 0.0D);
|
||||
worldIn.addParticle(ParticleTypes.FLAME, x + deltaX, y, z + deltaZ, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
70
src/main/java/techreborn/blocks/tier0/IronFurnaceBlock.java
Normal file
70
src/main/java/techreborn/blocks/tier0/IronFurnaceBlock.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2018 TechReborn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package techreborn.blocks.tier0;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.client.EGui;
|
||||
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
|
||||
import techreborn.blocks.GenericMachineBlock;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class IronFurnaceBlock extends GenericMachineBlock {
|
||||
|
||||
public IronFurnaceBlock() {
|
||||
super(EGui.IRON_FURNACE, IronFurnaceBlockEntity::new);
|
||||
}
|
||||
|
||||
// Block
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
||||
if (!isActive(stateIn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final double x = (double) pos.getX() + 0.5D;
|
||||
final double y = (double) pos.getY() + 2.0D / 16.0D + rand.nextDouble() * 5.0D / 16.0D;
|
||||
final double z = (double) pos.getZ() + 0.5D;
|
||||
if (rand.nextDouble() < 0.1D) {
|
||||
worldIn.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
|
||||
}
|
||||
|
||||
Direction facing = (Direction) stateIn.get(FACING);
|
||||
Direction.Axis facing$Axis = facing.getAxis();
|
||||
double double_5 = rand.nextDouble() * 0.6D - 0.3D;
|
||||
double deltaX = facing$Axis == Direction.Axis.X ? (double) facing.getOffsetX() * 0.52D : double_5;
|
||||
double deltaZ = facing$Axis == Direction.Axis.Z ? (double) facing.getOffsetZ() * 0.52D : double_5;
|
||||
worldIn.addParticle(ParticleTypes.SMOKE, x + deltaX, y, z + deltaZ, 0.0D, 0.0D, 0.0D);
|
||||
worldIn.addParticle(ParticleTypes.FLAME, x + deltaX, y, z + deltaZ, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
|
@ -53,8 +53,8 @@ import techreborn.blocks.cable.BlockCable;
|
|||
import techreborn.blocks.generator.*;
|
||||
import techreborn.blocks.lighting.BlockLamp;
|
||||
import techreborn.blocks.storage.*;
|
||||
import techreborn.blocks.tier0.BlockIronAlloyFurnace;
|
||||
import techreborn.blocks.tier0.BlockIronFurnace;
|
||||
import techreborn.blocks.tier0.IronAlloyFurnaceBlock;
|
||||
import techreborn.blocks.tier0.IronFurnaceBlock;
|
||||
import techreborn.blocks.tier1.BlockPlayerDetector;
|
||||
import techreborn.blocks.tier3.BlockCreativeQuantumChest;
|
||||
import techreborn.blocks.transformers.BlockEVTransformer;
|
||||
|
@ -398,8 +398,8 @@ public class TRContent {
|
|||
INDUSTRIAL_ELECTROLYZER(new GenericMachineBlock(EGui.INDUSTRIAL_ELECTROLYZER, IndustrialElectrolyzerBlockEntity::new)),
|
||||
INDUSTRIAL_GRINDER(new GenericMachineBlock(EGui.INDUSTRIAL_GRINDER, IndustrialGrinderBlockEntity::new)),
|
||||
INDUSTRIAL_SAWMILL(new GenericMachineBlock(EGui.SAWMILL, IndustrialSawmillBlockEntity::new)),
|
||||
IRON_ALLOY_FURNACE(new BlockIronAlloyFurnace()),
|
||||
IRON_FURNACE(new BlockIronFurnace()),
|
||||
IRON_ALLOY_FURNACE(new IronAlloyFurnaceBlock()),
|
||||
IRON_FURNACE(new IronFurnaceBlock()),
|
||||
MATTER_FABRICATOR(new GenericMachineBlock(EGui.MATTER_FABRICATOR, MatterFabricatorBlockEntity::new)),
|
||||
RECYCLER(new GenericMachineBlock(EGui.RECYCLER, RecyclerBlockEntity::new)),
|
||||
ROLLING_MACHINE(new GenericMachineBlock(EGui.ROLLING_MACHINE, RollingMachineBlockEntity::new)),
|
||||
|
|
|
@ -90,9 +90,8 @@ public class ItemNanosaber extends SwordItem implements IEnergyItemInfo, ItemDur
|
|||
ExternalPowerSystems.requestEnergyFromArmor(capEnergy, entityHitter);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO needs a stack aware version added in
|
||||
|
|
Loading…
Add table
Reference in a new issue