Use new canAccept/canProvide methods

This commit is contained in:
drcrazy 2020-10-21 01:15:36 +03:00
parent df974ef5da
commit aa18079315
23 changed files with 317 additions and 343 deletions

View file

@ -28,7 +28,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
@ -39,6 +38,7 @@ 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;
@ -157,15 +157,10 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
}
@Override
public boolean canAcceptEnergy(Direction direction) {
public boolean canAcceptEnergy(EnergySide side) {
return false;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return true;
}
@Override
public RebornInventory<?> getInventory() {
return inventory;

View file

@ -36,6 +36,7 @@ import net.minecraft.world.Heightmap;
import reborncore.api.IToolDrop;
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;
@ -53,6 +54,10 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
public void tick() {
super.tick();
if (world == null){
return;
}
if (onStatusHoldTicks > 0) {
--onStatusHoldTicks;
}
@ -110,6 +115,9 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
}
public boolean isValidIronFence(int y) {
if (world == null){
return false;
}
Block block = this.world.getBlockState(new BlockPos(pos.getX(), y, pos.getZ())).getBlock();
return block == TRContent.REFINED_IRON_FENCE;
}
@ -120,15 +128,10 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
public boolean canAcceptEnergy(EnergySide side) {
return false;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
return true;
}
@Override
public double getBaseMaxOutput() {
return TechRebornConfig.lightningRodMaxOutput;

View file

@ -33,7 +33,6 @@ import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
@ -42,6 +41,7 @@ import reborncore.common.blocks.BlockMachineBase;
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 techreborn.blocks.generator.BlockSolarPanel;
import techreborn.init.TRBlockEntities;
@ -179,14 +179,7 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
return false;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
return true;
}
protected boolean canAcceptEnergy(EnergySide side) { return false; }
@Override
public double getBaseMaxOutput() {

View file

@ -28,12 +28,12 @@ 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 reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
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;
@ -57,11 +57,15 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
return false;
}
// TilePowerAcceptor
// PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (world == null) {
return;
}
if (!world.isClient) {
if (world.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))
.getBlock() == Blocks.DRAGON_EGG) {
@ -83,15 +87,10 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(Direction direction) {
public boolean canAcceptEnergy(EnergySide side) {
return false;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return true;
}
@Override
public double getBaseMaxOutput() {
return TechRebornConfig.dragonEggSyphonMaxOutput;
@ -108,7 +107,7 @@ public class DragonEggSyphonBlockEntity extends PowerAcceptorBlockEntity
return TRContent.Machine.DRAGON_EGG_SYPHON.getStack();
}
// ItemHandlerProvider
// InventoryProvider
@Override
public RebornInventory<DragonEggSyphonBlockEntity> getInventory() {
return inventory;

View file

@ -31,7 +31,6 @@ import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -40,6 +39,7 @@ import reborncore.client.screen.builder.ScreenHandlerBuilder;
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;
@ -77,6 +77,9 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
@Override
public void tick() {
super.tick();
if (world == null){
return;
}
if (world.isClient) {
return;
}
@ -131,15 +134,10 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
}
@Override
public boolean canAcceptEnergy(Direction direction) {
public boolean canAcceptEnergy(EnergySide side) {
return false;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return true;
}
@Override
public double getBaseMaxOutput() {
return TechRebornConfig.solidFuelGeneratorMaxOutput;

View file

@ -31,6 +31,7 @@ import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
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;
@ -75,15 +76,10 @@ public class WaterMillBlockEntity extends PowerAcceptorBlockEntity implements IT
}
@Override
public boolean canAcceptEnergy(Direction direction) {
public boolean canAcceptEnergy(EnergySide side) {
return false;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return true;
}
@Override
public double getBaseMaxOutput() {
return TechRebornConfig.waterMillMaxOutput;

View file

@ -26,9 +26,9 @@ package techreborn.blockentity.generator.basic;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -50,6 +50,10 @@ public class WindMillBlockEntity extends PowerAcceptorBlockEntity implements ITo
public void tick() {
super.tick();
if (world == null) {
return;
}
boolean generating = pos.getY() > 64;
if (world.isClient) {
@ -79,12 +83,7 @@ public class WindMillBlockEntity extends PowerAcceptorBlockEntity implements ITo
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return false;
}
@Override
public boolean canProvideEnergy(Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return true;
}

View file

@ -31,11 +31,11 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.blocks.lighting.LampBlock;
import techreborn.init.TRBlockEntities;
public class LampBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop {
public class LampBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
private static final int capacity = 33;
@ -43,7 +43,7 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
super(TRBlockEntities.LAMP);
}
// TilePowerAcceptor
// PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
@ -52,16 +52,41 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
}
BlockState state = world.getBlockState(pos);
Block b = state.getBlock();
if (b instanceof LampBlock) {
double cost = getEuPerTick(((LampBlock) b).getCost());
if (getEnergy() > cost) {
useEnergy(getEuPerTick(cost));
if (!LampBlock.isActive(state))
LampBlock.setActive(true, world, pos);
} else if (LampBlock.isActive(state)) {
LampBlock.setActive(false, world, pos);
}
if (!(b instanceof LampBlock)) {
return;
}
double cost = getEuPerTick(((LampBlock) b).getCost());
if (getStored(EnergySide.UNKNOWN) > cost) {
useEnergy(cost);
if (!LampBlock.isActive(state)) {
LampBlock.setActive(true, world, pos);
}
} else if (LampBlock.isActive(state)) {
LampBlock.setActive(false, world, pos);
}
}
// @Override
// public boolean canAcceptEnergy(final Direction direction) {
// if (world == null) {
// // Blame tooltip for this
// return true;
// }
// Direction me = LampBlock.getFacing(world.getBlockState(pos)).getOpposite();
// return direction == me;
// }
@Override
protected boolean canAcceptEnergy(EnergySide side) {
return side == EnergySide.UNKNOWN || getFacing().getOpposite() != Direction.values()[side.ordinal()];
}
@Override
public boolean canProvideEnergy(EnergySide side) {
return false;
}
@Override
@ -69,21 +94,6 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
return capacity;
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
if (world == null) {
// Blame tooltip for this
return true;
}
Direction me = LampBlock.getFacing(world.getBlockState(pos)).getOpposite();
return direction == me;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
return false;
}
@Override
public double getBaseMaxOutput() {
return 0;
@ -99,6 +109,4 @@ public class LampBlockEntity extends PowerAcceptorBlockEntity
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
return new ItemStack(world.getBlockState(pos).getBlock());
}
}

View file

@ -28,13 +28,13 @@ import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.EnergySide;
/**
* @author drcrazy
@ -67,6 +67,12 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
checkTier();
}
/**
* Returns progress scaled to input value
*
* @param scale int Maximum value for progress
* @return int Scale of progress
*/
public int getProgressScaled(int scale) {
if (crafter != null && crafter.currentTickTime != 0) {
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
@ -78,7 +84,10 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (!world.isClient && energySlot != -1) {
if (world == null || world.isClient) {
return;
}
if (energySlot != -1) {
charge(energySlot);
}
}
@ -89,12 +98,7 @@ public abstract class GenericMachineBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -26,7 +26,6 @@ package techreborn.blockentity.machine.misc;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -35,6 +34,7 @@ import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
@ -76,13 +76,8 @@ public class ChargeOMatBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
return direction == null;
public boolean canProvideEnergy(EnergySide side) {
return false;
}
@Override

View file

@ -32,7 +32,6 @@ 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 reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
@ -53,9 +52,7 @@ import techreborn.init.TRContent;
public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public RebornInventory<FusionControlComputerBlockEntity> inventory;
public int crafingTickTime = 0;
public int craftingTickTime = 0;
public int neededPower = 0;
public int size = 6;
public int state = -1;
@ -74,10 +71,44 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
this.inventory = new RebornInventory<>(3, "FusionControlComputerBlockEntity", 64, this);
}
@Override
public void writeMultiblock(MultiblockWriter writer) {
BlockState coil = TRContent.Machine.FUSION_COIL.block.getDefaultState();
Torus.generate(BlockPos.ORIGIN, size).forEach(pos -> writer.add(pos.getX(), pos.getY(), pos.getZ(), coil));
public FusionReactorRecipe getCurrentRecipeFromID() {
if (currentRecipeID == null) return null;
return ModRecipes.FUSION_REACTOR.getRecipes(world).stream()
.filter(recipe -> recipe.getId().equals(currentRecipeID))
.findFirst()
.orElse(null);
}
//TODO: translate
public Text getStateText() {
if (state == -1) {
return LiteralText.EMPTY;
} else if (state == 0) {
return new LiteralText("No recipe");
} else if (state == 1) {
FusionReactorRecipe r = getCurrentRecipeFromID();
if (r == null) {
return new LiteralText("Charging");
}
int percentage = percentage(r.getStartEnergy(), getEnergy());
return new LiteralText("Charging (")
.append(StringUtils.getPercentageText(percentage));
} else if (state == 2) {
return new LiteralText("Crafting");
}
return LiteralText.EMPTY;
}
/**
* Changes size of fusion reactor ring after GUI button click
*
* @param sizeDelta int Size increment
*/
public void changeSize(int sizeDelta) {
int newSize = size + sizeDelta;
this.size = Math.max(6, Math.min(TechRebornConfig.fusionControlComputerMaxCoilSize, newSize));
}
/**
@ -85,7 +116,7 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
*/
private void resetCrafter() {
currentRecipe = null;
crafingTickTime = 0;
craftingTickTime = 0;
neededPower = 0;
hasStartedCrafting = false;
}
@ -113,20 +144,6 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
return false;
}
/**
* Returns progress scaled to input value
*
* @param scale int Maximum value for progress
* @return int Scale of progress
*/
public int getProgressScaled(int scale) {
FusionReactorRecipe reactorRecipe = getCurrentRecipeFromID();
if (crafingTickTime != 0 && reactorRecipe != null && reactorRecipe.getTime() != 0) {
return crafingTickTime * scale / reactorRecipe.getTime();
}
return 0;
}
/**
* Tries to set current recipe based in inputs in reactor
*/
@ -134,7 +151,7 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
for (RebornRecipe recipe : ModRecipes.FUSION_REACTOR.getRecipes(getWorld())) {
if (validateRecipe((FusionReactorRecipe) recipe)) {
currentRecipe = (FusionReactorRecipe) recipe;
crafingTickTime = 0;
craftingTickTime = 0;
neededPower = currentRecipe.getStartEnergy();
hasStartedCrafting = false;
break;
@ -192,13 +209,50 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
}
private int percentage(double MaxValue, double CurrentValue) {
if (CurrentValue == 0) {
return 0;
}
return (int) ((CurrentValue * 100.0f) / MaxValue);
}
// TilePowerAcceptor
// GenericMachineBlockEntity
@Override
public int getProgressScaled(int scale) {
FusionReactorRecipe reactorRecipe = getCurrentRecipeFromID();
if (craftingTickTime != 0 && reactorRecipe != null && reactorRecipe.getTime() != 0) {
return craftingTickTime * scale / reactorRecipe.getTime();
}
return 0;
}
@Override
public double getBaseMaxPower() {
return Math.min(TechRebornConfig.fusionControlComputerMaxEnergy * getPowerMultiplier(), Integer.MAX_VALUE);
}
@Override
public double getBaseMaxOutput() {
if (!hasStartedCrafting) {
return 0;
}
return TechRebornConfig.fusionControlComputerMaxOutput;
}
@Override
public double getBaseMaxInput() {
if (hasStartedCrafting) {
return 0;
}
return TechRebornConfig.fusionControlComputerMaxInput;
}
// PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (world.isClient) {
if (world == null || world.isClient) {
return;
}
@ -213,7 +267,7 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
if (lastTick == world.getTime()) {
//Prevent tick accerators, blame obstinate for this.
//Prevent tick accelerators, blame obstinate for this.
return;
}
lastTick = world.getTime();
@ -248,21 +302,21 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
useInput(bottomStackSlot);
}
}
if (hasStartedCrafting && crafingTickTime < currentRecipe.getTime()) {
if (hasStartedCrafting && craftingTickTime < currentRecipe.getTime()) {
// Power gen
if (currentRecipe.getPower() > 0) {
// Waste power if it has no where to go
double power = Math.abs(currentRecipe.getPower()) * getPowerMultiplier();
addEnergy(power);
powerChange = (power);
crafingTickTime++;
craftingTickTime++;
} else { // Power user
if (getStored(EnergySide.UNKNOWN) > currentRecipe.getPower()) {
setEnergy(getEnergy() - currentRecipe.getPower());
crafingTickTime++;
craftingTickTime++;
}
}
} else if (crafingTickTime >= currentRecipe.getTime()) {
} else if (craftingTickTime >= currentRecipe.getTime()) {
ItemStack result = currentRecipe.getOutputs().get(0);
if (canFitStack(result, outputStackSlot, true)) {
if (inventory.getStack(outputStackSlot).isEmpty()) {
@ -271,7 +325,7 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
inventory.shrinkSlot(outputStackSlot, -result.getCount());
}
if (validateRecipe(this.currentRecipe)) {
crafingTickTime = 0;
craftingTickTime = 0;
useInput(topStackSlot);
useInput(bottomStackSlot);
} else {
@ -285,48 +339,22 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
inventory.resetChanged();
}
@Override
public double getPowerMultiplier() {
double calc = (1F / 2F) * Math.pow(size - 5, 1.8);
return Math.max(Math.round(calc * 100D) / 100D, 1D);
protected boolean canAcceptEnergy(EnergySide side) {
// Accept from sides
return !(side == EnergySide.DOWN || side == EnergySide.UP);
}
@Override
public double getBaseMaxPower() {
return Math.min(TechRebornConfig.fusionControlComputerMaxEnergy * getPowerMultiplier(), Integer.MAX_VALUE);
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return !(direction == Direction.DOWN || direction == Direction.UP);
}
@Override
public boolean canProvideEnergy(Direction direction) {
return direction == Direction.DOWN || direction == Direction.UP;
}
@Override
public double getBaseMaxOutput() {
if (!hasStartedCrafting) {
return 0;
}
return TechRebornConfig.fusionControlComputerMaxOutput;
}
@Override
public double getBaseMaxInput() {
if (hasStartedCrafting) {
return 0;
}
return TechRebornConfig.fusionControlComputerMaxInput;
public boolean canProvideEnergy(EnergySide side) {
// Provide from top and bottom
return side == EnergySide.DOWN || side == EnergySide.UP;
}
@Override
public void fromTag(BlockState blockState, final CompoundTag tagCompound) {
super.fromTag(blockState, tagCompound);
this.crafingTickTime = tagCompound.getInt("crafingTickTime");
this.craftingTickTime = tagCompound.getInt("craftingTickTime");
this.neededPower = tagCompound.getInt("neededPower");
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
if (tagCompound.contains("hasActiveRecipe") && tagCompound.getBoolean("hasActiveRecipe") && this.currentRecipe == null) {
@ -335,13 +363,14 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
if (tagCompound.contains("size")) {
this.size = tagCompound.getInt("size");
}
this.size = Math.min(size, TechRebornConfig.fusionControlComputerMaxCoilSize);//Done here to force the samller size, will be useful if people lag out on a large one.
//Done here to force the smaller size, will be useful if people lag out on a large one.
this.size = Math.min(size, TechRebornConfig.fusionControlComputerMaxCoilSize);
}
@Override
public CompoundTag toTag(final CompoundTag tagCompound) {
super.toTag(tagCompound);
tagCompound.putInt("crafingTickTime", this.crafingTickTime);
tagCompound.putInt("craftingTickTime", this.craftingTickTime);
tagCompound.putInt("neededPower", this.neededPower);
tagCompound.putBoolean("hasStartedCrafting", this.hasStartedCrafting);
tagCompound.putBoolean("hasActiveRecipe", this.currentRecipe != null);
@ -349,23 +378,30 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
return tagCompound;
}
//MachineBaseBlockEntity
@Override
public double getPowerMultiplier() {
double calc = (1F / 2F) * Math.pow(size - 5, 1.8);
return Math.max(Math.round(calc * 100D) / 100D, 1D);
}
@Override
public void writeMultiblock(MultiblockWriter writer) {
BlockState coil = TRContent.Machine.FUSION_COIL.block.getDefaultState();
Torus.generate(BlockPos.ORIGIN, size).forEach(pos -> writer.add(pos.getX(), pos.getY(), pos.getZ(), coil));
}
@Override
public boolean canBeUpgraded() {
return false;
}
// ItemHandlerProvider
@Override
public RebornInventory<FusionControlComputerBlockEntity> getInventory() {
return inventory;
}
// IContainerProvider
// BuiltScreenHandlerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("fusionreactor").player(player.inventory).inventory().hotbar()
.addInventory().blockEntity(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).syncEnergyValue()
.sync(this::getCrafingTickTime, this::setCrafingTickTime)
.sync(this::getCraftingTickTime, this::setCraftingTickTime)
.sync(this::getSize, this::setSize)
.sync(this::getState, this::setState)
.sync(this::getNeededPower, this::setNeededPower)
@ -374,20 +410,12 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
.create(this, syncID);
}
public int getCrafingTickTime() {
return crafingTickTime;
public int getCraftingTickTime() {
return craftingTickTime;
}
public void setCrafingTickTime(int crafingTickTime) {
this.crafingTickTime = crafingTickTime;
}
public int getNeededPower() {
return neededPower;
}
public void setNeededPower(int neededPower) {
this.neededPower = neededPower;
public void setCraftingTickTime(int craftingTickTime) {
this.craftingTickTime = craftingTickTime;
}
public int getSize() {
@ -398,11 +426,6 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
this.size = size;
}
public void changeSize(int sizeDelta) {
int newSize = size + sizeDelta;
this.size = Math.max(6, Math.min(TechRebornConfig.fusionControlComputerMaxCoilSize, newSize));
}
public int getState() {
if (currentRecipe == null) {
return 0; //No Recipe
@ -417,6 +440,14 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
this.state = state;
}
public int getNeededPower() {
return neededPower;
}
public void setNeededPower(int neededPower) {
this.neededPower = neededPower;
}
public Identifier getCurrentRecipeID() {
if (currentRecipe == null) {
return new Identifier("null", "null");
@ -430,38 +461,4 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
this.currentRecipeID = currentRecipeID;
}
public FusionReactorRecipe getCurrentRecipeFromID() {
if (currentRecipeID == null) return null;
return ModRecipes.FUSION_REACTOR.getRecipes(world).stream()
.filter(recipe -> recipe.getId().equals(currentRecipeID))
.findFirst()
.orElse(null);
}
public Text getStateText() {
if (state == -1) {
return LiteralText.EMPTY;
} else if (state == 0) {
return new LiteralText("No recipe");
} else if (state == 1) {
FusionReactorRecipe r = getCurrentRecipeFromID();
if (r == null) {
return new LiteralText("Charging");
}
int percentage = percentage(r.getStartEnergy(), getEnergy());
return new LiteralText("Charging (")
.append(StringUtils.getPercentageText(percentage));
} else if (state == 2) {
return new LiteralText("Crafting");
}
return LiteralText.EMPTY;
}
private int percentage(double MaxValue, double CurrentValue) {
if (CurrentValue == 0) {
return 0;
}
return (int) ((CurrentValue * 100.0f) / MaxValue);
}
}

View file

@ -412,12 +412,7 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(Direction enumFacing) {
return true;
}
@Override
public boolean canProvideEnergy(Direction enumFacing) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -29,7 +29,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.SmeltingRecipe;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -194,7 +193,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
super.tick();
charge(2);
if (world.isClient) {
if (world == null || world.isClient) {
return;
}
@ -231,21 +230,16 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
setInvDirty(false);
}
@Override
protected boolean canProvideEnergy(EnergySide side) {
return false;
}
@Override
public double getBaseMaxPower() {
return TechRebornConfig.electricFurnaceMaxEnergy;
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
return false;
}
@Override
public double getBaseMaxOutput() {
return 0;
@ -262,13 +256,13 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
return TRContent.Machine.ELECTRIC_FURNACE.getStack();
}
// ItemHandlerProvider
// InventoryProvider
@Override
public RebornInventory<ElectricFurnaceBlockEntity> getInventory() {
return inventory;
}
// IContainerProvider
// BuiltScreenHandlerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("electricfurnace").player(player.inventory).inventory().hotbar().addInventory()

View file

@ -214,7 +214,7 @@ public class GreenhouseControllerBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canProvideEnergy(Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -28,7 +28,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.WorldUtils;
@ -53,36 +52,47 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
return redstone;
}
// TilePowerAcceptor
// PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (!world.isClient && world.getTime() % 20 == 0) {
boolean lastRedstone = redstone;
redstone = false;
if (getStored(EnergySide.UNKNOWN) > TechRebornConfig.playerDetectorEuPerTick) {
for (PlayerEntity player : world.getPlayers()) {
if (player.distanceTo(player) <= 256.0D) {
PlayerDetectorType type = world.getBlockState(pos).get(PlayerDetectorBlock.TYPE);
if (type == PlayerDetectorType.ALL) {// ALL
if (world == null) {
return;
}
if (world.isClient) {
return;
}
if (world.getTime() % 20 != 0) {
return;
}
boolean lastRedstone = redstone;
redstone = false;
if (getStored(EnergySide.UNKNOWN) > TechRebornConfig.playerDetectorEuPerTick) {
for (PlayerEntity player : world.getPlayers()) {
if (player.distanceTo(player) <= 256.0D) {
PlayerDetectorType type = world.getBlockState(pos).get(PlayerDetectorBlock.TYPE);
if (type == PlayerDetectorType.ALL) {// ALL
redstone = true;
} else if (type == PlayerDetectorType.OTHERS) {// Others
if (!owenerUdid.isEmpty() && !owenerUdid.equals(player.getUuid().toString())) {
redstone = true;
}
} else {// You
if (!owenerUdid.isEmpty() && owenerUdid.equals(player.getUuid().toString())) {
redstone = true;
} else if (type == PlayerDetectorType.OTHERS) {// Others
if (!owenerUdid.isEmpty() && !owenerUdid.equals(player.getUuid().toString())) {
redstone = true;
}
} else {// You
if (!owenerUdid.isEmpty() && owenerUdid.equals(player.getUuid().toString())) {
redstone = true;
}
}
}
}
useEnergy(TechRebornConfig.playerDetectorEuPerTick);
}
if (lastRedstone != redstone) {
WorldUtils.updateBlock(world, pos);
world.updateNeighborsAlways(pos, world.getBlockState(pos).getBlock());
}
useEnergy(TechRebornConfig.playerDetectorEuPerTick);
}
if (lastRedstone != redstone) {
WorldUtils.updateBlock(world, pos);
world.updateNeighborsAlways(pos, world.getBlockState(pos).getBlock());
}
}
@ -92,12 +102,7 @@ public class PlayerDectectorBlockEntity extends PowerAcceptorBlockEntity impleme
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -28,7 +28,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.IUpgrade;
@ -152,12 +151,7 @@ public class RecyclerBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -31,7 +31,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.Ingredient;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import reborncore.api.IToolDrop;
@ -85,12 +84,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(final Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(final Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -26,7 +26,6 @@ package techreborn.blockentity.machine.tier3;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -157,12 +156,7 @@ public class MatterFabricatorBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return true;
}
@Override
public boolean canProvideEnergy(Direction direction) {
public boolean canProvideEnergy(EnergySide side) {
return false;
}

View file

@ -33,15 +33,14 @@ import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyTier;
import techreborn.blocks.storage.energy.EnergyStorageBlock;
/**
* Created by Rushmead
*/
public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, InventoryProvider {
public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider {
public RebornInventory<EnergyStorageBlockEntity> inventory;
public String name;
@ -68,6 +67,9 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
@Override
public void tick() {
super.tick();
if (world == null) {
return;
}
if (world.isClient) {
return;
}
@ -79,21 +81,21 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
}
}
@Override
public boolean canAcceptEnergy(EnergySide side) {
return side == EnergySide.UNKNOWN || getFacing() != Direction.values()[side.ordinal()];
}
@Override
public boolean canProvideEnergy(EnergySide side) {
return side == EnergySide.UNKNOWN || getFacing() == Direction.values()[side.ordinal()];
}
@Override
public double getBaseMaxPower() {
return maxStorage;
}
@Override
public boolean canAcceptEnergy(Direction direction) {
return direction == null || getFacing() != direction;
}
@Override
public boolean canProvideEnergy(Direction direction) {
return direction == null || getFacing() == direction;
}
@Override
public double getBaseMaxOutput() {
return maxOutput;

View file

@ -90,6 +90,11 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
return;
}
@Override
protected boolean shouldHandleEnergyNBT() {
return false;
}
@Override
public void fromTag(BlockState blockState, CompoundTag nbttagcompound) {
super.fromTag(blockState, nbttagcompound);
@ -112,9 +117,4 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
.complete(8, 18).addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this, syncID);
}
@Override
protected boolean shouldHandleEnergyNBT() {
return false;
}
}

View file

@ -47,14 +47,12 @@ import java.util.List;
/**
* Created by Rushmead
*/
public class TransformerBlockEntity extends PowerAcceptorBlockEntity
implements IToolDrop, IListInfoProvider {
public class TransformerBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, IListInfoProvider {
public String name;
public Block wrenchDrop;
public EnergyTier inputTier;
public EnergyTier ouputTier;
public EnergyTier outputTier;
public int maxInput;
public int maxOutput;
public int maxStorage;
@ -64,9 +62,9 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
this.wrenchDrop = wrenchDrop;
this.inputTier = tier;
if (tier != EnergyTier.MICRO) {
ouputTier = EnergyTier.values()[tier.ordinal() - 1];
outputTier = EnergyTier.values()[tier.ordinal() - 1];
} else {
ouputTier = EnergyTier.MICRO;
outputTier = EnergyTier.MICRO;
}
this.name = name;
this.maxInput = tier.getMaxInput();
@ -75,31 +73,37 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
}
// TilePowerAcceptor
// PowerAcceptorBlockEntity
@Override
protected boolean canAcceptEnergy(EnergySide side) {
if (side == EnergySide.UNKNOWN) {
return true;
}
if (TechRebornConfig.IC2TransformersStyle) {
return getFacing() == Direction.values()[side.ordinal()];
}
return getFacing() != Direction.values()[side.ordinal()];
}
@Override
protected boolean canProvideEnergy(EnergySide side) {
if (side == EnergySide.UNKNOWN) {
return true;
}
if (TechRebornConfig.IC2TransformersStyle) {
return getFacing() != Direction.values()[side.ordinal()];
}
return getFacing() == Direction.values()[side.ordinal()];
}
@Override
public double getBaseMaxPower() {
return maxStorage;
}
@Override
public boolean canAcceptEnergy(Direction direction) {
if (TechRebornConfig.IC2TransformersStyle) {
return getFacingEnum() == direction;
}
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(Direction direction) {
if (TechRebornConfig.IC2TransformersStyle) {
return getFacingEnum() != direction;
}
return getFacing() == direction;
}
@Override
public double getBaseMaxOutput() {
return ouputTier.getMaxOutput();
return outputTier.getMaxOutput();
}
@Override
@ -112,7 +116,7 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
//Nope
}
// TileMachineBase
// MachineBaseBlockEntity
@Override
public Direction getFacingEnum() {
if (world == null) {
@ -125,6 +129,11 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
return null;
}
@Override
public boolean canBeUpgraded() {
return false;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity playerIn) {
@ -132,12 +141,12 @@ public class TransformerBlockEntity extends PowerAcceptorBlockEntity
}
// IListInfoProvider
// TO-DO: translate
@Override
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
info.add(new LiteralText(Formatting.GRAY + "Input Rate: " + Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted((int) getMaxInput(EnergySide.UNKNOWN))));
info.add(new LiteralText(Formatting.GRAY + "Input Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(inputTier.toString())));
info.add(new LiteralText(Formatting.GRAY + "Output Rate: " + Formatting.GOLD + PowerSystem.getLocaliszedPowerFormatted((int) getMaxOutput(EnergySide.UNKNOWN))));
info.add(new LiteralText(Formatting.GRAY + "Output Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(ouputTier.toString())));
info.add(new LiteralText(Formatting.GRAY + "Output Tier: " + Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(outputTier.toString())));
}
}

View file

@ -86,7 +86,7 @@ public class BlockFusionControlComputer extends BlockMachineBase {
public void onSteppedOn(final World worldIn, final BlockPos pos, final Entity entityIn) {
super.onSteppedOn(worldIn, pos, entityIn);
if (worldIn.getBlockEntity(pos) instanceof FusionControlComputerBlockEntity) {
if (((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).crafingTickTime != 0
if (((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).craftingTickTime != 0
&& ((FusionControlComputerBlockEntity) worldIn.getBlockEntity(pos)).isMultiblockValid()) {
entityIn.damage(new FusionDamageSource(), 200F);
}

View file

@ -122,10 +122,10 @@ public class LampBlock extends BaseBlockEntityProvider {
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
for (Direction enumfacing : context.getPlacementDirections()) {
BlockState iblockstate = this.getDefaultState().with(FACING, enumfacing.getOpposite());
if (iblockstate.canPlaceAt(context.getWorld(), context.getBlockPos())) {
return iblockstate;
for (Direction facing : context.getPlacementDirections()) {
BlockState state = this.getDefaultState().with(FACING, facing.getOpposite());
if (state.canPlaceAt(context.getWorld(), context.getBlockPos())) {
return state;
}
}
return null;