Initial migration to V2 Energy API (#2474)

* Initial Energy API refactor

* Allow charging in energy storage BEs

* Remove maven for experimental fabric

Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
Technici4n 2021-09-01 22:14:15 +02:00 committed by GitHub
parent 2bc4886cc0
commit 3e2b0e11ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
75 changed files with 764 additions and 694 deletions

View file

@ -46,11 +46,12 @@ import reborncore.common.misc.ModSounds;
import reborncore.common.misc.RebornCoreTags;
import reborncore.common.multiblock.MultiblockRegistry;
import reborncore.common.network.ServerBoundPackets;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.recipes.PaddedShapedRecipe;
import reborncore.common.util.CalenderUtils;
import reborncore.common.util.GenericWrenchHelper;
import reborncore.common.util.Tank;
import team.reborn.energy.api.EnergyStorage;
import java.io.File;
import java.util.function.Supplier;
@ -124,6 +125,12 @@ public class RebornCore implements ModInitializer {
}
return null;
});
EnergyStorage.SIDED.registerFallback((world, pos, state, be, direction) -> {
if (be instanceof PowerAcceptorBlockEntity powerAcceptor) {
return powerAcceptor.getSideEnergyStorage(direction);
}
return null;
});
LOGGER.info("Reborn core is done for now, now to let other mods have their turn...");
LOADED = true;

View file

@ -43,10 +43,8 @@ import reborncore.RebornCore;
import reborncore.api.IListInfoProvider;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.StringUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import java.util.List;
@ -60,24 +58,24 @@ public class StackToolTipHandler implements ItemTooltipCallback {
if (item instanceof IListInfoProvider) {
((IListInfoProvider) item).addInfo(tooltipLines, false, false);
}
else if (item instanceof EnergyHolder) {
LiteralText line1 = new LiteralText(PowerSystem.getLocalizedPowerNoSuffix(Energy.of(itemStack).getEnergy()));
else if (item instanceof RcEnergyItem energyItem) {
LiteralText line1 = new LiteralText(PowerSystem.getLocalizedPowerNoSuffix(energyItem.getStoredEnergy(itemStack)));
line1.append("/");
line1.append(PowerSystem.getLocalizedPower(Energy.of(itemStack).getMaxStored()));
line1.append(PowerSystem.getLocalizedPower(energyItem.getEnergyCapacity()));
line1.formatted(Formatting.GOLD);
tooltipLines.add(1, line1);
if (Screen.hasShiftDown()) {
int percentage = percentage(Energy.of(itemStack).getEnergy(), Energy.of(itemStack).getMaxStored());
int percentage = percentage(energyItem.getStoredEnergy(itemStack), energyItem.getEnergyCapacity());
MutableText line2 = StringUtils.getPercentageText(percentage);
line2.append(" ");
line2.formatted(Formatting.GRAY);
line2.append(I18n.translate("reborncore.gui.tooltip.power_charged"));
tooltipLines.add(2, line2);
double inputRate = ((EnergyHolder) item).getMaxInput(EnergySide.UNKNOWN);
double outputRate = ((EnergyHolder) item).getMaxOutput(EnergySide.UNKNOWN);
double inputRate = energyItem.getEnergyMaxInput();
double outputRate = energyItem.getEnergyMaxOutput();
LiteralText line3 = new LiteralText("");
if (inputRate != 0 && inputRate == outputRate){
line3.append(I18n.translate("techreborn.tooltip.transferRate"));

View file

@ -1,48 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* 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 reborncore.client.gui.slots;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import team.reborn.energy.Energy;
/**
* Created by Rushmead
*/
public class SlotCharge extends BaseSlot {
public SlotCharge(Inventory inventoryIn, int index, int xPosition, int yPosition) {
super(inventoryIn, index, xPosition, yPosition);
}
@Override
public boolean canInsert(ItemStack stack) {
return Energy.valid(stack);
}
@Override
public boolean canWorldBlockRemove() {
return false;
}
}

View file

@ -26,6 +26,9 @@ package reborncore.client.screen.builder;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.inventory.CraftingInventory;
@ -48,7 +51,7 @@ import reborncore.client.screen.builder.slot.UpgradeSlot;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.fluid.container.ItemFluidInfo;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.Energy;
import team.reborn.energy.api.EnergyStorageUtil;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -106,7 +109,7 @@ public class BlockEntityScreenHandlerBuilder {
public BlockEntityScreenHandlerBuilder energySlot(final int index, final int x, final int y) {
this.parent.slots.add(new FilteredSlot(this.inventory, index, x, y)
.setFilter(Energy::valid));
.setFilter(EnergyStorageUtil::isEnergyStorage));
return this;
}

View file

@ -28,6 +28,7 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import reborncore.client.gui.slots.BaseSlot;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
public class FilteredSlot extends BaseSlot {

View file

@ -327,8 +327,8 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
}
@Override
public double getEuPerTick(double baseEu) {
return baseEu * powerMultiplier;
public long getEuPerTick(long baseEu) {
return (long) (baseEu * powerMultiplier);
}
@Override

View file

@ -24,9 +24,14 @@
package reborncore.common.powerSystem;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
@ -41,23 +46,37 @@ import reborncore.api.IListInfoProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blockentity.RedstoneConfiguration;
import reborncore.common.util.StringUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyStorage;
import team.reborn.energy.EnergyTier;
import team.reborn.energy.api.EnergyStorage;
import team.reborn.energy.api.EnergyStorageUtil;
import team.reborn.energy.api.base.SimpleSidedEnergyContainer;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity implements EnergyStorage, IListInfoProvider // TechReborn
{
private EnergyTier blockEntityPowerTier;
private double energy;
public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity implements IListInfoProvider {
public final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
@Override
public long getCapacity() {
return PowerAcceptorBlockEntity.this.getMaxStoredPower();
}
public double extraPowerStorage;
public double extraPowerInput;
@Override
public long getMaxInsert(@Nullable Direction side) {
return PowerAcceptorBlockEntity.this.getMaxInput(side);
}
@Override
public long getMaxExtract(@Nullable Direction side) {
return PowerAcceptorBlockEntity.this.getMaxOutput(side);
}
};
private RcEnergyTier blockEntityPowerTier;
public long extraPowerStorage;
public long extraPowerInput;
public int extraTier;
public double powerChange;
public double powerLastTick;
public long powerChange;
public long powerLastTick;
public boolean checkOverfill = true; // Set to false to disable the overfill check.
public PowerAcceptorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
@ -65,22 +84,16 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
checkTier();
}
public void checkTier() {
if (this.getMaxInput(EnergySide.UNKNOWN) == 0) {
blockEntityPowerTier = getTier((int) this.getBaseMaxOutput());
} else {
blockEntityPowerTier = getTier((int) this.getBaseMaxInput());
}
public EnergyStorage getSideEnergyStorage(@Nullable Direction side) {
return energyContainer.getSideStorage(side);
}
// TO-DO: Move to Energy API probably. Cables use this method.
public static EnergyTier getTier(int power) {
for (EnergyTier tier : EnergyTier.values()) {
if (tier.getMaxInput() >= power) {
return tier;
}
public void checkTier() {
if (this.getMaxInput(null) == 0) {
blockEntityPowerTier = RcEnergyTier.getTier(this.getBaseMaxOutput());
} else {
blockEntityPowerTier = RcEnergyTier.getTier(this.getBaseMaxInput());
}
return EnergyTier.INFINITE;
}
/**
@ -88,8 +101,8 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @return double Free space for energy in internal buffer
*/
public double getFreeSpace() {
return getMaxStoredPower() - getStored(EnergySide.UNKNOWN);
public long getFreeSpace() {
return getMaxStoredPower() - getStored();
}
/**
@ -97,8 +110,18 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @param amount double Amount to add
*/
public void addEnergy(double amount){
setStored(energy + amount);
public void addEnergy(long amount){
setStored(getEnergy() + amount);
}
public void addEnergyProbabilistic(double amount) {
long integerPart = (long) Math.floor(amount);
addEnergy(integerPart);
double fractionalPart = amount - integerPart;
if (ThreadLocalRandom.current().nextDouble() <= fractionalPart) {
addEnergy(1);
}
}
/**
@ -106,9 +129,9 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @param amount double Amount of energy to use
*/
public void useEnergy(double amount){
if (energy > amount) {
setStored(energy - amount);
public void useEnergy(long amount){
if (getEnergy() > amount) {
setStored(getEnergy() - amount);
} else {
setStored(0);
}
@ -127,21 +150,21 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
return;
}
double chargeEnergy = Math.min(getFreeSpace(), getMaxInput(EnergySide.UNKNOWN));
if (chargeEnergy <= 0.0) {
long chargeEnergy = Math.min(getFreeSpace(), getMaxInput(null));
if (chargeEnergy <= 0) {
return;
}
if (!getOptionalInventory().isPresent()) {
return;
}
ItemStack batteryStack = getOptionalInventory().get().getStack(slot);
if (batteryStack.isEmpty()) {
if (getOptionalInventory().isEmpty()) {
return;
}
Inventory inventory = getOptionalInventory().get();
if (Energy.valid(batteryStack)) {
Energy.of(batteryStack).into(Energy.of(this)).move();
}
EnergyStorageUtil.move(
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
energyContainer.getSideStorage(null),
Long.MAX_VALUE,
null
);
}
/**
@ -158,30 +181,30 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
return;
}
if (!getOptionalInventory().isPresent()){
if (getOptionalInventory().isEmpty()){
return;
}
ItemStack batteryStack = getOptionalInventory().get().getStack(slot);
if (batteryStack.isEmpty()) {
return;
}
Inventory inventory = getOptionalInventory().get();
if (Energy.valid(batteryStack)) {
Energy.of(this).into(Energy.of(batteryStack)).move(getTier().getMaxOutput());
}
EnergyStorageUtil.move(
energyContainer.getSideStorage(null),
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
Long.MAX_VALUE,
null
);
}
/**
* Calculates the comparator output of a powered BE with the formula
* {@code ceil(blockEntity.getStored(EnergySide.UNKNOWN) * 15.0 / storage.getMaxPower())}.
* {@code ceil(blockEntity.getStored() * 15.0 / storage.getMaxPower())}.
*
* @param blockEntity the powered BE
* @return the calculated comparator output or 0 if {@code blockEntity} is not a {@code PowerAcceptorBlockEntity}
*/
public static int calculateComparatorOutputFromEnergy(@Nullable BlockEntity blockEntity) {
if (blockEntity instanceof PowerAcceptorBlockEntity storage) {
return MathHelper.ceil(storage.getStored(EnergySide.UNKNOWN) * 15.0 / storage.getMaxStoredPower());
return MathHelper.ceil(storage.getStored() * 15.0 / storage.getMaxStoredPower());
} else {
return 0;
}
@ -202,7 +225,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
* @param side EnergySide Machine side
* @return boolean Returns true if machine can accept energy from side provided
*/
protected boolean canAcceptEnergy(EnergySide side){
protected boolean canAcceptEnergy(@Nullable Direction side){
return true;
}
@ -212,17 +235,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
* @param side EnergySide Machine side
* @return boolean Returns true if machine can provide energy via particular side
*/
protected boolean canProvideEnergy(EnergySide side){
return true;
}
@Deprecated
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Deprecated
public boolean canProvideEnergy(Direction direction) {
protected boolean canProvideEnergy(@Nullable Direction side){
return true;
}
@ -231,7 +244,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @return double Size of additional energy buffer
*/
public double getExtraPowerStorage(){
public long getExtraPowerStorage(){
return extraPowerStorage;
}
@ -240,7 +253,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @param extraPowerStorage double Size of additional energy buffer
*/
public void setExtraPowerStorage(double extraPowerStorage) {
public void setExtraPowerStorage(long extraPowerStorage) {
this.extraPowerStorage = extraPowerStorage;
}
@ -249,7 +262,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @return double Energy change per tick
*/
public double getPowerChange() {
public long getPowerChange() {
return powerChange;
}
@ -258,7 +271,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @param powerChange double Energy change per tick
*/
public void setPowerChange(double powerChange) {
public void setPowerChange(long powerChange) {
this.powerChange = powerChange;
}
@ -268,15 +281,15 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
* @return double Energy stored in block entity
*/
public double getEnergy() {
return getStored(EnergySide.UNKNOWN);
public long getEnergy() {
return getStored();
}
/**
* Wrapper method used to sync energy values with client via BlockEntityScreenHandlerBuilder
* @param energy double Energy stored in block entity
*/
public void setEnergy(double energy) {
public void setEnergy(long energy) {
setStored(energy);
}
@ -285,21 +298,21 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
*
* @return double Size of internal Energy buffer
*/
public abstract double getBaseMaxPower();
public abstract long getBaseMaxPower();
/**
* Returns base output rate or zero if machine doesn't output energy
*
* @return double Output rate, E\t
*/
public abstract double getBaseMaxOutput();
public abstract long getBaseMaxOutput();
/**
* Returns base input rate or zero if machine doesn't accept energy
*
* @return double Input rate, E\t
*/
public abstract double getBaseMaxInput();
public abstract long getBaseMaxInput();
// MachineBaseBlockEntity
@Override
@ -308,7 +321,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
if (world == null || world.isClient) {
return;
}
if (getStored(EnergySide.UNKNOWN) <= 0) {
if (getStored() <= 0) {
return;
}
if (!isActive(RedstoneConfiguration.POWER_IO)) {
@ -316,18 +329,16 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
}
for (Direction side : Direction.values()) {
BlockEntity blockEntity = world.getBlockEntity(getPos().offset(side));
if (blockEntity == null || !Energy.valid(blockEntity)) {
continue;
}
Energy.of(this)
.side(side)
.into(Energy.of(blockEntity).side(side.getOpposite()))
.move();
EnergyStorageUtil.move(
energyContainer.getSideStorage(side),
EnergyStorage.SIDED.find(world, pos.offset(side), side.getOpposite()),
Long.MAX_VALUE,
null
);
}
powerChange = getStored(EnergySide.UNKNOWN) - powerLastTick;
powerLastTick = getStored(EnergySide.UNKNOWN);
powerChange = getStored() - powerLastTick;
powerLastTick = getStored();
}
@Override
@ -335,7 +346,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
super.readNbt(tag);
NbtCompound data = tag.getCompound("PowerAcceptor");
if (shouldHandleEnergyNBT()) {
this.setStored(data.getDouble("energy"));
this.setStored(data.getLong("energy"));
}
}
@ -343,7 +354,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
public NbtCompound writeNbt(NbtCompound tag) {
super.writeNbt(tag);
NbtCompound data = new NbtCompound();
data.putDouble("energy", getStored(EnergySide.UNKNOWN));
data.putLong("energy", getStored());
tag.put("PowerAcceptor", data);
return tag;
}
@ -356,28 +367,23 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
extraPowerInput = 0;
}
// EnergyStorage
@Override
public double getStored(EnergySide face) {
return energy;
public long getStored() {
return energyContainer.amount;
}
@Override
public void setStored(double amount) {
this.energy = amount;
public void setStored(long amount) {
energyContainer.amount = amount;
if(checkOverfill){
this.energy = Math.max(Math.min(energy, getMaxStoredPower()), 0);
energyContainer.amount = Math.max(Math.min(energyContainer.amount, getMaxStoredPower()), 0);
}
markDirty();
}
@Override
public double getMaxStoredPower() {
public long getMaxStoredPower() {
return getBaseMaxPower() + extraPowerStorage;
}
@Override
public double getMaxOutput(EnergySide face) {
public long getMaxOutput(@Nullable Direction face) {
if (!isActive(RedstoneConfiguration.POWER_IO)) {
return 0;
}
@ -390,8 +396,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
return getBaseMaxOutput();
}
@Override
public double getMaxInput(EnergySide face) {
public long getMaxInput(@Nullable Direction face) {
if (!isActive(RedstoneConfiguration.POWER_IO)) {
return 0;
}
@ -404,23 +409,31 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
return getBaseMaxInput() + extraPowerInput;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
if (blockEntityPowerTier == null) {
checkTier();
}
if (extraTier > 0) {
for (EnergyTier enumTier : EnergyTier.values()) {
for (RcEnergyTier enumTier : RcEnergyTier.values()) {
if (enumTier.ordinal() == blockEntityPowerTier.ordinal() + extraTier) {
return enumTier;
}
}
return EnergyTier.INFINITE;
return RcEnergyTier.INFINITE;
}
return blockEntityPowerTier;
}
public boolean tryUseExact(long energy) {
if (getStored() >= energy) {
addEnergy(-energy);
return true;
} else {
return false;
}
}
// IListInfoProvider
@Override
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
@ -429,7 +442,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
new TranslatableText("reborncore.tooltip.energy")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(energy))
.append(PowerSystem.getLocalizedPower(getStored()))
.formatted(Formatting.GOLD)
);
}
@ -442,21 +455,21 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
.formatted(Formatting.GOLD)
);
if (getMaxInput(EnergySide.UNKNOWN) != 0) {
if (getMaxInput(null) != 0) {
info.add(
new TranslatableText("reborncore.tooltip.energy.inputRate")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(getMaxInput(EnergySide.UNKNOWN)))
.append(PowerSystem.getLocalizedPower(getMaxInput(null)))
.formatted(Formatting.GOLD)
);
}
if (getMaxOutput(EnergySide.UNKNOWN) > 0) {
if (getMaxOutput(null) > 0) {
info.add(
new TranslatableText("reborncore.tooltip.energy.outputRate")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(getMaxOutput(EnergySide.UNKNOWN)))
.append(PowerSystem.getLocalizedPower(getMaxOutput(null)))
.formatted(Formatting.GOLD)
);
}

View file

@ -0,0 +1,28 @@
package reborncore.common.powerSystem;
import team.reborn.energy.api.base.SimpleBatteryItem;
/**
* Implement on simple energy-containing items and (on top of what SimpleBatteryItem does):
* <ul>
* <li>A tooltip will be added for the item, indicating the stored power, the max power and the extraction rates.</li>
* <li>Any RcEnergyItem input in a crafting recipe input will automatically give its energy to the output if the output implements RcEnergyItem.</li>
* </ul>
* TODO: consider moving this functionality to the energy API?
*/
public interface RcEnergyItem extends SimpleBatteryItem {
long getEnergyCapacity();
/**
* @return the tier of this EnergyStorage, used to have standard I/O rates.
*/
RcEnergyTier getTier();
default long getEnergyMaxInput() {
return getTier().getMaxInput();
}
default long getEnergyMaxOutput() {
return getTier().getMaxOutput();
}
}

View file

@ -0,0 +1,39 @@
package reborncore.common.powerSystem;
/**
* Standard input / output limits for RC-based machines.
*/
public enum RcEnergyTier {
MICRO(8, 8),
LOW(32, 32),
MEDIUM(128, 128),
HIGH(512, 512),
EXTREME(2048, 2048),
INSANE(8192, 8192),
INFINITE(Integer.MAX_VALUE, Integer.MAX_VALUE);
private final int maxInput;
private final int maxOutput;
RcEnergyTier(int maxInput, int maxOutput) {
this.maxInput = maxInput;
this.maxOutput = maxOutput;
}
public int getMaxInput() {
return maxInput;
}
public int getMaxOutput() {
return maxOutput;
}
public static RcEnergyTier getTier(long power) {
for (RcEnergyTier tier : RcEnergyTier.values()) {
if (tier.getMaxInput() >= power) {
return tier;
}
}
return RcEnergyTier.INFINITE;
}
}

View file

@ -39,7 +39,7 @@ public interface IUpgradeHandler {
double getPowerMultiplier();
double getEuPerTick(double baseEu);
long getEuPerTick(long baseEu);
void addSpeedMulti(double amount);

View file

@ -36,11 +36,9 @@ import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.crafting.ingredient.RebornIngredient;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyStorage;
import java.util.ArrayList;
import java.util.Optional;
@ -63,7 +61,7 @@ public class RecipeCrafter implements IUpgradeHandler {
/**
* This is the place to use the power from
*/
public EnergyStorage energy;
public PowerAcceptorBlockEntity energy;
public Optional<IUpgradeHandler> parentUpgradeHandler = Optional.empty();
@ -107,8 +105,8 @@ public class RecipeCrafter implements IUpgradeHandler {
int[] inputSlots, int[] outputSlots) {
this.recipeType = recipeType;
this.blockEntity = blockEntity;
if (blockEntity instanceof EnergyStorage) {
energy = (EnergyStorage) blockEntity;
if (blockEntity instanceof PowerAcceptorBlockEntity powerAcceptor) {
energy = powerAcceptor;
}
if (blockEntity instanceof IUpgradeHandler) {
parentUpgradeHandler = Optional.of((IUpgradeHandler) blockEntity);
@ -180,8 +178,8 @@ public class RecipeCrafter implements IUpgradeHandler {
}
}
} else if (currentRecipe != null && currentTickTime < currentNeededTicks) {
double useRequirement = getEuPerTick(currentRecipe.getPower());
if (Energy.of(energy).use(useRequirement)) {
long useRequirement = getEuPerTick(currentRecipe.getPower());
if (energy.tryUseExact(useRequirement)) {
currentTickTime++;
if ((currentTickTime == 1 || currentTickTime % 20 == 0) && soundHanlder != null) {
soundHanlder.playSound(false, blockEntity);
@ -315,7 +313,7 @@ public class RecipeCrafter implements IUpgradeHandler {
}
private boolean isActive() {
return currentRecipe != null && energy.getStored(EnergySide.UNKNOWN) >= currentRecipe.getPower();
return currentRecipe != null && energy.getEnergy() >= currentRecipe.getPower();
}
public boolean canCraftAgain() {
@ -326,7 +324,7 @@ public class RecipeCrafter implements IUpgradeHandler {
return false;
}
}
return !(energy.getStored(EnergySide.UNKNOWN) < recipe.getPower());
return !(energy.getEnergy() < recipe.getPower());
}
}
return false;
@ -404,8 +402,8 @@ public class RecipeCrafter implements IUpgradeHandler {
}
@Override
public double getEuPerTick(double baseEu) {
double power = parentUpgradeHandler.map(iUpgradeHandler -> iUpgradeHandler.getEuPerTick(baseEu)).orElse(1D);
public long getEuPerTick(long baseEu) {
long power = parentUpgradeHandler.map(iUpgradeHandler -> iUpgradeHandler.getEuPerTick(baseEu)).orElse(1L);
return Math.min(power, energy.getMaxStoredPower());
}

View file

@ -24,14 +24,20 @@
package reborncore.common.util;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.recipes.IRecipeInput;
import team.reborn.energy.Energy;
import team.reborn.energy.api.EnergyStorage;
import team.reborn.energy.api.EnergyStorageUtil;
import java.util.List;
import java.util.function.Predicate;
@ -103,15 +109,11 @@ public class ItemUtils {
}
public static double getPowerForDurabilityBar(ItemStack stack) {
if (stack.isEmpty()) {
if (!(stack.getItem() instanceof RcEnergyItem energyItem)) {
return 0.0;
}
if (!Energy.valid(stack)) {
return 0.0;
}
return Energy.of(stack).getEnergy() / Energy.of(stack).getMaxStored();
return (double) energyItem.getStoredEnergy(stack) / energyItem.getEnergyCapacity();
}
/**
@ -136,7 +138,7 @@ public class ItemUtils {
if (!ItemUtils.isActive(stack)) {
return;
}
if (Energy.of(stack).getEnergy() >= cost) {
if (((RcEnergyItem) stack.getItem()).getStoredEnergy(stack) >= cost) {
return;
}
if (isClient) {
@ -213,12 +215,29 @@ public class ItemUtils {
* @param itemStack ItemStack Powered item
* @param maxOutput int Maximum output rate of powered item
*/
public static void distributePowerToInventory(PlayerEntity player, ItemStack itemStack, int maxOutput) {
public static void distributePowerToInventory(PlayerEntity player, ItemStack itemStack, long maxOutput) {
distributePowerToInventory(player, itemStack, maxOutput, (stack) -> true);
}
public static void distributePowerToInventory(PlayerEntity player, ItemStack itemStack, int maxOutput, Predicate<ItemStack> filter) {
if (!Energy.valid(itemStack)) {
public static void distributePowerToInventory(PlayerEntity player, ItemStack itemStack, long maxOutput, Predicate<ItemStack> filter) {
// Locate the current stack in the player inventory.
PlayerInventoryStorage playerInv = PlayerInventoryStorage.of(player);
SingleSlotStorage<ItemVariant> sourceSlot = null;
for (int i = 0; i < player.getInventory().size(); i++) {
if (player.getInventory().getStack(i) == itemStack) {
sourceSlot = playerInv.getSlots().get(i);
break;
}
}
if (sourceSlot == null) {
throw new IllegalArgumentException("Failed to locate current stack in the player inventory.");
}
EnergyStorage sourceStorage = ContainerItemContext.ofPlayerSlot(player, sourceSlot).find(EnergyStorage.ITEM);
if (sourceStorage == null) {
return;
}
@ -229,11 +248,12 @@ public class ItemUtils {
continue;
}
if (Energy.valid(invStack)) {
Energy.of(itemStack)
.into(Energy.of(invStack))
.move(maxOutput);
}
EnergyStorageUtil.move(
sourceStorage,
ContainerItemContext.ofPlayerSlot(player, playerInv.getSlots().get(i)).find(EnergyStorage.ITEM),
maxOutput,
null
);
}
}
}

View file

@ -91,6 +91,10 @@ allprojects {
dev
}
repositories {
mavenLocal()
}
// Shared deps between TR and RC
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"

View file

@ -51,9 +51,10 @@ import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Nullable;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.multiblock.MultiblockRenderer;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemUtils;
import reborncore.mixin.client.AccessorModelPredicateProviderRegistry;
import team.reborn.energy.Energy;
import team.reborn.energy.api.base.SimpleBatteryItem;
import techreborn.client.render.DynamicBucketBakedModel;
import techreborn.client.render.DynamicCellBakedModel;
import techreborn.client.render.entitys.CableCoverRenderer;
@ -183,7 +184,7 @@ public class TechRebornClient implements ClientModInitializer {
BatpackItem.class,
new Identifier("techreborn:empty"),
(item, stack, world, entity, seed) -> {
if (!stack.isEmpty() && Energy.of(stack).getEnergy() == 0) {
if (!stack.isEmpty() && SimpleBatteryItem.getStoredEnergyUnchecked(stack) == 0) {
return 1.0F;
}
return 0.0F;
@ -194,7 +195,7 @@ public class TechRebornClient implements ClientModInitializer {
BatteryItem.class,
new Identifier("techreborn:empty"),
(item, stack, world, entity, seed) -> {
if (!stack.isEmpty() && Energy.of(stack).getEnergy() == 0) {
if (!stack.isEmpty() && SimpleBatteryItem.getStoredEnergyUnchecked(stack) == 0) {
return 1.0F;
}
return 0.0F;
@ -218,7 +219,7 @@ public class TechRebornClient implements ClientModInitializer {
ChainsawItem.class,
new Identifier("techreborn:animated"),
(item, stack, world, entity, seed) -> {
if (!stack.isEmpty() && Energy.of(stack).getEnergy() >= item.getCost() && entity != null && entity.getMainHandStack().equals(stack)) {
if (!stack.isEmpty() && SimpleBatteryItem.getStoredEnergyUnchecked(stack) >= item.getCost() && entity != null && entity.getMainHandStack().equals(stack)) {
return 1.0F;
}
return 0.0F;
@ -230,7 +231,8 @@ public class TechRebornClient implements ClientModInitializer {
new Identifier("techreborn:active"),
(item, stack, world, entity, seed) -> {
if (ItemUtils.isActive(stack)) {
if (Energy.of(stack).getMaxStored() - Energy.of(stack).getEnergy() >= 0.9 * Energy.of(stack).getMaxStored()) {
RcEnergyItem energyItem = (RcEnergyItem) stack.getItem();
if (energyItem.getEnergyCapacity() - energyItem.getStoredEnergy(stack) >= 0.9 * item.getEnergyCapacity()) {
return 0.5F;
}
return 1.0F;

View file

@ -24,6 +24,7 @@
package techreborn.blockentity.cable;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
@ -40,18 +41,16 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop;
import reborncore.common.network.ClientBoundPackets;
import reborncore.common.network.NetworkManager;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.StringUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyStorage;
import team.reborn.energy.EnergyTier;
import team.reborn.energy.api.EnergyStorage;
import team.reborn.energy.api.EnergyStorageUtil;
import team.reborn.energy.api.base.SimpleSidedEnergyContainer;
import techreborn.blocks.cable.CableBlock;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -65,11 +64,29 @@ import java.util.List;
*/
public class CableBlockEntity extends BlockEntity
implements BlockEntityTicker<CableBlockEntity>, IListInfoProvider, IToolDrop, EnergyStorage {
implements BlockEntityTicker<CableBlockEntity>, IListInfoProvider, IToolDrop {
private final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
@Override
public long getCapacity() {
return getCableType().transferRate * 4;
}
@Override
public long getMaxInsert(@Nullable Direction side) {
if (!canAcceptEnergy(side)) {
return 0;
}
return getCableType().transferRate;
}
@Override
public long getMaxExtract(@Nullable Direction side) {
return getCableType().transferRate;
}
};
private double energy = 0;
private TRContent.Cables cableType = null;
private ArrayList<EnergySide> sendingFace = new ArrayList<>();
private ArrayList<Direction> sendingFace = new ArrayList<>();
private BlockState cover = null;
public CableBlockEntity(BlockPos pos, BlockState state) {
@ -96,6 +113,10 @@ public class CableBlockEntity extends BlockEntity
return TRContent.Cables.COPPER;
}
public EnergyStorage getSideEnergyStorage(@Nullable Direction side) {
return energyContainer.getSideStorage(side);
}
public BlockState getCover() {
return cover;
}
@ -107,19 +128,19 @@ public class CableBlockEntity extends BlockEntity
}
}
public boolean canAcceptEnergy(EnergySide direction) {
public boolean canAcceptEnergy(@Nullable Direction direction) {
if (sendingFace.contains(direction)) {
return false;
}
return getMaxStoredPower() != getEnergy();
return energyContainer.getCapacity() != getEnergy();
}
public double getEnergy() {
return getStored(EnergySide.UNKNOWN);
public long getEnergy() {
return energyContainer.amount;
}
public void setEnergy(double energy) {
setStored(energy);
public void setEnergy(long energy) {
energyContainer.amount = energy;
}
// BlockEntity
@ -171,17 +192,19 @@ public class CableBlockEntity extends BlockEntity
return;
}
ArrayList<Pair<BlockEntity, Direction>> acceptors = new ArrayList<>();
ArrayList<EnergyStorage> acceptors = new ArrayList<>();
ArrayList<CableBlockEntity> cables = new ArrayList<>();
for (Direction face : Direction.values()) {
BlockEntity blockEntity = world.getBlockEntity(pos.offset(face));
if (blockEntity == null || !Energy.valid(blockEntity)) {
BlockPos adjPos = pos.offset(face);
BlockEntity blockEntity = world.getBlockEntity(adjPos);
EnergyStorage target = EnergyStorage.SIDED.find(world, adjPos, null, blockEntity, face.getOpposite());
if (target == null) {
continue;
}
if (blockEntity instanceof CableBlockEntity cableBlockEntity) {
if (cableBlockEntity.getTier() != this.getTier()) {
if (cableBlockEntity.cableType != this.cableType) {
continue;
}
// Only need ones with energy stores less than ours
@ -191,12 +214,12 @@ public class CableBlockEntity extends BlockEntity
} else {
EnergySide side = EnergySide.fromMinecraft(face);
if (Energy.of(blockEntity).side(face.getOpposite()).getMaxInput() > 0) {
acceptors.add(Pair.of(blockEntity, face));
if (!sendingFace.contains(side)) {
sendingFace.add(side);
try (Transaction transaction = Transaction.openOuter()) {
if (target.insert(Long.MAX_VALUE, transaction) > 0) {
acceptors.add(target);
if (!sendingFace.contains(face)) {
sendingFace.add(face);
}
}
}
}
@ -205,11 +228,12 @@ public class CableBlockEntity extends BlockEntity
if (!acceptors.isEmpty()) {
Collections.shuffle(acceptors);
acceptors.forEach(pair ->
Energy.of(this)
.into(Energy.of(pair.getLeft()).side(pair.getRight().getOpposite()))
.move()
);
acceptors.forEach(t -> EnergyStorageUtil.move(
energyContainer.getSideStorage(null),
t,
Long.MAX_VALUE,
null
));
}
@ -218,10 +242,15 @@ public class CableBlockEntity extends BlockEntity
if (!cables.isEmpty()) {
cables.add(this);
double energyTotal = cables.stream().mapToDouble(CableBlockEntity::getEnergy).sum();
double energyPer = energyTotal / cables.size();
long energyTotal = cables.stream().mapToLong(CableBlockEntity::getEnergy).sum();
long remainingCount = cables.size();
cables.forEach(cableBlockEntity -> cableBlockEntity.setEnergy(energyPer));
for (CableBlockEntity cable : cables) {
long newEnergy = energyTotal / remainingCount;
cable.setEnergy(newEnergy);
energyTotal -= newEnergy;
remainingCount--;
}
}
}
@ -257,38 +286,4 @@ public class CableBlockEntity extends BlockEntity
public ItemStack getToolDrop(PlayerEntity playerIn) {
return new ItemStack(getCableType().block);
}
// EnergyStorage
@Override
public double getStored(EnergySide face) {
return energy;
}
@Override
public void setStored(double amount) {
this.energy = amount;
}
@Override
public double getMaxStoredPower() {
return getCableType().transferRate * 4;
}
@Override
public EnergyTier getTier() {
return PowerAcceptorBlockEntity.getTier(getCableType().transferRate);
}
@Override
public double getMaxInput(EnergySide side) {
if (!canAcceptEnergy(side)) {
return 0;
}
return getCableType().transferRate;
}
@Override
public double getMaxOutput(EnergySide side) {
return getCableType().transferRate;
}
}

View file

@ -29,6 +29,7 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.Nullable;
@ -41,7 +42,6 @@ import reborncore.common.fluid.container.ItemFluidInfo;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.Tank;
import team.reborn.energy.EnergySide;
import techreborn.api.generator.EFluidGenerator;
import techreborn.api.generator.FluidGeneratorRecipe;
import techreborn.api.generator.FluidGeneratorRecipeList;
@ -150,17 +150,17 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return euTick;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
public boolean canAcceptEnergy(@Nullable Direction side) {
return false;
}

View file

@ -31,14 +31,15 @@ import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -91,7 +92,7 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
if (!world.isClient) {
world.spawnEntity(lightningBolt);
}
addEnergy(TechRebornConfig.lightningRodBaseEnergyStrike * (0.3F + weatherStrength));
addEnergy((long) (TechRebornConfig.lightningRodBaseEnergyStrike * (0.3F + weatherStrength)));
machineBaseBlock.setActive(true, world, pos);
onStatusHoldTicks = 400;
}
@ -123,22 +124,22 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.lightningRodMaxEnergy;
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
public boolean canAcceptEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.lightningRodMaxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}

View file

@ -49,12 +49,12 @@ public class PlasmaGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity im
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.plasmaGeneratorMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.plasmaGeneratorMaxOutput;
}

View file

@ -34,7 +34,9 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
@ -43,9 +45,8 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.StringUtils;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.blocks.generator.BlockSolarPanel;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -171,24 +172,24 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return getPanel().internalCapacity;
}
@Override
protected boolean canAcceptEnergy(EnergySide side) { return false; }
protected boolean canAcceptEnergy(@Nullable Direction side) { return false; }
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
if (getPanel() == TRContent.SolarPanels.CREATIVE) {
return EnergyTier.INSANE.getMaxOutput();
return RcEnergyTier.INSANE.getMaxOutput();
}
// Solar panel output will only be limited by the cables the users use
return EnergyTier.EXTREME.getMaxOutput();
return RcEnergyTier.EXTREME.getMaxOutput();
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}
@ -203,7 +204,7 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return getPanel().powerTier;
}

View file

@ -50,12 +50,12 @@ public class DieselGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity im
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.dieselGeneratorMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.dieselGeneratorMaxOutput;
}

View file

@ -29,14 +29,15 @@ import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -85,22 +86,22 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.dragonEggSyphonMaxEnergy;
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
public boolean canAcceptEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.dragonEggSyphonMaxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}

View file

@ -50,12 +50,12 @@ public class GasTurbineBlockEntity extends BaseFluidGeneratorBlockEntity impleme
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.gasTurbineMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.gasTurbineMaxOutput;
}

View file

@ -50,12 +50,12 @@ public class SemiFluidGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.semiFluidGeneratorMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.semiFluidGeneratorMaxOutput;
}

View file

@ -50,12 +50,12 @@ public class ThermalGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity i
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.thermalGeneratorMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.thermalGeneratorMaxOutput;
}

View file

@ -33,8 +33,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -44,7 +46,6 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -131,22 +132,22 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.solidFuelGeneratorMaxEnergy;
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
public boolean canAcceptEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.solidFuelGeneratorMaxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}

View file

@ -31,11 +31,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -58,7 +59,7 @@ public class WaterMillBlockEntity extends PowerAcceptorBlockEntity implements IT
checkForWater();
}
if (waterblocks > 0) {
addEnergy(waterblocks * TechRebornConfig.waterMillEnergyMultiplier);
addEnergyProbabilistic(waterblocks * TechRebornConfig.waterMillEnergyMultiplier);
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, true));
} else {
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, false));
@ -75,22 +76,22 @@ public class WaterMillBlockEntity extends PowerAcceptorBlockEntity implements IT
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.waterMillMaxEnergy;
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
public boolean canAcceptEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.waterMillMaxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}

View file

@ -28,11 +28,13 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -82,22 +84,22 @@ public class WindMillBlockEntity extends PowerAcceptorBlockEntity implements ITo
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.windMillMaxEnergy;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return true;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.windMillMaxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 0;
}

View file

@ -31,10 +31,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.blocks.lighting.LampBlock;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -59,8 +59,8 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity implements IToolDr
return;
}
double cost = getEuPerTick(((LampBlock) b).getCost());
if (getStored(EnergySide.UNKNOWN) > cost) {
long cost = getEuPerTick(((LampBlock) b).getCost());
if (getStored() > cost) {
useEnergy(cost);
if (!LampBlock.isActive(state)) {
LampBlock.setActive(true, world, pos);
@ -71,27 +71,27 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity implements IToolDr
}
@Override
protected boolean canAcceptEnergy(EnergySide side) {
return side == EnergySide.UNKNOWN || getFacing().getOpposite() == Direction.values()[side.ordinal()];
protected boolean canAcceptEnergy(@Nullable Direction side) {
return side == null || getFacing().getOpposite() == Direction.values()[side.ordinal()];
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return capacity;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return 32;
}

View file

@ -30,7 +30,9 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.api.recipe.IRecipeCrafterProvider;
@ -38,7 +40,7 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
/**
* @author drcrazy
@ -97,22 +99,22 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return maxEnergy;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return maxInput;
}

View file

@ -28,7 +28,9 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -37,7 +39,6 @@ import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -65,23 +66,23 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.chargeOMatBMaxEnergy;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
// This allows to move energy from BE to chargeable item. #2264
return side == EnergySide.UNKNOWN;
return side == null;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return TechRebornConfig.chargeOMatBMaxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.chargeOMatBMaxInput;
}

View file

@ -32,7 +32,9 @@ import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
@ -44,7 +46,6 @@ import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.StringUtils;
import reborncore.common.util.Torus;
import team.reborn.energy.EnergySide;
import techreborn.api.recipe.recipes.FusionReactorRecipe;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
import techreborn.config.TechRebornConfig;
@ -229,12 +230,12 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
@Override
public double getBaseMaxPower() {
return Math.min(TechRebornConfig.fusionControlComputerMaxEnergy * getPowerMultiplier(), Integer.MAX_VALUE);
public long getBaseMaxPower() {
return Math.min((long) (TechRebornConfig.fusionControlComputerMaxEnergy * getPowerMultiplier()), Long.MAX_VALUE);
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
if (!hasStartedCrafting) {
return 0;
}
@ -242,7 +243,7 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
if (hasStartedCrafting) {
return 0;
}
@ -297,7 +298,7 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
if (!hasStartedCrafting) {
// Ignition!
if (getStored(EnergySide.UNKNOWN) > currentRecipe.getStartEnergy()) {
if (getStored() > currentRecipe.getStartEnergy()) {
useEnergy(currentRecipe.getStartEnergy());
hasStartedCrafting = true;
useInput(topStackSlot);
@ -308,12 +309,12 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
// Power gen
if (currentRecipe.getPower() > 0) {
// Waste power if it has no where to go
double power = Math.abs(currentRecipe.getPower()) * getPowerMultiplier();
long power = (long) (Math.abs(currentRecipe.getPower()) * getPowerMultiplier());
addEnergy(power);
powerChange = (power);
craftingTickTime++;
} else { // Power user
if (getStored(EnergySide.UNKNOWN) > currentRecipe.getPower()) {
if (getStored() > currentRecipe.getPower()) {
setEnergy(getEnergy() - currentRecipe.getPower());
craftingTickTime++;
}
@ -342,15 +343,15 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
@Override
protected boolean canAcceptEnergy(EnergySide side) {
protected boolean canAcceptEnergy(@Nullable Direction side) {
// Accept from sides
return !(side == EnergySide.DOWN || side == EnergySide.UP);
return !(side == Direction.DOWN || side == Direction.UP);
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
// Provide from top and bottom
return side == EnergySide.DOWN || side == EnergySide.UP;
return side == Direction.DOWN || side == Direction.UP;
}
@Override

View file

@ -37,6 +37,7 @@ import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
@ -50,7 +51,6 @@ import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.recipes.ExtendedRecipeRemainder;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModSounds;
import techreborn.init.TRBlockEntities;
@ -372,7 +372,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
} else {
if (canMake(recipe)) {
if (getStored(EnergySide.UNKNOWN) > euTick) {
if (getStored() > euTick) {
progress++;
if (progress == 1) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.AUTO_CRAFTING,
@ -387,22 +387,22 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.autoCraftingTableMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.autoCraftingTableMaxInput;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}

View file

@ -31,7 +31,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.SmeltingRecipe;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -43,7 +45,6 @@ import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -221,7 +222,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
craftRecipe(currentRecipe);
updateCurrentRecipe();
} else if (cookTime < cookTimeTotal) {
if (getStored(EnergySide.UNKNOWN) > getEuPerTick(EnergyPerTick)) {
if (getStored() > getEuPerTick(EnergyPerTick)) {
useEnergy(getEuPerTick(EnergyPerTick));
cookTime++;
if (cookTime == 1 || cookTime % 20 == 0 && RecipeCrafter.soundHanlder != null) {
@ -234,22 +235,22 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
}
@Override
protected boolean canProvideEnergy(EnergySide side) {
protected boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.electricFurnaceMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.electricFurnaceMaxInput;
}

View file

@ -33,6 +33,7 @@ import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -43,7 +44,6 @@ import reborncore.common.blockentity.MultiblockWriter;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.blocks.lighting.LampBlock;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig;
@ -88,7 +88,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
if (block instanceof Fertilizable || block instanceof PlantBlock
|| block instanceof SugarCaneBlock || block instanceof CactusBlock
) {
if (getStored(EnergySide.UNKNOWN) > TechRebornConfig.greenhouseControllerEnergyPerBonemeal) {
if (getStored() > TechRebornConfig.greenhouseControllerEnergyPerBonemeal) {
useEnergy(TechRebornConfig.greenhouseControllerEnergyPerBonemeal);
blockState.randomTick((ServerWorld) world, blockPos, world.random);
}
@ -124,7 +124,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
} else if (block instanceof BlockRubberLog) {
for (int y = 0; (blockState = world.getBlockState(blockPos.up(y))).getBlock() == block && y < 10; y++) {
if (blockState.get(BlockRubberLog.HAS_SAP)
&& (getStored(EnergySide.UNKNOWN) > TechRebornConfig.greenhouseControllerEnergyPerHarvest)
&& (getStored() > TechRebornConfig.greenhouseControllerEnergyPerHarvest)
&& insertIntoInv(Collections.singletonList(TRContent.Parts.SAP.getStack()))
) {
useEnergy(TechRebornConfig.greenhouseControllerEnergyPerHarvest);
@ -150,7 +150,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
if (world == null) {
return false;
}
if (getStored(EnergySide.UNKNOWN) < TechRebornConfig.greenhouseControllerEnergyPerHarvest){
if (getStored() < TechRebornConfig.greenhouseControllerEnergyPerHarvest){
return false;
}
if (insertIntoInv(Block.getDroppedStacks(blockState, (ServerWorld) world, blockPos, null))) {
@ -204,7 +204,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
charge(6);
if (getStored(EnergySide.UNKNOWN) < getEuPerTick(TechRebornConfig.greenhouseControllerEnergyPerTick)) {
if (getStored() < getEuPerTick(TechRebornConfig.greenhouseControllerEnergyPerTick)) {
return;
}
@ -222,22 +222,22 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.greenhouseControllerMaxEnergy;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.greenhouseControllerMaxInput;
}

View file

@ -29,8 +29,10 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
@ -38,7 +40,7 @@ import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.WorldUtils;
import team.reborn.energy.EnergySide;
import techreborn.blocks.machine.tier1.PlayerDetectorBlock;
import techreborn.blocks.machine.tier1.PlayerDetectorBlock.PlayerDetectorType;
import techreborn.config.TechRebornConfig;
@ -86,7 +88,7 @@ public class PlayerDetectorBlockEntity extends PowerAcceptorBlockEntity implemen
boolean lastRedstone = redstone;
redstone = false;
if (getStored(EnergySide.UNKNOWN) > TechRebornConfig.playerDetectorEuPerTick) {
if (getStored() > TechRebornConfig.playerDetectorEuPerTick) {
for (PlayerEntity player : world.getPlayers()) {
if (MathHelper.sqrt((float)player.squaredDistanceTo(pos.getX(), pos.getY(), pos.getZ())) <= (float)radius ) {
PlayerDetectorType type = world.getBlockState(pos).get(PlayerDetectorBlock.TYPE);
@ -112,22 +114,22 @@ public class PlayerDetectorBlockEntity extends PowerAcceptorBlockEntity implemen
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.playerDetectorMaxEnergy;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.playerDetectorMaxInput;
}

View file

@ -32,9 +32,11 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.Ingredient;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -45,7 +47,7 @@ import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.api.recipe.recipes.RollingMachineRecipe;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModRecipes;
@ -81,22 +83,22 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.rollingMachineMaxEnergy;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.rollingMachineMaxInput;
}
@ -157,7 +159,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
tickTime = 0;
}
if (!currentRecipeOutput.isEmpty()) {
if (getStored(EnergySide.UNKNOWN) > getEuPerTick(TechRebornConfig.rollingMachineEnergyPerTick)
if (getStored() > getEuPerTick(TechRebornConfig.rollingMachineEnergyPerTick)
&& tickTime < Math.max((int) (TechRebornConfig.rollingMachineRunTime * (1.0 - getSpeedMultiplier())), 1)
&& canMake(craftMatrix)) {
useEnergy(getEuPerTick(TechRebornConfig.rollingMachineEnergyPerTick));

View file

@ -28,7 +28,9 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -38,7 +40,6 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -85,20 +86,6 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
}
}
public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) {
if (getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
return false;
} else {
setEnergy(getEnergy() - aEnergy);
if (getEnergy() < 0) {
setEnergy(0);
return false;
} else {
return true;
}
}
}
public int getValue(ItemStack itemStack) {
if (itemStack.isItemEqualIgnoreDamage(TRContent.Parts.SCRAP.getStack())) {
return 200;
@ -138,7 +125,7 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
if (!stack.isEmpty() && spaceForOutput()) {
final int amp = getValue(stack);
final int euNeeded = amp * TechRebornConfig.matterFabricatorEnergyPerAmp;
if (amp != 0 && getStored(EnergySide.UNKNOWN) > euNeeded) {
if (amp != 0 && getStored() > euNeeded) {
useEnergy(euNeeded);
amplifier += amp;
inventory.shrinkSlot(i, 1);
@ -155,22 +142,22 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return TechRebornConfig.matterFabricatorMaxEnergy;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
public boolean canProvideEnergy(@Nullable Direction side) {
return false;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return 0;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return TechRebornConfig.matterFabricatorMaxInput;
}

View file

@ -29,15 +29,16 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.blockentity.IUpgrade;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -49,7 +50,7 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
public int superconductors = 0;
public AdjustableSUBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.ADJUSTABLE_SU, pos, state, "ADJUSTABLE_SU", 4, TRContent.Machine.ADJUSTABLE_SU.block, EnergyTier.INSANE, TechRebornConfig.aesuMaxEnergy);
super(TRBlockEntities.ADJUSTABLE_SU, pos, state, "ADJUSTABLE_SU", 4, TRContent.Machine.ADJUSTABLE_SU.block, RcEnergyTier.INSANE, TechRebornConfig.aesuMaxEnergy);
}
public int getMaxConfigOutput() {
@ -114,12 +115,12 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return OUTPUT;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
//If we have super conductors increase the max input of the machine
if (getMaxConfigOutput() > maxOutput) {
return getMaxConfigOutput();
@ -135,7 +136,7 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
}
@Override
public double getMaxOutput(EnergySide side) {
public long getMaxOutput(@Nullable Direction side) {
return OUTPUT;
}

View file

@ -32,13 +32,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.blocks.storage.energy.EnergyStorageBlock;
/**
@ -49,16 +49,14 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity implement
public RebornInventory<EnergyStorageBlockEntity> inventory;
public String name;
public Block wrenchDrop;
public EnergyTier tier;
public int maxInput;
public int maxOutput;
public int maxStorage;
public EnergyStorageBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, String name, int invSize, Block wrenchDrop, EnergyTier tier, int maxStorage) {
public EnergyStorageBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, String name, int invSize, Block wrenchDrop, RcEnergyTier tier, int maxStorage) {
super(blockEntityType, pos, state);
inventory = new RebornInventory<>(invSize, name + "BlockEntity", 64, this);
this.wrenchDrop = wrenchDrop;
this.tier = tier;
this.name = name;
this.maxInput = tier.getMaxInput();
this.maxOutput = tier.getMaxOutput();
@ -86,27 +84,28 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity implement
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
return side == EnergySide.UNKNOWN || getFacing() != Direction.values()[side.ordinal()];
public boolean canAcceptEnergy(@Nullable Direction side) {
return getFacing() != side;
}
@Override
public boolean canProvideEnergy(EnergySide side) {
return side == EnergySide.UNKNOWN || getFacing() == Direction.values()[side.ordinal()];
public boolean canProvideEnergy(@Nullable Direction side) {
// side == null allows to move energy from BE to chargeable item.
return side == null || getFacing() == side;
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return maxStorage;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return maxOutput;
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return maxInput;
}

View file

@ -30,7 +30,8 @@ import net.minecraft.util.math.BlockPos;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -43,7 +44,7 @@ public class HighVoltageSUBlockEntity extends EnergyStorageBlockEntity implement
* MFSU should store 4M Energy with 512 E/t I/O
*/
public HighVoltageSUBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.HIGH_VOLTAGE_SU, pos, state, "HIGH_VOLTAGE_SU", 2, TRContent.Machine.HIGH_VOLTAGE_SU.block, EnergyTier.HIGH, 4_000_000);
super(TRBlockEntities.HIGH_VOLTAGE_SU, pos, state, "HIGH_VOLTAGE_SU", 2, TRContent.Machine.HIGH_VOLTAGE_SU.block, RcEnergyTier.HIGH, 4_000_000);
}
@Override

View file

@ -30,7 +30,7 @@ import net.minecraft.util.math.BlockPos;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -40,7 +40,7 @@ import techreborn.init.TRContent;
public class LowVoltageSUBlockEntity extends EnergyStorageBlockEntity implements BuiltScreenHandlerProvider {
public LowVoltageSUBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.LOW_VOLTAGE_SU, pos, state, "BatBox", 2, TRContent.Machine.LOW_VOLTAGE_SU.block, EnergyTier.LOW, 40_000);
super(TRBlockEntities.LOW_VOLTAGE_SU, pos, state, "BatBox", 2, TRContent.Machine.LOW_VOLTAGE_SU.block, RcEnergyTier.LOW, 40_000);
}
@Override

View file

@ -30,7 +30,7 @@ import net.minecraft.util.math.BlockPos;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -43,7 +43,7 @@ public class MediumVoltageSUBlockEntity extends EnergyStorageBlockEntity impleme
* MFE should store 300k energy with 128 E/t I/O
*/
public MediumVoltageSUBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.MEDIUM_VOLTAGE_SU, pos, state, "MEDIUM_VOLTAGE_SU", 2, TRContent.Machine.MEDIUM_VOLTAGE_SU.block, EnergyTier.MEDIUM, 300_000);
super(TRBlockEntities.MEDIUM_VOLTAGE_SU, pos, state, "MEDIUM_VOLTAGE_SU", 2, TRContent.Machine.MEDIUM_VOLTAGE_SU.block, RcEnergyTier.MEDIUM, 300_000);
}
@Override

View file

@ -78,7 +78,7 @@ public class IDSUManager extends PersistentState {
public class IDSUPlayer implements NBTSerializable {
private double energy;
private long energy;
private IDSUPlayer() {
}
@ -91,20 +91,20 @@ public class IDSUManager extends PersistentState {
@Override
public NbtCompound write() {
NbtCompound tag = new NbtCompound();
tag.putDouble("energy", energy);
tag.putLong("energy", energy);
return tag;
}
@Override
public void read(@NotNull NbtCompound tag) {
energy = tag.getDouble("energy");
energy = tag.getLong("energy");
}
public double getEnergy() {
public long getEnergy() {
return energy;
}
public void setEnergy(double energy) {
public void setEnergy(long energy) {
this.energy = energy;
markDirty();
}

View file

@ -32,8 +32,7 @@ import org.apache.commons.lang3.StringUtils;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.blockentity.storage.energy.EnergyStorageBlockEntity;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
@ -44,16 +43,16 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
public String ownerUdid;
//This is the energy value that is synced to the client
private double clientEnergy;
private long clientEnergy;
public InterdimensionalSUBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.INTERDIMENSIONAL_SU, pos, state, "IDSU", 2, TRContent.Machine.INTERDIMENSIONAL_SU.block, EnergyTier.INSANE, TechRebornConfig.idsuMaxEnergy);
super(TRBlockEntities.INTERDIMENSIONAL_SU, pos, state, "IDSU", 2, TRContent.Machine.INTERDIMENSIONAL_SU.block, RcEnergyTier.INSANE, TechRebornConfig.idsuMaxEnergy);
}
@Override
public double getStored(EnergySide face) {
public long getStored() {
if (ownerUdid == null || ownerUdid.isEmpty()) {
return 0.0;
return 0;
}
if (world.isClient) {
return clientEnergy;
@ -62,7 +61,7 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
}
@Override
public void setStored(double energy) {
public void setStored(long energy) {
if (ownerUdid == null || ownerUdid.isEmpty()) {
return;
}
@ -74,14 +73,14 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
}
@Override
public void useEnergy(double extract) {
public void useEnergy(long extract) {
if (ownerUdid == null || ownerUdid.isEmpty()) {
return;
}
if (world.isClient) {
throw new UnsupportedOperationException("cannot set energy on the client!");
}
double energy = IDSUManager.getPlayer(world.getServer(), ownerUdid).getEnergy();
long energy = IDSUManager.getPlayer(world.getServer(), ownerUdid).getEnergy();
if (extract > energy) {
extract = energy;
}

View file

@ -35,7 +35,7 @@ import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.blockentity.storage.energy.EnergyStorageBlockEntity;
import techreborn.blocks.storage.energy.LapotronicSUBlock;
import techreborn.config.TechRebornConfig;
@ -50,7 +50,7 @@ public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements
private final ArrayList<LesuNetwork> countedNetworks = new ArrayList<>();
public LapotronicSUBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.LAPOTRONIC_SU, pos, state, "LESU", 2, TRContent.Machine.LAPOTRONIC_SU.block, EnergyTier.LOW, TechRebornConfig.lesuStoragePerBlock);
super(TRBlockEntities.LAPOTRONIC_SU, pos, state, "LESU", 2, TRContent.Machine.LAPOTRONIC_SU.block, RcEnergyTier.LOW, TechRebornConfig.lesuStoragePerBlock);
checkOverfill = false;
this.maxOutput = TechRebornConfig.lesuBaseOutput;
}
@ -67,9 +67,9 @@ public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements
if (connectedBlocks < 32) {
return;
} else if (connectedBlocks < 128) {
maxInput = EnergyTier.MEDIUM.getMaxInput();
maxInput = RcEnergyTier.MEDIUM.getMaxInput();
} else {
maxInput = EnergyTier.HIGH.getMaxInput();
maxInput = RcEnergyTier.HIGH.getMaxInput();
}
}

View file

@ -26,7 +26,7 @@ package techreborn.blockentity.transformers;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -36,7 +36,7 @@ import techreborn.init.TRContent;
public class EVTransformerBlockEntity extends TransformerBlockEntity {
public EVTransformerBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.EV_TRANSFORMER, pos, state, "EVTransformer", TRContent.Machine.EV_TRANSFORMER.block, EnergyTier.INSANE);
super(TRBlockEntities.EV_TRANSFORMER, pos, state, "EVTransformer", TRContent.Machine.EV_TRANSFORMER.block, RcEnergyTier.INSANE);
}
}

View file

@ -26,7 +26,7 @@ package techreborn.blockentity.transformers;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -36,7 +36,7 @@ import techreborn.init.TRContent;
public class HVTransformerBlockEntity extends TransformerBlockEntity {
public HVTransformerBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.HV_TRANSFORMER, pos, state, "HVTransformer", TRContent.Machine.HV_TRANSFORMER.block, EnergyTier.EXTREME);
super(TRBlockEntities.HV_TRANSFORMER, pos, state, "HVTransformer", TRContent.Machine.HV_TRANSFORMER.block, RcEnergyTier.EXTREME);
}
}

View file

@ -26,7 +26,7 @@ package techreborn.blockentity.transformers;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -36,7 +36,7 @@ import techreborn.init.TRContent;
public class LVTransformerBlockEntity extends TransformerBlockEntity {
public LVTransformerBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.LV_TRANSFORMER, pos, state, "LVTransformer", TRContent.Machine.LV_TRANSFORMER.block, EnergyTier.MEDIUM);
super(TRBlockEntities.LV_TRANSFORMER, pos, state, "LVTransformer", TRContent.Machine.LV_TRANSFORMER.block, RcEnergyTier.MEDIUM);
}
}

View file

@ -26,7 +26,7 @@ package techreborn.blockentity.transformers;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -36,6 +36,6 @@ import techreborn.init.TRContent;
public class MVTransformerBlockEntity extends TransformerBlockEntity {
public MVTransformerBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.MV_TRANSFORMER, pos, state, "MVTransformer", TRContent.Machine.MV_TRANSFORMER.block, EnergyTier.HIGH);
super(TRBlockEntities.MV_TRANSFORMER, pos, state, "MVTransformer", TRContent.Machine.MV_TRANSFORMER.block, RcEnergyTier.HIGH);
}
}

View file

@ -34,13 +34,13 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.StringUtils;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.blocks.transformers.BlockTransformer;
import techreborn.config.TechRebornConfig;
@ -53,20 +53,20 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity implements
public String name;
public Block wrenchDrop;
public EnergyTier inputTier;
public EnergyTier outputTier;
public RcEnergyTier inputTier;
public RcEnergyTier outputTier;
public int maxInput;
public int maxOutput;
public int maxStorage;
public TransformerBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, String name, Block wrenchDrop, EnergyTier tier) {
public TransformerBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, String name, Block wrenchDrop, RcEnergyTier tier) {
super(blockEntityType, pos, state);
this.wrenchDrop = wrenchDrop;
this.inputTier = tier;
if (tier != EnergyTier.MICRO) {
outputTier = EnergyTier.values()[tier.ordinal() - 1];
if (tier != RcEnergyTier.MICRO) {
outputTier = RcEnergyTier.values()[tier.ordinal() - 1];
} else {
outputTier = EnergyTier.MICRO;
outputTier = RcEnergyTier.MICRO;
}
this.name = name;
this.maxInput = tier.getMaxInput();
@ -77,39 +77,39 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity implements
// PowerAcceptorBlockEntity
@Override
protected boolean canAcceptEnergy(EnergySide side) {
if (side == EnergySide.UNKNOWN) {
protected boolean canAcceptEnergy(@Nullable Direction side) {
if (side == null) {
return true;
}
if (TechRebornConfig.IC2TransformersStyle) {
return getFacing() == Direction.values()[side.ordinal()];
return getFacing() == side;
}
return getFacing() != Direction.values()[side.ordinal()];
return getFacing() != side;
}
@Override
protected boolean canProvideEnergy(EnergySide side) {
if (side == EnergySide.UNKNOWN) {
protected boolean canProvideEnergy(@Nullable Direction side) {
if (side == null) {
return true;
}
if (TechRebornConfig.IC2TransformersStyle) {
return getFacing() != Direction.values()[side.ordinal()];
return getFacing() != side;
}
return getFacing() == Direction.values()[side.ordinal()];
return getFacing() == side;
}
@Override
public double getBaseMaxPower() {
public long getBaseMaxPower() {
return maxStorage;
}
@Override
public double getBaseMaxOutput() {
public long getBaseMaxOutput() {
return outputTier.getMaxOutput();
}
@Override
public double getBaseMaxInput() {
public long getBaseMaxInput() {
return inputTier.getMaxInput();
}
@ -149,7 +149,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity implements
new TranslatableText("reborncore.tooltip.energy.inputRate")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(getMaxInput(EnergySide.UNKNOWN)))
.append(PowerSystem.getLocalizedPower(getMaxInput(null)))
.formatted(Formatting.GOLD)
);
info.add(
@ -163,7 +163,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity implements
new TranslatableText("reborncore.tooltip.energy.outputRate")
.formatted(Formatting.GRAY)
.append(": ")
.append(PowerSystem.getLocalizedPower(getMaxOutput(EnergySide.UNKNOWN)))
.append(PowerSystem.getLocalizedPower(getMaxOutput(null)))
.formatted(Formatting.GOLD)
);
info.add(

View file

@ -37,6 +37,7 @@ import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
@ -58,7 +59,7 @@ import org.jetbrains.annotations.Nullable;
import reborncore.api.ToolManager;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.util.WrenchUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.api.EnergyStorage;
import techreborn.api.events.CableElectrocutionEvent;
import techreborn.blockentity.cable.CableBlockEntity;
import techreborn.config.TechRebornConfig;
@ -116,20 +117,25 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
}
private BlockState makeConnections(World world, BlockPos pos) {
Boolean down = canConnectTo(world, pos.down());
Boolean up = canConnectTo(world, pos.up());
Boolean north = canConnectTo(world, pos.north());
Boolean east = canConnectTo(world, pos.east());
Boolean south = canConnectTo(world, pos.south());
Boolean west = canConnectTo(world, pos.west());
Boolean down = canConnectTo(world, pos, Direction.DOWN);
Boolean up = canConnectTo(world, pos, Direction.UP);
Boolean north = canConnectTo(world, pos, Direction.NORTH);
Boolean east = canConnectTo(world, pos, Direction.EAST);
Boolean south = canConnectTo(world, pos, Direction.SOUTH);
Boolean west = canConnectTo(world, pos, Direction.WEST);
return this.getDefaultState().with(DOWN, down).with(UP, up).with(NORTH, north).with(EAST, east)
.with(SOUTH, south).with(WEST, west);
}
private Boolean canConnectTo(WorldAccess world, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity != null && (Energy.valid(blockEntity) || blockEntity instanceof CableBlockEntity)) {
private Boolean canConnectTo(WorldAccess world, BlockPos currentPos, Direction side) {
BlockPos adjPos = currentPos.offset(side);
BlockEntity adjBe = world.getBlockEntity(adjPos);
if (adjBe instanceof CableBlockEntity) {
return Boolean.TRUE;
}
// TODO: this doesn't work at all, fix this
else if (world instanceof ServerWorld sw && EnergyStorage.SIDED.find(sw, adjPos, null, adjBe, side.getOpposite()) != null) {
return Boolean.TRUE;
}
return Boolean.FALSE;
@ -210,13 +216,13 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState ourState, Direction ourFacing, BlockState otherState,
public BlockState getStateForNeighborUpdate(BlockState ourState, Direction direction, BlockState otherState,
WorldAccess worldIn, BlockPos ourPos, BlockPos otherPos) {
if (ourState.get(WATERLOGGED)) {
worldIn.getFluidTickScheduler().schedule(ourPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
}
Boolean value = canConnectTo(worldIn, otherPos);
return ourState.with(getProperty(ourFacing), value);
Boolean value = canConnectTo(worldIn, otherPos, direction);
return ourState.with(getProperty(direction), value);
}
@SuppressWarnings("deprecation")
@ -260,7 +266,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
entity.setOnFireFor(1);
}
entity.damage(new ElectrialShockSource(), 1F);
blockEntityCable.setEnergy(0d);
blockEntityCable.setEnergy(0);
}
if (TechRebornConfig.uninsulatedElectrocutionSound) {
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), ModSounds.CABLE_SHOCK, SoundCategory.BLOCKS,

View file

@ -46,7 +46,6 @@ import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.util.WorldUtils;
import team.reborn.energy.Energy;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModSounds;
import techreborn.init.TRContent;
@ -135,15 +134,15 @@ public class BlockRubberLog extends PillarBlock {
return ActionResult.PASS;
}
if ((Energy.valid(stack) && Energy.of(stack).getEnergy() > 20 && stack.getItem() instanceof ElectricTreetapItem) || stack.getItem() instanceof TreeTapItem) {
if ((stack.getItem() instanceof ElectricTreetapItem item && item.getStoredEnergy(stack) > 20) || stack.getItem() instanceof TreeTapItem) {
if (state.get(HAS_SAP) && state.get(SAP_SIDE) == hitResult.getSide()) {
worldIn.setBlockState(pos, state.with(HAS_SAP, false).with(SAP_SIDE, Direction.fromHorizontal(0)));
worldIn.playSound(playerIn, pos, ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS, 0.6F, 1F);
if (worldIn.isClient) {
return ActionResult.SUCCESS;
}
if (Energy.valid(stack)) {
Energy.of(stack).use(20);
if (stack.getItem() instanceof ElectricTreetapItem item) {
item.tryUseEnergy(stack, 20);
} else {
stack.damage(1, playerIn, player -> player.sendToolBreakStatus(hand));
}

View file

@ -91,7 +91,7 @@ public class TechRebornConfig {
public static int plasmaGeneratorMaxOutput = 2048;
@Config(config = "generators", category = "plasma_generator", key = "PlasmaGeneratorMaxEnergy", comment = "Plasma Generator Max Energy")
public static double plasmaGeneratorMaxEnergy = 500_000_000;
public static long plasmaGeneratorMaxEnergy = 500_000_000;
@Config(config = "generators", category = "plasma_generator", key = "PlasmaGeneratorEnergyPerTick", comment = "Plasma Generator Energy Per Tick")
public static int plasmaGeneratorEnergyPerTick = 400;
@ -275,22 +275,22 @@ public class TechRebornConfig {
public static int cloackingDeviceCost = 10;
@Config(config = "items", category = "power", key = "quantumSuitCapacity", comment = "Quantum Suit Energy Capacity")
public static double quantumSuitCapacity = 40_000_000;
public static long quantumSuitCapacity = 40_000_000;
@Config(config = "items", category = "power", key = "quantumSuitFlyingCost", comment = "Quantum Suit Flying Cost")
public static double quantumSuitFlyingCost = 50;
public static long quantumSuitFlyingCost = 50;
@Config(config = "items", category = "power", key = "quantumSuitSwimmingCost", comment = "Quantum Suit Swimming Cost")
public static double quantumSuitSwimmingCost = 20;
public static long quantumSuitSwimmingCost = 20;
@Config(config = "items", category = "power", key = "quantumSuitBreathingCost", comment = "Quantum Suit Breathing Cost")
public static double quantumSuitBreathingCost = 20;
public static long quantumSuitBreathingCost = 20;
@Config(config = "items", category = "power", key = "quantumSuitSprintingCost", comment = "Quantum Suit Sprinting Cost")
public static double quantumSuitSprintingCost = 20;
public static long quantumSuitSprintingCost = 20;
@Config(config = "items", category = "power", key = "quantumSuitFireExtinguishCost", comment = "Quantum Suit Cost for Fire Extinguish")
public static double fireExtinguishCost = 50;
public static long fireExtinguishCost = 50;
@Config(config = "items", category = "power", key = "quantumSuitEnableSprint", comment = "Enable Sprint Speed increase for Quantum Legs")
public static boolean quantumSuitEnableSprint = true;

View file

@ -28,7 +28,6 @@ import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import reborncore.api.events.ApplyArmorToDamageCallback;
import team.reborn.energy.Energy;
import techreborn.config.TechRebornConfig;
import techreborn.items.armor.QuantumSuitItem;
@ -42,17 +41,17 @@ public class ApplyArmorToDamageHandler implements ApplyArmorToDamageCallback {
public float applyArmorToDamage(PlayerEntity player, DamageSource source, float amount) {
double damageAbsorbed = 0.0d;
for (ItemStack stack : player.getArmorItems()) {
if (!(stack.getItem() instanceof QuantumSuitItem)) {
if (!(stack.getItem() instanceof QuantumSuitItem item)) {
continue;
}
double stackEnergy = Energy.of(stack).getEnergy();
double stackEnergy = item.getStoredEnergy(stack);
if (stackEnergy == 0.0d) {
continue;
}
double damageToAbsorb = Math.min(stackEnergy, amount * 0.2d);
if (Energy.of(stack).use(damageToAbsorb * TechRebornConfig.damageAbsorbCost)) {
if (item.tryUseEnergy(stack, (long) (damageToAbsorb * TechRebornConfig.damageAbsorbCost))) {
damageAbsorbed += damageToAbsorb;
}
}

View file

@ -33,8 +33,11 @@ import net.minecraft.item.Items;
import net.minecraft.item.ToolMaterials;
import net.minecraft.sound.BlockSoundGroup;
import reborncore.RebornRegistry;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import team.reborn.energy.api.EnergyStorage;
import techreborn.TechReborn;
import techreborn.blockentity.cable.CableBlockEntity;
import techreborn.blocks.misc.*;
import techreborn.config.TechRebornConfig;
import techreborn.init.*;
@ -65,6 +68,7 @@ public class ModRegistry {
registerItems();
registerFluids();
registerSounds();
registerApis();
}
private static void registerBlocks() {
@ -170,26 +174,26 @@ public class ModRegistry {
RebornRegistry.registerItem(TRContent.PERIDOT_BOOTS = InitUtils.setup(new TRArmourItem(TRArmorMaterials.PERIDOT, EquipmentSlot.FEET), "peridot_boots"));
// Battery
RebornRegistry.registerItem(TRContent.RED_CELL_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.redCellBatteryMaxCharge, EnergyTier.LOW), "red_cell_battery"));
RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.lithiumIonBatteryMaxCharge, EnergyTier.MEDIUM), "lithium_ion_battery"));
RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lithiumBatpackCharge, TRArmorMaterials.LITHIUM_BATPACK, EnergyTier.MEDIUM), "lithium_ion_batpack"));
RebornRegistry.registerItem(TRContent.ENERGY_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.energyCrystalMaxCharge, EnergyTier.HIGH), "energy_crystal"));
RebornRegistry.registerItem(TRContent.LAPOTRON_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronCrystalMaxCharge, EnergyTier.EXTREME), "lapotron_crystal"));
RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORB = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronicOrbMaxCharge, EnergyTier.INSANE), "lapotronic_orb"));
RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORBPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lapotronPackCharge, TRArmorMaterials.LAPOTRONIC_ORBPACK, EnergyTier.INSANE), "lapotronic_orbpack"));
RebornRegistry.registerItem(TRContent.RED_CELL_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.redCellBatteryMaxCharge, RcEnergyTier.LOW), "red_cell_battery"));
RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.lithiumIonBatteryMaxCharge, RcEnergyTier.MEDIUM), "lithium_ion_battery"));
RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lithiumBatpackCharge, TRArmorMaterials.LITHIUM_BATPACK, RcEnergyTier.MEDIUM), "lithium_ion_batpack"));
RebornRegistry.registerItem(TRContent.ENERGY_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.energyCrystalMaxCharge, RcEnergyTier.HIGH), "energy_crystal"));
RebornRegistry.registerItem(TRContent.LAPOTRON_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronCrystalMaxCharge, RcEnergyTier.EXTREME), "lapotron_crystal"));
RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORB = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronicOrbMaxCharge, RcEnergyTier.INSANE), "lapotronic_orb"));
RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORBPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lapotronPackCharge, TRArmorMaterials.LAPOTRONIC_ORBPACK, RcEnergyTier.INSANE), "lapotronic_orbpack"));
// Tools
RebornRegistry.registerItem(TRContent.TREE_TAP = InitUtils.setup(new TreeTapItem(), "treetap"));
RebornRegistry.registerItem(TRContent.WRENCH = InitUtils.setup(new WrenchItem(), "wrench"));
RebornRegistry.registerItem(TRContent.PAINTING_TOOL = InitUtils.setup(new PaintingToolItem(), "painting_tool"));
RebornRegistry.registerItem(TRContent.BASIC_DRILL = InitUtils.setup(new DrillItem(ToolMaterials.IRON, TechRebornConfig.basicDrillCharge, EnergyTier.MEDIUM, TechRebornConfig.basicDrillCost, 6F, -.5F, MiningLevel.IRON), "basic_drill"));
RebornRegistry.registerItem(TRContent.BASIC_CHAINSAW = InitUtils.setup(new ChainsawItem(ToolMaterials.IRON, TechRebornConfig.basicChainsawCharge, EnergyTier.MEDIUM, TechRebornConfig.basicChainsawCost, 20F, 0.5F, Items.IRON_AXE), "basic_chainsaw"));
RebornRegistry.registerItem(TRContent.BASIC_JACKHAMMER = InitUtils.setup(new JackhammerItem(TechRebornConfig.basicJackhammerCharge, EnergyTier.MEDIUM, TechRebornConfig.basicJackhammerCost), "basic_jackhammer"));
RebornRegistry.registerItem(TRContent.BASIC_DRILL = InitUtils.setup(new DrillItem(ToolMaterials.IRON, TechRebornConfig.basicDrillCharge, RcEnergyTier.MEDIUM, TechRebornConfig.basicDrillCost, 6F, -.5F, MiningLevel.IRON), "basic_drill"));
RebornRegistry.registerItem(TRContent.BASIC_CHAINSAW = InitUtils.setup(new ChainsawItem(ToolMaterials.IRON, TechRebornConfig.basicChainsawCharge, RcEnergyTier.MEDIUM, TechRebornConfig.basicChainsawCost, 20F, 0.5F, Items.IRON_AXE), "basic_chainsaw"));
RebornRegistry.registerItem(TRContent.BASIC_JACKHAMMER = InitUtils.setup(new JackhammerItem(TechRebornConfig.basicJackhammerCharge, RcEnergyTier.MEDIUM, TechRebornConfig.basicJackhammerCost), "basic_jackhammer"));
RebornRegistry.registerItem(TRContent.ELECTRIC_TREE_TAP = InitUtils.setup(new ElectricTreetapItem(), "electric_treetap"));
RebornRegistry.registerItem(TRContent.ADVANCED_DRILL = InitUtils.setup(new DrillItem(ToolMaterials.DIAMOND, TechRebornConfig.advancedDrillCharge, EnergyTier.EXTREME, TechRebornConfig.advancedDrillCost, 12F, 0.2F, MiningLevel.DIAMOND), "advanced_drill"));
RebornRegistry.registerItem(TRContent.ADVANCED_CHAINSAW = InitUtils.setup(new ChainsawItem(ToolMaterials.DIAMOND, TechRebornConfig.advancedChainsawCharge, EnergyTier.EXTREME, TechRebornConfig.advancedChainsawCost, 20F, 1.0F, Items.DIAMOND_AXE), "advanced_chainsaw"));
RebornRegistry.registerItem(TRContent.ADVANCED_DRILL = InitUtils.setup(new DrillItem(ToolMaterials.DIAMOND, TechRebornConfig.advancedDrillCharge, RcEnergyTier.EXTREME, TechRebornConfig.advancedDrillCost, 12F, 0.2F, MiningLevel.DIAMOND), "advanced_drill"));
RebornRegistry.registerItem(TRContent.ADVANCED_CHAINSAW = InitUtils.setup(new ChainsawItem(ToolMaterials.DIAMOND, TechRebornConfig.advancedChainsawCharge, RcEnergyTier.EXTREME, TechRebornConfig.advancedChainsawCost, 20F, 1.0F, Items.DIAMOND_AXE), "advanced_chainsaw"));
RebornRegistry.registerItem(TRContent.ADVANCED_JACKHAMMER = InitUtils.setup(new AdvancedJackhammerItem(), "advanced_jackhammer"));
RebornRegistry.registerItem(TRContent.ROCK_CUTTER = InitUtils.setup(new RockCutterItem(), "rock_cutter"));
@ -227,4 +231,8 @@ public class ModRegistry {
ModSounds.MACHINE_START = InitUtils.setup("machine_start");
ModSounds.SAP_EXTRACT = InitUtils.setup("sap_extract");
}
private static void registerApis() {
EnergyStorage.SIDED.registerForBlockEntities((be, direction) -> ((CableBlockEntity) be).getSideEnergyStorage(direction), TRBlockEntities.CABLE);
}
}

View file

@ -39,8 +39,9 @@ import org.jetbrains.annotations.Nullable;
import reborncore.api.blockentity.IUpgrade;
import reborncore.common.fluid.FluidValue;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
import techreborn.blockentity.generator.LightningRodBlockEntity;
import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity;
@ -238,12 +239,12 @@ public class TRContent {
public static Item PERIDOT_BOOTS;
public enum SolarPanels implements ItemConvertible {
BASIC(EnergyTier.MICRO, TechRebornConfig.basicGenerationRateD, TechRebornConfig.basicGenerationRateN),
ADVANCED(EnergyTier.LOW, TechRebornConfig.advancedGenerationRateD, TechRebornConfig.advancedGenerationRateN),
INDUSTRIAL(EnergyTier.MEDIUM, TechRebornConfig.industrialGenerationRateD, TechRebornConfig.industrialGenerationRateN),
ULTIMATE(EnergyTier.HIGH, TechRebornConfig.ultimateGenerationRateD, TechRebornConfig.ultimateGenerationRateN),
QUANTUM(EnergyTier.EXTREME, TechRebornConfig.quantumGenerationRateD, TechRebornConfig.quantumGenerationRateN),
CREATIVE(EnergyTier.INFINITE, Integer.MAX_VALUE / 100, Integer.MAX_VALUE / 100);
BASIC(RcEnergyTier.MICRO, TechRebornConfig.basicGenerationRateD, TechRebornConfig.basicGenerationRateN),
ADVANCED(RcEnergyTier.LOW, TechRebornConfig.advancedGenerationRateD, TechRebornConfig.advancedGenerationRateN),
INDUSTRIAL(RcEnergyTier.MEDIUM, TechRebornConfig.industrialGenerationRateD, TechRebornConfig.industrialGenerationRateN),
ULTIMATE(RcEnergyTier.HIGH, TechRebornConfig.ultimateGenerationRateD, TechRebornConfig.ultimateGenerationRateN),
QUANTUM(RcEnergyTier.EXTREME, TechRebornConfig.quantumGenerationRateD, TechRebornConfig.quantumGenerationRateN),
CREATIVE(RcEnergyTier.INFINITE, Integer.MAX_VALUE / 100, Integer.MAX_VALUE / 100);
public final String name;
public final Block block;
@ -254,9 +255,9 @@ public class TRContent {
public int generationRateN;
// Internal EU storage of solar panel
public int internalCapacity;
public final EnergyTier powerTier;
public final RcEnergyTier powerTier;
SolarPanels(EnergyTier tier, int generationRateD, int generationRateN) {
SolarPanels(RcEnergyTier tier, int generationRateD, int generationRateN) {
name = this.toString().toLowerCase(Locale.ROOT);
powerTier = tier;
block = new BlockSolarPanel(this);
@ -332,15 +333,15 @@ public class TRContent {
}
public enum Cables implements ItemConvertible {
COPPER(128, 12.0, true, EnergyTier.MEDIUM),
TIN(32, 12.0, true, EnergyTier.LOW),
GOLD(512, 12.0, true, EnergyTier.HIGH),
HV(2048, 12.0, true, EnergyTier.EXTREME),
GLASSFIBER(8192, 12.0, false, EnergyTier.INSANE),
INSULATED_COPPER(128, 10.0, false, EnergyTier.MEDIUM),
INSULATED_GOLD(512, 10.0, false, EnergyTier.HIGH),
INSULATED_HV(2048, 10.0, false, EnergyTier.EXTREME),
SUPERCONDUCTOR(Integer.MAX_VALUE / 4, 10.0, false, EnergyTier.INFINITE);
COPPER(128, 12.0, true, RcEnergyTier.MEDIUM),
TIN(32, 12.0, true, RcEnergyTier.LOW),
GOLD(512, 12.0, true, RcEnergyTier.HIGH),
HV(2048, 12.0, true, RcEnergyTier.EXTREME),
GLASSFIBER(8192, 12.0, false, RcEnergyTier.INSANE),
INSULATED_COPPER(128, 10.0, false, RcEnergyTier.MEDIUM),
INSULATED_GOLD(512, 10.0, false, RcEnergyTier.HIGH),
INSULATED_HV(2048, 10.0, false, RcEnergyTier.EXTREME),
SUPERCONDUCTOR(Integer.MAX_VALUE / 4, 10.0, false, RcEnergyTier.INFINITE);
public final String name;
@ -351,10 +352,10 @@ public class TRContent {
public double cableThickness;
public boolean canKill;
public boolean defaultCanKill;
public EnergyTier tier;
public RcEnergyTier tier;
Cables(int transferRate, double cableThickness, boolean canKill, EnergyTier tier) {
Cables(int transferRate, double cableThickness, boolean canKill, RcEnergyTier tier) {
name = this.toString().toLowerCase(Locale.ROOT);
this.transferRate = transferRate;
this.defaultTransferRate = transferRate;
@ -860,7 +861,7 @@ public class TRContent {
handler.addPowerMulti(TechRebornConfig.overclockerPower);
}
if (powerAcceptor != null) {
powerAcceptor.extraPowerInput += powerAcceptor.getMaxInput(EnergySide.UNKNOWN);
powerAcceptor.extraPowerInput += powerAcceptor.getMaxInput(null);
powerAcceptor.extraPowerStorage += powerAcceptor.getBaseMaxPower();
}
}),

View file

@ -40,22 +40,22 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
import techreborn.utils.MessageIDs;
import java.util.List;
public class BatteryItem extends Item implements EnergyHolder, ItemDurabilityExtensions {
public class BatteryItem extends Item implements RcEnergyItem, ItemDurabilityExtensions {
private final int maxEnergy;
private final EnergyTier tier;
private final RcEnergyTier tier;
public BatteryItem(int maxEnergy, EnergyTier tier) {
public BatteryItem(int maxEnergy, RcEnergyTier tier) {
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1));
this.maxEnergy = maxEnergy;
this.tier = tier;
@ -102,12 +102,12 @@ public class BatteryItem extends Item implements EnergyHolder, ItemDurabilityExt
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxEnergy;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return tier;
}

View file

@ -36,19 +36,19 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabilityExtensions {
public class BatpackItem extends ArmorItem implements RcEnergyItem, ItemDurabilityExtensions {
public final int maxCharge;
public final EnergyTier tier;
public final RcEnergyTier tier;
public BatpackItem(int maxCharge, ArmorMaterial material, EnergyTier tier) {
public BatpackItem(int maxCharge, ArmorMaterial material, RcEnergyTier tier) {
super(material, EquipmentSlot.CHEST, new Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
this.maxCharge = maxCharge;
this.tier = tier;
@ -86,12 +86,12 @@ public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabili
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return tier;
}

View file

@ -35,17 +35,15 @@ import net.minecraft.util.collection.DefaultedList;
import reborncore.api.items.ArmorBlockEntityTicker;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRArmorMaterials;
import techreborn.utils.InitUtils;
public class CloakingDeviceItem extends TRArmourItem implements EnergyHolder, ArmorBlockEntityTicker, ArmorRemoveHandler {
public class CloakingDeviceItem extends TRArmourItem implements RcEnergyItem, ArmorBlockEntityTicker, ArmorRemoveHandler {
public static int maxCharge = TechRebornConfig.cloakingDeviceCharge;
public static int cost = TechRebornConfig.cloackingDeviceCost;
@ -94,24 +92,24 @@ public class CloakingDeviceItem extends TRArmourItem implements EnergyHolder, Ar
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
return EnergyTier.INSANE;
public RcEnergyTier getTier() {
return RcEnergyTier.INSANE;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}
// ArmorTickable
@Override
public void tickArmor(ItemStack stack, PlayerEntity playerEntity) {
if (Energy.of(stack).use(cost)) {
if (tryUseEnergy(stack, cost)) {
playerEntity.setInvisible(true);
} else {
if (playerEntity.isInvisible()) {

View file

@ -44,21 +44,20 @@ import reborncore.api.items.ArmorBlockEntityTicker;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.api.items.ItemStackModifiers;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
import techreborn.utils.InitUtils;
public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers, ArmorBlockEntityTicker, ArmorRemoveHandler, EnergyHolder {
public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers, ArmorBlockEntityTicker, ArmorRemoveHandler, RcEnergyItem {
public final double flyCost = TechRebornConfig.quantumSuitFlyingCost;
public final double swimCost = TechRebornConfig.quantumSuitSwimmingCost;
public final double breathingCost = TechRebornConfig.quantumSuitBreathingCost;
public final double sprintingCost = TechRebornConfig.quantumSuitSprintingCost;
public final double fireExtinguishCost = TechRebornConfig.fireExtinguishCost;
public final long flyCost = TechRebornConfig.quantumSuitFlyingCost;
public final long swimCost = TechRebornConfig.quantumSuitSwimmingCost;
public final long breathingCost = TechRebornConfig.quantumSuitBreathingCost;
public final long sprintingCost = TechRebornConfig.quantumSuitSprintingCost;
public final long fireExtinguishCost = TechRebornConfig.fireExtinguishCost;
public final boolean enableSprint = TechRebornConfig.quantumSuitEnableSprint;
public final boolean enableFlight = TechRebornConfig.quantumSuitEnableFlight;
@ -73,12 +72,12 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
attributes.removeAll(EntityAttributes.GENERIC_MOVEMENT_SPEED);
if (this.slot == EquipmentSlot.LEGS && equipmentSlot == EquipmentSlot.LEGS && enableSprint) {
if (Energy.of(stack).getEnergy() > sprintingCost) {
if (getStoredEnergy(stack) > sprintingCost) {
attributes.put(EntityAttributes.GENERIC_MOVEMENT_SPEED, new EntityAttributeModifier(MODIFIERS[equipmentSlot.getEntitySlotId()], "Movement Speed", 0.15, EntityAttributeModifier.Operation.ADDITION));
}
}
if (equipmentSlot == this.slot && Energy.of(stack).getEnergy() > 0) {
if (equipmentSlot == this.slot && getStoredEnergy(stack) > 0) {
attributes.put(EntityAttributes.GENERIC_ARMOR, new EntityAttributeModifier(MODIFIERS[slot.getEntitySlotId()], "Armor modifier", 20, EntityAttributeModifier.Operation.ADDITION));
attributes.put(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, new EntityAttributeModifier(MODIFIERS[slot.getEntitySlotId()], "Knockback modifier", 2, EntityAttributeModifier.Operation.ADDITION));
}
@ -89,17 +88,17 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
switch (this.slot) {
case HEAD:
if (playerEntity.isSubmergedInWater()) {
if (Energy.of(stack).use(breathingCost)) {
if (tryUseEnergy(stack, breathingCost)) {
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.WATER_BREATHING, 5, 1));
}
}
break;
case CHEST:
if (enableFlight){
if (Energy.of(stack).getEnergy() > flyCost && !TechReborn.elytraPredicate.test(playerEntity)) {
if (getStoredEnergy(stack) > flyCost && !TechReborn.elytraPredicate.test(playerEntity)) {
playerEntity.getAbilities().allowFlying = true;
if (playerEntity.getAbilities().flying) {
Energy.of(stack).use(flyCost);
tryUseEnergy(stack, flyCost);
}
playerEntity.setOnGround(true);
} else {
@ -107,18 +106,18 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
playerEntity.getAbilities().flying = false;
}
}
if (playerEntity.isOnFire() && Energy.of(stack).getEnergy() > fireExtinguishCost) {
if (playerEntity.isOnFire() && getStoredEnergy(stack) > fireExtinguishCost) {
playerEntity.extinguish();
}
break;
case LEGS:
if (playerEntity.isSprinting() && enableSprint) {
Energy.of(stack).use(sprintingCost);
tryUseEnergy(stack, sprintingCost);
}
break;
case FEET:
if (playerEntity.isSwimming()) {
if (Energy.of(stack).use(swimCost)) {
if (tryUseEnergy(stack, swimCost)) {
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.DOLPHINS_GRACE, 5, 1));
}
}
@ -169,13 +168,13 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
}
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return TechRebornConfig.quantumSuitCapacity;
}
@Override
public EnergyTier getTier() {
return EnergyTier.EXTREME;
public RcEnergyTier getTier() {
return RcEnergyTier.EXTREME;
}
@Environment(EnvType.CLIENT)

View file

@ -34,27 +34,25 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
import java.util.Random;
public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilityExtensions {
public class ChainsawItem extends AxeItem implements RcEnergyItem, ItemDurabilityExtensions {
public final int maxCharge;
public final int cost;
public final float poweredSpeed;
private final float unpoweredSpeed;
public final Item referenceTool;
public final EnergyTier tier;
public final RcEnergyTier tier;
public ChainsawItem(ToolMaterials material, int energyCapacity, EnergyTier tier, int cost, float poweredSpeed, float unpoweredSpeed, Item referenceTool) {
public ChainsawItem(ToolMaterials material, int energyCapacity, RcEnergyTier tier, int cost, float poweredSpeed, float unpoweredSpeed, Item referenceTool) {
// combat stats same as for diamond axe. Fix for #2468
super(material, 5.0F, -3.0F, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
this.maxCharge = energyCapacity;
@ -68,7 +66,7 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
// AxeItem
@Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
if (Energy.of(stack).getEnergy() >= cost
if (getStoredEnergy(stack) >= cost
&& (state.getMaterial() == Material.WOOD || state.getMaterial() == Material.NETHER_WOOD)) {
return poweredSpeed;
}
@ -80,7 +78,7 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
Random rand = new Random();
if (rand.nextInt(EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack) + 1) == 0) {
Energy.of(stack).use(cost);
tryUseEnergy(stack, cost);
}
return true;
}
@ -138,17 +136,17 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return tier;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}

View file

@ -39,7 +39,7 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.Util;
import net.minecraft.util.registry.Registry;
import reborncore.common.powerSystem.PowerSystem;
import team.reborn.energy.Energy;
import team.reborn.energy.api.EnergyStorage;
import techreborn.TechReborn;
import java.util.Map.Entry;
@ -60,26 +60,30 @@ public class DebugToolItem extends Item {
if (block == null) {
return ActionResult.FAIL;
}
if (context.getWorld().isClient) {
return ActionResult.SUCCESS;
}
sendMessage(context, new LiteralText(getRegistryName(block)));
for (Entry<Property<?>, Comparable<?>> entry : blockState.getEntries().entrySet()) {
sendMessage(context, new LiteralText(getPropertyString(entry)));
}
EnergyStorage energyStorage = EnergyStorage.SIDED.find(context.getWorld(), context.getBlockPos(), context.getSide());
if (energyStorage != null) {
sendMessage(context, new LiteralText(getRCPower(energyStorage)));
}
BlockEntity blockEntity = context.getWorld().getBlockEntity(context.getBlockPos());
if (blockEntity == null) {
return ActionResult.SUCCESS;
return ActionResult.CONSUME;
}
sendMessage(context, new LiteralText(getBlockEntityType(blockEntity)));
if (Energy.valid(blockEntity)) {
sendMessage(context, new LiteralText(getRCPower(blockEntity)));
}
sendMessage(context, getBlockEntityTags(blockEntity));
return ActionResult.SUCCESS;
return ActionResult.CONSUME;
}
private void sendMessage(ItemUsageContext context, Text message) {
@ -120,13 +124,13 @@ public class DebugToolItem extends Item {
return s;
}
private String getRCPower(BlockEntity blockEntity) {
private String getRCPower(EnergyStorage energyStorage) {
String s = "" + Formatting.GREEN;
s += "Power: ";
s += Formatting.BLUE;
s += PowerSystem.getLocalizedPower(Energy.of(blockEntity).getEnergy());
s += PowerSystem.getLocalizedPower(energyStorage.getAmount());
s += "/";
s += PowerSystem.getLocalizedPower(Energy.of(blockEntity).getMaxStored());
s += PowerSystem.getLocalizedPower(energyStorage.getCapacity());
return s;
}

View file

@ -36,25 +36,23 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions, DynamicAttributeTool {
public class DrillItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions, DynamicAttributeTool {
public final int maxCharge;
public final int cost;
public final float poweredSpeed;
public final float unpoweredSpeed;
public final int miningLevel;
public final EnergyTier tier;
public final RcEnergyTier tier;
public DrillItem(ToolMaterials material, int energyCapacity, EnergyTier tier, int cost, float poweredSpeed, float unpoweredSpeed, MiningLevel miningLevel) {
public DrillItem(ToolMaterials material, int energyCapacity, RcEnergyTier tier, int cost, float poweredSpeed, float unpoweredSpeed, MiningLevel miningLevel) {
// combat stats same as for diamond pickaxe. Fix for #2468
super(material, 1, -2.8F, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
this.maxCharge = energyCapacity;
@ -69,7 +67,7 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
// Going to remain to use this ol reliable function, the fabric one is funky
if (Energy.of(stack).getEnergy() >= cost) {
if (getStoredEnergy(stack) >= cost) {
if (stack.getItem().isSuitableFor(state)) {
return poweredSpeed;
} else {
@ -105,7 +103,7 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
@Override
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
if (worldIn.random.nextInt(EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack) + 1) == 0) {
Energy.of(stack).use(cost);
tryUseEnergy(stack, cost);
}
return true;
}
@ -153,17 +151,17 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return tier;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}

View file

@ -37,26 +37,24 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
import techreborn.utils.ToolsUtil;
import java.util.Random;
public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions, DynamicAttributeTool {
public class JackhammerItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions, DynamicAttributeTool {
public final int maxCharge;
public final EnergyTier tier;
public final RcEnergyTier tier;
public final int cost;
protected final float unpoweredSpeed = 0.5F;
public JackhammerItem(int energyCapacity, EnergyTier tier, int cost) {
public JackhammerItem(int energyCapacity, RcEnergyTier tier, int cost) {
// combat stats same as for diamond pickaxe. Fix for #2468
super(ToolMaterials.DIAMOND, 1, -2.8F, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
this.maxCharge = energyCapacity;
@ -67,7 +65,7 @@ public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDur
// PickaxeItem
@Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
if (Energy.of(stack).getEnergy() < cost) return unpoweredSpeed;
if (getStoredEnergy(stack) < cost) return unpoweredSpeed;
if (ToolsUtil.JackHammerSkippedBlocks(state)) return unpoweredSpeed;
if (state.getMaterial() == Material.STONE) {
@ -95,7 +93,7 @@ public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDur
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
Random rand = new Random();
if (rand.nextInt(EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack) + 1) == 0) {
Energy.of(stack).use(cost);
tryUseEnergy(stack, cost);
}
return true;
}
@ -132,17 +130,17 @@ public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDur
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return tier;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}

View file

@ -41,7 +41,7 @@ import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.misc.MultiBlockBreakingTool;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.items.tool.JackhammerItem;
import techreborn.utils.MessageIDs;
@ -55,7 +55,7 @@ import java.util.stream.Collectors;
public class AdvancedJackhammerItem extends JackhammerItem implements MultiBlockBreakingTool {
public AdvancedJackhammerItem() {
super(TechRebornConfig.advancedJackhammerCharge, EnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost);
super(TechRebornConfig.advancedJackhammerCharge, RcEnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost);
}
private boolean shouldBreak(World worldIn, BlockPos originalPos, BlockPos pos, ItemStack stack) {

View file

@ -31,10 +31,10 @@ import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
import techreborn.utils.InitUtils;
@ -42,11 +42,11 @@ import techreborn.utils.InitUtils;
/**
* Created by modmuss50 on 05/11/2016.
*/
public class ElectricTreetapItem extends Item implements EnergyHolder, ItemDurabilityExtensions {
public class ElectricTreetapItem extends Item implements RcEnergyItem, ItemDurabilityExtensions {
public final int maxCharge = TechRebornConfig.electricTreetapCharge;
public int cost = TechRebornConfig.electricTreetapCost;
public EnergyTier tier = EnergyTier.MEDIUM;
public RcEnergyTier tier = RcEnergyTier.MEDIUM;
public ElectricTreetapItem() {
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
@ -85,12 +85,12 @@ public class ElectricTreetapItem extends Item implements EnergyHolder, ItemDurab
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
public RcEnergyTier getTier() {
return tier;
}
}

View file

@ -36,19 +36,17 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import java.util.Random;
public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions {
public class RockCutterItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions {
public static final int maxCharge = TechRebornConfig.rockCutterCharge;
public int cost = TechRebornConfig.rockCutterCost;
@ -67,7 +65,7 @@ public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDur
@Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
if (Energy.of(stack).getEnergy() < cost) {
if (getStoredEnergy(stack) < cost) {
return 2F;
} else {
return Items.DIAMOND_PICKAXE.getMiningSpeedMultiplier(stack, state);
@ -79,7 +77,7 @@ public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDur
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
Random rand = new Random();
if (rand.nextInt(EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack) + 1) == 0) {
Energy.of(stack).use(cost);
tryUseEnergy(stack, cost);
}
return true;
}
@ -123,7 +121,7 @@ public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDur
uncharged.addEnchantment(Enchantments.SILK_TOUCH, 1);
ItemStack charged = new ItemStack(TRContent.ROCK_CUTTER);
charged.addEnchantment(Enchantments.SILK_TOUCH, 1);
Energy.of(charged).set(Energy.of(charged).getMaxStored());
setStoredEnergy(charged, getEnergyCapacity());
stacks.add(uncharged);
stacks.add(charged);
@ -147,17 +145,17 @@ public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDur
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
return EnergyTier.MEDIUM;
public RcEnergyTier getTier() {
return RcEnergyTier.MEDIUM;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}
}

View file

@ -43,8 +43,7 @@ import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.items.tool.ChainsawItem;
import techreborn.utils.MessageIDs;
@ -59,7 +58,7 @@ public class IndustrialChainsawItem extends ChainsawItem {
private static final Direction[] SEARCH_ORDER = new Direction[]{Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP};
public IndustrialChainsawItem() {
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialChainsawCharge, EnergyTier.EXTREME, TechRebornConfig.industrialChainsawCost, 20F, 1.0F, Items.DIAMOND_AXE);
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialChainsawCharge, RcEnergyTier.EXTREME, TechRebornConfig.industrialChainsawCost, 20F, 1.0F, Items.DIAMOND_AXE);
}
private void findWood(World world, BlockPos pos, List<BlockPos> wood, List<BlockPos> leaves) {
@ -95,7 +94,7 @@ public class IndustrialChainsawItem extends ChainsawItem {
findWood(worldIn, pos, wood, leaves);
wood.remove(pos);
wood.stream()
.filter(p -> Energy.of(stack).simulate().use(cost))
.filter(p -> tryUseEnergy(stack, cost))
.forEach(pos1 -> ToolsUtil.breakBlock(stack, worldIn, pos1, entityLiving, cost));
leaves.remove(pos);
leaves.forEach(pos1 -> ToolsUtil.breakBlock(stack, worldIn, pos1, entityLiving, 0));

View file

@ -43,7 +43,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import techreborn.items.tool.DrillItem;
@ -57,7 +57,7 @@ import java.util.List;
public class IndustrialDrillItem extends DrillItem {
public IndustrialDrillItem() {
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialDrillCharge, EnergyTier.INSANE, TechRebornConfig.industrialDrillCost, 20.0F, 1.0F, MiningLevel.DIAMOND);
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialDrillCharge, RcEnergyTier.INSANE, TechRebornConfig.industrialDrillCost, 20.0F, 1.0F, MiningLevel.DIAMOND);
}
private boolean shouldBreak(PlayerEntity playerIn, World worldIn, BlockPos originalPos, BlockPos pos) {

View file

@ -45,7 +45,7 @@ import org.jetbrains.annotations.Nullable;
import reborncore.common.misc.MultiBlockBreakingTool;
import reborncore.common.util.ChatUtils;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.items.tool.JackhammerItem;
import techreborn.utils.MessageIDs;
@ -59,7 +59,7 @@ import java.util.stream.Collectors;
public class IndustrialJackhammerItem extends JackhammerItem implements MultiBlockBreakingTool {
public IndustrialJackhammerItem() {
super(TechRebornConfig.industrialJackhammerCharge, EnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost);
super(TechRebornConfig.industrialJackhammerCharge, RcEnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost);
}
// Cycle Inactive, Active 3*3 and Active 5*5

View file

@ -46,12 +46,10 @@ import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.items.ItemStackModifiers;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
@ -59,7 +57,7 @@ import techreborn.utils.MessageIDs;
import java.util.List;
public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabilityExtensions, ItemStackModifiers {
public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemDurabilityExtensions, ItemStackModifiers {
public static final int maxCharge = TechRebornConfig.nanosaberCharge;
public int cost = TechRebornConfig.nanosaberCost;
@ -71,7 +69,7 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
// SwordItem
@Override
public boolean postHit(ItemStack stack, LivingEntity entityHit, LivingEntity entityHitter) {
return Energy.of(stack).use(cost);
return tryUseEnergy(stack, cost);
}
// ToolItem
@ -120,12 +118,12 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
ItemStack inactiveCharged = new ItemStack(TRContent.NANOSABER);
inactiveCharged.setNbt(new NbtCompound());
inactiveCharged.getOrCreateNbt().putBoolean("isActive", false);
Energy.of(inactiveCharged).set(Energy.of(inactiveCharged).getMaxStored());
setStoredEnergy(inactiveCharged, getEnergyCapacity());
ItemStack activeCharged = new ItemStack(TRContent.NANOSABER);
activeCharged.setNbt(new NbtCompound());
activeCharged.getOrCreateNbt().putBoolean("isActive", true);
Energy.of(activeCharged).set(Energy.of(activeCharged).getMaxStored());
setStoredEnergy(activeCharged, getEnergyCapacity());
itemList.add(inactiveUncharged);
itemList.add(inactiveCharged);
@ -140,17 +138,17 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public EnergyTier getTier() {
return EnergyTier.EXTREME;
public RcEnergyTier getTier() {
return RcEnergyTier.EXTREME;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}

View file

@ -45,13 +45,11 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.TorchHelper;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
@ -60,7 +58,7 @@ import techreborn.utils.InitUtils;
import java.util.List;
public class OmniToolItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions, DynamicAttributeTool {
public class OmniToolItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions, DynamicAttributeTool {
public final int maxCharge = TechRebornConfig.omniToolCharge;
public int cost = TechRebornConfig.omniToolCost;
@ -83,7 +81,7 @@ public class OmniToolItem extends PickaxeItem implements EnergyHolder, ItemDurab
@Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
if (Energy.of(stack).getEnergy() >= cost) {
if (getStoredEnergy(stack) >= cost) {
return ToolMaterials.DIAMOND.getMiningSpeedMultiplier();
}
return super.getMiningSpeedMultiplier(stack, state);
@ -92,13 +90,13 @@ public class OmniToolItem extends PickaxeItem implements EnergyHolder, ItemDurab
// MiningToolItem
@Override
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
Energy.of(stack).use(cost);
tryUseEnergy(stack, cost);
return true;
}
@Override
public boolean postHit(ItemStack stack, LivingEntity entityliving, LivingEntity attacker) {
if (Energy.of(stack).use(hitCost)) {
if (tryUseEnergy(stack, hitCost)) {
entityliving.damage(DamageSource.player((PlayerEntity) attacker), 8F);
}
return false;
@ -159,18 +157,18 @@ public class OmniToolItem extends PickaxeItem implements EnergyHolder, ItemDurab
// EnergyHolder
@Override
public double getMaxStoredPower() {
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public double getMaxOutput(EnergySide side) {
public long getEnergyMaxOutput() {
return 0;
}
@Override
public EnergyTier getTier() {
return EnergyTier.EXTREME;
public RcEnergyTier getTier() {
return RcEnergyTier.EXTREME;
}
// DynamicAttributeTool

View file

@ -37,7 +37,7 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;
import reborncore.RebornRegistry;
import team.reborn.energy.Energy;
import reborncore.common.powerSystem.RcEnergyItem;
import techreborn.TechReborn;
public class InitUtils {
@ -59,8 +59,9 @@ public class InitUtils {
public static void initPoweredItems(Item item, DefaultedList<ItemStack> itemList) {
ItemStack uncharged = new ItemStack(item);
ItemStack charged = new ItemStack(item);
RcEnergyItem energyItem = (RcEnergyItem) item;
Energy.of(charged).set(Energy.of(charged).getMaxStored());
energyItem.setStoredEnergy(charged, energyItem.getEnergyCapacity());
itemList.add(uncharged);
itemList.add(charged);

View file

@ -32,7 +32,7 @@ import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.registry.Registry;
import reborncore.api.events.ItemCraftCallback;
import team.reborn.energy.Energy;
import reborncore.common.powerSystem.RcEnergyItem;
import techreborn.TechReborn;
import java.util.Map;
@ -49,15 +49,20 @@ public final class PoweredCraftingHandler implements ItemCraftCallback {
@Override
public void onCraft(ItemStack stack, CraftingInventory craftingInventory, PlayerEntity playerEntity) {
if (Energy.valid(stack)) {
double totalEnergy = IntStream.range(0, craftingInventory.size())
if (stack.getItem() instanceof RcEnergyItem energyItem) {
long totalEnergy = IntStream.range(0, craftingInventory.size())
.mapToObj(craftingInventory::getStack)
.filter(s -> !s.isEmpty())
.filter(Energy::valid)
.mapToDouble(s -> Energy.of(s).getEnergy())
.mapToLong(s -> {
if (s.getItem() instanceof RcEnergyItem inputItem) {
return inputItem.getStoredEnergy(s);
} else {
return 0;
}
})
.sum();
Energy.of(stack).set(totalEnergy);
energyItem.setStoredEnergy(stack, totalEnergy);
}
if (!Registry.ITEM.getId(stack.getItem()).getNamespace().equalsIgnoreCase(TechReborn.MOD_ID)) {

View file

@ -37,7 +37,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import team.reborn.energy.Energy;
import reborncore.common.powerSystem.RcEnergyItem;
import java.util.Collections;
import java.util.HashSet;
@ -59,7 +59,7 @@ public class ToolsUtil {
}
Random rand = new Random();
if (rand.nextInt(EnchantmentHelper.getLevel(Enchantments.UNBREAKING, tool) + 1) == 0) {
if (!Energy.of(tool).use(cost)) {
if (!((RcEnergyItem) tool.getItem()).tryUseEnergy(tool, cost)) {
return;
}
}