Merge remote-tracking branch 'origin/1.15' into 1.15
This commit is contained in:
commit
4cc07abe90
40 changed files with 539 additions and 240 deletions
|
@ -33,6 +33,9 @@ import net.minecraft.text.Text;
|
|||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.client.containerBuilder.IContainerProvider;
|
||||
import reborncore.client.containerBuilder.builder.BuiltContainer;
|
||||
import reborncore.client.containerBuilder.builder.ContainerBuilder;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
|
@ -45,25 +48,26 @@ import techreborn.init.TRContent.SolarPanels;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop {
|
||||
public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, IContainerProvider {
|
||||
|
||||
|
||||
// State ZEROGEN: No exposure to sun
|
||||
// State NIGHTGEN: Has direct exposure to sun
|
||||
// State DAYGEN: Has exposure to sun and weather is sunny and not raining/thundering
|
||||
public static final int ZEROGEN = 0;
|
||||
public static final int NIGHTGEN = 1;
|
||||
public static final int DAYGEN = 2;
|
||||
|
||||
private int state = ZEROGEN;
|
||||
private int prevState = ZEROGEN;
|
||||
|
||||
boolean canSeeSky = false;
|
||||
boolean lastState = false;
|
||||
private SolarPanels panel;
|
||||
|
||||
public SolarPanelBlockEntity() {
|
||||
super(TRBlockEntities.SOLAR_PANEL);
|
||||
}
|
||||
|
||||
public SolarPanelBlockEntity(SolarPanels panel) {
|
||||
super(TRBlockEntities.SOLAR_PANEL);
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
public boolean isSunOut() {
|
||||
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDay();
|
||||
}
|
||||
|
||||
private void updatePanel() {
|
||||
if (world == null) {
|
||||
return;
|
||||
|
@ -75,35 +79,81 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
}
|
||||
}
|
||||
|
||||
// PowerAcceptorBlockEntity
|
||||
|
||||
// Setters and getters for the GUI to sync
|
||||
private void setSunState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getSunState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
SolarPanels getPanel() {
|
||||
if (panel == null) {
|
||||
updatePanel();
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
if (world.isSkyVisible(pos.up())) {
|
||||
this.setSunState(NIGHTGEN);
|
||||
|
||||
if (!world.isRaining() && !world.isThundering() && world.isDay()) {
|
||||
this.setSunState(DAYGEN);
|
||||
}
|
||||
} else {
|
||||
this.setSunState(ZEROGEN);
|
||||
}
|
||||
|
||||
if (prevState != this.getSunState()) {
|
||||
boolean isGenerating = getSunState() == DAYGEN;
|
||||
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, isGenerating));
|
||||
|
||||
prevState = this.getSunState();
|
||||
}
|
||||
}
|
||||
|
||||
public int getGenerationRate() {
|
||||
int rate = 0;
|
||||
|
||||
switch (getSunState()) {
|
||||
case DAYGEN:
|
||||
rate = getPanel().generationRateD;
|
||||
break;
|
||||
case NIGHTGEN:
|
||||
rate = getPanel().generationRateN;
|
||||
}
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
|
||||
// Overrides
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getPanel() == TRContent.SolarPanels.CREATIVE) {
|
||||
checkOverfill = false;
|
||||
setEnergy(Integer.MAX_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
// State checking and updating
|
||||
if (world.getTime() % 20 == 0) {
|
||||
canSeeSky = world.isSkyVisible(pos.up());
|
||||
if (lastState != isSunOut()) {
|
||||
world.setBlockState(pos, world.getBlockState(pos).with(BlockMachineBase.ACTIVE, isSunOut()));
|
||||
lastState = isSunOut();
|
||||
}
|
||||
}
|
||||
int powerToAdd;
|
||||
if (isSunOut()) {
|
||||
powerToAdd = getPanel().generationRateD;
|
||||
} else if (canSeeSky) {
|
||||
powerToAdd = getPanel().generationRateN;
|
||||
} else {
|
||||
powerToAdd = 0;
|
||||
updateState();
|
||||
}
|
||||
|
||||
addEnergy(powerToAdd);
|
||||
// Power generation calculations
|
||||
addEnergy(getGenerationRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,7 +173,8 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
|
||||
@Override
|
||||
public double getBaseMaxOutput() {
|
||||
return getPanel().generationRateD;
|
||||
// Solar panel output will only be limited by the cables the users use
|
||||
return EnergyTier.EXTREME.getMaxOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,6 +182,16 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlotConfig() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyTier getTier() {
|
||||
return getPanel().powerTier;
|
||||
|
@ -141,13 +202,6 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
// Nope
|
||||
}
|
||||
|
||||
public SolarPanels getPanel() {
|
||||
if(panel == null){
|
||||
updatePanel();
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInfo(List<Text> info, boolean isReal, boolean hasData) {
|
||||
if (panel == SolarPanels.CREATIVE) {
|
||||
|
@ -188,4 +242,12 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
|
|||
public ItemStack getToolDrop(final PlayerEntity playerIn) {
|
||||
return new ItemStack(getBlockType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
|
||||
return new ContainerBuilder("solar_panel").player(player.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).syncEnergyValue()
|
||||
.sync(this::getSunState, this::setSunState)
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue