diff --git a/src/main/java/rearth/oritech/block/base/entity/MachineBlockEntity.java b/src/main/java/rearth/oritech/block/base/entity/MachineBlockEntity.java index ff6d857f1..d08852370 100644 --- a/src/main/java/rearth/oritech/block/base/entity/MachineBlockEntity.java +++ b/src/main/java/rearth/oritech/block/base/entity/MachineBlockEntity.java @@ -59,6 +59,7 @@ public abstract class MachineBlockEntity extends BlockEntity // crafting / processing protected int progress; + protected int energyPerTick; protected OritechRecipe currentRecipe = OritechRecipe.DUMMY; protected InventoryInputMode inventoryInputMode = InventoryInputMode.FILL_LEFT_TO_RIGHT; @@ -75,8 +76,9 @@ protected void onFinalCommit() { } }; - public MachineBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + public MachineBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, int energyPerTick) { super(type, pos, state); + this.energyPerTick = energyPerTick; } @Override @@ -119,16 +121,16 @@ public void tick(World world, BlockPos pos, BlockState state, MachineBlockEntity } private boolean hasEnoughEnergy(OritechRecipe recipe) { - return energyStorage.amount > calculateEnergyUsage(recipe); + return energyStorage.amount > calculateEnergyUsage(); } @SuppressWarnings("lossy-conversions") private void useEnergy(OritechRecipe recipe) { - energyStorage.amount -= calculateEnergyUsage(recipe); + energyStorage.amount -= calculateEnergyUsage(); } - private float calculateEnergyUsage(OritechRecipe recipe) { - return recipe.getEnergyPerTick() * getEfficiencyMultiplier() * (1 / getSpeedMultiplier()); + private float calculateEnergyUsage() { + return energyPerTick * getEfficiencyMultiplier() * (1 / getSpeedMultiplier()); } private void updateNetwork() { @@ -323,7 +325,7 @@ private int slotRecipeSearch(ItemStack stack, List inv) { // find matching recipe // check if currently already using a recipe, if so use this one. This means that all slots are used, and we can just top the slots up - if (currentRecipe.getEnergyPerTick() != -1) { + if (currentRecipe.getTime() != -1) { return findLowestMatchingSlot(stack, inv, false); } @@ -566,4 +568,11 @@ public void setEnergyStored(long amount) { energyStorage.amount = amount; } + public int getBaseEnergyPerTick() { + return energyPerTick; + } + + public float getEffectiveEnergyPerTick() { + return calculateEnergyUsage(); + } } diff --git a/src/main/java/rearth/oritech/block/base/entity/MultiblockMachineEntity.java b/src/main/java/rearth/oritech/block/base/entity/MultiblockMachineEntity.java index 40f5cd44d..abe410cc2 100644 --- a/src/main/java/rearth/oritech/block/base/entity/MultiblockMachineEntity.java +++ b/src/main/java/rearth/oritech/block/base/entity/MultiblockMachineEntity.java @@ -24,8 +24,26 @@ public abstract class MultiblockMachineEntity extends UpgradableMachineBlockEnti private float coreQuality = 1f; - public MultiblockMachineEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); + public MultiblockMachineEntity(BlockEntityType type, BlockPos pos, BlockState state, int energyPerTick) { + super(type, pos, state, energyPerTick); + } + + public static Vec3i rotatePosition(Vec3i relativePos, Direction facing) { + return switch (facing) { + case NORTH -> new BlockPos(relativePos.getZ(), relativePos.getY(), relativePos.getX()); + case WEST -> new BlockPos(-relativePos.getX(), relativePos.getY(), -relativePos.getZ()); + case SOUTH -> new BlockPos(-relativePos.getZ(), relativePos.getY(), -relativePos.getX()); + case EAST -> new BlockPos(relativePos.getX(), relativePos.getY(), relativePos.getZ()); + default -> relativePos; + }; + } + + // this seems to work as expected for some reason? + public static Vec3i worldToRelativePos(Vec3i ownWorldPos, Vec3i worldPos, Direction ownFacing) { + var relativePos = worldPos.subtract(ownWorldPos); + return relativePos; +// var facingInverted = ownFacing.getOpposite(); +// return rotatePosition(relativePos, facingInverted); } @Override @@ -158,24 +176,6 @@ private void highlightBlock(BlockPos block) { ParticleContent.HIGHLIGHT_BLOCK.spawn(world, Vec3d.of(block), null); } - public static Vec3i rotatePosition(Vec3i relativePos, Direction facing) { - return switch (facing) { - case NORTH -> new BlockPos(relativePos.getZ(), relativePos.getY(), relativePos.getX()); - case WEST -> new BlockPos(-relativePos.getX(), relativePos.getY(), -relativePos.getZ()); - case SOUTH -> new BlockPos(-relativePos.getZ(), relativePos.getY(), -relativePos.getX()); - case EAST -> new BlockPos(relativePos.getX(), relativePos.getY(), relativePos.getZ()); - default -> relativePos; - }; - } - - // this seems to work as expected for some reason? - public static Vec3i worldToRelativePos(Vec3i ownWorldPos, Vec3i worldPos, Direction ownFacing) { - var relativePos = worldPos.subtract(ownWorldPos); - return relativePos; -// var facingInverted = ownFacing.getOpposite(); -// return rotatePosition(relativePos, facingInverted); - } - @Override public boolean isActive(BlockState state) { return state.get(MultiblockMachine.ASSEMBLED); diff --git a/src/main/java/rearth/oritech/block/base/entity/UpgradableMachineBlockEntity.java b/src/main/java/rearth/oritech/block/base/entity/UpgradableMachineBlockEntity.java index fd52e4b20..140fd3d93 100644 --- a/src/main/java/rearth/oritech/block/base/entity/UpgradableMachineBlockEntity.java +++ b/src/main/java/rearth/oritech/block/base/entity/UpgradableMachineBlockEntity.java @@ -34,8 +34,8 @@ public abstract class UpgradableMachineBlockEntity extends MachineBlockEntity { private long combinedEnergyStorage = 0; private long combinedEnergyInsert = 0; - public UpgradableMachineBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); + public UpgradableMachineBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, int energyPerTick) { + super(type, pos, state, energyPerTick); } @Override diff --git a/src/main/java/rearth/oritech/block/custom/machines/addons/MachineAddonBlock.java b/src/main/java/rearth/oritech/block/custom/machines/addons/MachineAddonBlock.java index 68cc80ee1..ea643d94a 100644 --- a/src/main/java/rearth/oritech/block/custom/machines/addons/MachineAddonBlock.java +++ b/src/main/java/rearth/oritech/block/custom/machines/addons/MachineAddonBlock.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import rearth.oritech.Oritech; +import rearth.oritech.block.entity.machines.MachineCoreEntity; import rearth.oritech.block.entity.machines.addons.AddonBlockEntity; import rearth.oritech.block.base.entity.UpgradableMachineBlockEntity; import rearth.oritech.block.entity.machines.PulverizerBlockEntity; @@ -73,7 +74,7 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return getBlockEntityType().getDeclaredConstructor(BlockPos.class, BlockState.class).newInstance(pos, state); } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { Oritech.LOGGER.error("Unable to create blockEntity for " + getBlockEntityType().getSimpleName() + " at " + this); - return new PulverizerBlockEntity(pos, state); + return new MachineCoreEntity(pos, state); } } diff --git a/src/main/java/rearth/oritech/block/entity/machines/AssemblerBlockEntity.java b/src/main/java/rearth/oritech/block/entity/machines/AssemblerBlockEntity.java index 4657cd5d1..1b82b4af5 100644 --- a/src/main/java/rearth/oritech/block/entity/machines/AssemblerBlockEntity.java +++ b/src/main/java/rearth/oritech/block/entity/machines/AssemblerBlockEntity.java @@ -16,7 +16,7 @@ public class AssemblerBlockEntity extends MultiblockMachineEntity { public AssemblerBlockEntity(BlockPos pos, BlockState state) { - super(BlockEntitiesContent.ASSEMBLER_ENTITY, pos, state); + super(BlockEntitiesContent.ASSEMBLER_ENTITY, pos, state, 30); } @Override diff --git a/src/main/java/rearth/oritech/block/entity/machines/GrinderBlockEntity.java b/src/main/java/rearth/oritech/block/entity/machines/GrinderBlockEntity.java index d2fb78d8d..c6b686943 100644 --- a/src/main/java/rearth/oritech/block/entity/machines/GrinderBlockEntity.java +++ b/src/main/java/rearth/oritech/block/entity/machines/GrinderBlockEntity.java @@ -17,7 +17,7 @@ public class GrinderBlockEntity extends MultiblockMachineEntity { public GrinderBlockEntity(BlockPos pos, BlockState state) { - super(BlockEntitiesContent.GRINDER_ENTITY, pos, state); + super(BlockEntitiesContent.GRINDER_ENTITY, pos, state, 50); } @Override diff --git a/src/main/java/rearth/oritech/block/entity/machines/PulverizerBlockEntity.java b/src/main/java/rearth/oritech/block/entity/machines/PulverizerBlockEntity.java index 50f139ce3..fd77c6387 100644 --- a/src/main/java/rearth/oritech/block/entity/machines/PulverizerBlockEntity.java +++ b/src/main/java/rearth/oritech/block/entity/machines/PulverizerBlockEntity.java @@ -16,7 +16,7 @@ public class PulverizerBlockEntity extends UpgradableMachineBlockEntity { public PulverizerBlockEntity(BlockPos pos, BlockState state) { - super(BlockEntitiesContent.PULVERIZER_ENTITY, pos, state); + super(BlockEntitiesContent.PULVERIZER_ENTITY, pos, state, 20); } @Override diff --git a/src/main/java/rearth/oritech/client/ui/BasicMachineScreen.java b/src/main/java/rearth/oritech/client/ui/BasicMachineScreen.java index 3fec180d8..36d28b727 100644 --- a/src/main/java/rearth/oritech/client/ui/BasicMachineScreen.java +++ b/src/main/java/rearth/oritech/client/ui/BasicMachineScreen.java @@ -12,6 +12,7 @@ import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import rearth.oritech.Oritech; +import rearth.oritech.block.base.entity.MachineBlockEntity; import rearth.oritech.network.NetworkContent; public class BasicMachineScreen extends BaseOwoHandledScreen { @@ -97,7 +98,8 @@ private void updateEnergyBar() { public Text getEnergyTooltip(long amount, long max) { var percentage = (float) amount / max; var energyFill = String.format("%.1f", percentage * 100); - return Text.literal(amount + " / " + max + " RF\n" + energyFill + "% Charged"); + var energyUsage = ((MachineBlockEntity) handler.blockEntity).getEffectiveEnergyPerTick(); + return Text.literal(amount + " / " + max + " RF\n" + energyFill + "% Charged\n\nMaximum Usage: " + energyUsage + " RF/t"); } public void updateSettingsButtons() { diff --git a/src/main/java/rearth/oritech/init/compat/Screens/PulverizerScreen.java b/src/main/java/rearth/oritech/init/compat/Screens/PulverizerScreen.java index c4ad11ea8..660dda8bd 100644 --- a/src/main/java/rearth/oritech/init/compat/Screens/PulverizerScreen.java +++ b/src/main/java/rearth/oritech/init/compat/Screens/PulverizerScreen.java @@ -52,10 +52,9 @@ public void fillDisplay(FlowLayout root, OritechDisplay display, ReiUIAdapter { private final OritechRecipeType type; private final List inputs; private final List results; - private final int energyPerTick; private final int time; - public static final OritechRecipe DUMMY = new OritechRecipe(-1, 10, DefaultedList.ofSize(1, Ingredient.ofStacks(Items.IRON_INGOT.getDefaultStack())), DefaultedList.ofSize(1, Items.IRON_BLOCK.getDefaultStack()), RecipeContent.PULVERIZER); + public static final OritechRecipe DUMMY = new OritechRecipe(-1, DefaultedList.ofSize(1, Ingredient.ofStacks(Items.IRON_INGOT.getDefaultStack())), DefaultedList.ofSize(1, Items.IRON_BLOCK.getDefaultStack()), RecipeContent.PULVERIZER); - public OritechRecipe(int energy, int time, List inputs, List results, OritechRecipeType type) { + public OritechRecipe(int time, List inputs, List results, OritechRecipeType type) { this.type = type; this.results = results; this.inputs = inputs; - this.energyPerTick = energy; this.time = time; } @@ -85,15 +83,10 @@ public String toString() { "type=" + type + ", inputs=" + inputs + ", results=" + results + - ", energy=" + energyPerTick + ", time=" + time + '}'; } - public int getEnergyPerTick() { - return energyPerTick; - } - public int getTime() { return time; } diff --git a/src/main/java/rearth/oritech/init/recipes/OritechRecipeType.java b/src/main/java/rearth/oritech/init/recipes/OritechRecipeType.java index 6de3bc9dc..088e0d13f 100644 --- a/src/main/java/rearth/oritech/init/recipes/OritechRecipeType.java +++ b/src/main/java/rearth/oritech/init/recipes/OritechRecipeType.java @@ -13,7 +13,6 @@ public class OritechRecipeType extends EndecRecipeSerializer implements RecipeType { public static final Endec ORI_RECIPE_ENDEC = StructEndecBuilder.of( - Endec.INT.fieldOf("energyPerTick", OritechRecipe::getEnergyPerTick), Endec.INT.fieldOf("time", OritechRecipe::getTime), Endec.ofCodec(Ingredient.DISALLOW_EMPTY_CODEC).listOf().fieldOf("ingredients", OritechRecipe::getInputs), BuiltInEndecs.ITEM_STACK.listOf().fieldOf("results", OritechRecipe::getResults), diff --git a/src/main/resources/assets/oritech/lang/en_us.json b/src/main/resources/assets/oritech/lang/en_us.json index 17987b170..a9895b52a 100644 --- a/src/main/resources/assets/oritech/lang/en_us.json +++ b/src/main/resources/assets/oritech/lang/en_us.json @@ -16,5 +16,7 @@ "block.oritech.machine_capacitor_addon": "Capacitor Addon", "block.oritech.machine_acceptor_addon": "Energy Acceptor Addon", "block.oritech.machine_inventory_proxy_addon": "Inventory Proxy Addon", - "block.oritech.machine_extender": "Machine Extender" + "block.oritech.machine_extender": "Machine Extender", + "block.oritech.machine_core_basic": "Basic Machine Core", + "block.oritech.machine_core_good": "Good Machine Core" } \ No newline at end of file diff --git a/src/main/resources/data/oritech/recipes/apple_to_banana.json b/src/main/resources/data/oritech/recipes/apple_to_banana.json index ef8b2dc3e..b9dd88ab0 100644 --- a/src/main/resources/data/oritech/recipes/apple_to_banana.json +++ b/src/main/resources/data/oritech/recipes/apple_to_banana.json @@ -14,6 +14,5 @@ "Count": 1 } ], - "energyPerTick": 15, "time": 80 } \ No newline at end of file diff --git a/src/main/resources/data/oritech/recipes/apple_to_emerald_grinder.json b/src/main/resources/data/oritech/recipes/apple_to_emerald_grinder.json index 5687fec59..d53002a0d 100644 --- a/src/main/resources/data/oritech/recipes/apple_to_emerald_grinder.json +++ b/src/main/resources/data/oritech/recipes/apple_to_emerald_grinder.json @@ -17,6 +17,5 @@ "Count": 2 } ], - "energyPerTick": 10, "time": 40 } \ No newline at end of file diff --git a/src/main/resources/data/oritech/recipes/coal_to_emerald.json b/src/main/resources/data/oritech/recipes/coal_to_emerald.json index 505926145..aec14991e 100644 --- a/src/main/resources/data/oritech/recipes/coal_to_emerald.json +++ b/src/main/resources/data/oritech/recipes/coal_to_emerald.json @@ -11,6 +11,5 @@ "Count": 1 } ], - "energyPerTick": 100, "time": 15 } \ No newline at end of file diff --git a/src/main/resources/data/oritech/recipes/coal_to_emerald_assembler.json b/src/main/resources/data/oritech/recipes/coal_to_emerald_assembler.json index b3d241876..e9901bfbc 100644 --- a/src/main/resources/data/oritech/recipes/coal_to_emerald_assembler.json +++ b/src/main/resources/data/oritech/recipes/coal_to_emerald_assembler.json @@ -13,6 +13,5 @@ "Count": 2 } ], - "energyPerTick": 25, "time": 40 } \ No newline at end of file