This commit is contained in:
parent
40580ec504
commit
cc4795c9d3
@ -38,7 +38,7 @@ public class SolarPanelBlockEntity extends EnergyGeneratorBlockEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void serverTick() {
|
protected void serverTick() {
|
||||||
setEnergy(getDisplayEnergy());
|
|
||||||
super.serverTick();
|
super.serverTick();
|
||||||
|
setEnergy(getDisplayEnergy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,7 @@ public class PassiveBatteryControllerBlockEntity extends EnergyReceiverBlockEnti
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
||||||
|
super.handlePropagatedAction(action);
|
||||||
handlePropagatedActionWithGenerator(action);
|
handlePropagatedActionWithGenerator(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void serverTick() {
|
protected void serverTick() {
|
||||||
|
super.serverTick();
|
||||||
if (getCachedState().get(ReactorControllerBlock.POWERED)) {
|
if (getCachedState().get(ReactorControllerBlock.POWERED)) {
|
||||||
Reactor reactor = getReactor();
|
Reactor reactor = getReactor();
|
||||||
if (reactor != null && !reactor.core.isReacting()) {
|
if (reactor != null && !reactor.core.isReacting()) {
|
||||||
@ -62,7 +63,6 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setEnergy(getDisplayEnergy());
|
setEnergy(getDisplayEnergy());
|
||||||
super.serverTick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,6 +36,12 @@ public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProv
|
|||||||
scheduledTicks.clear();
|
scheduledTicks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void schedule() {
|
||||||
|
if (!scheduledTicks.contains(this)) {
|
||||||
|
scheduledTicks.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public EnergyProviderBlockEntity(BlockEntityType<?> type) {
|
public EnergyProviderBlockEntity(BlockEntityType<?> type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -95,7 +101,11 @@ public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProv
|
|||||||
private final List<Action.PropagatedAction> completedActions = new ArrayList<>();
|
private final List<Action.PropagatedAction> completedActions = new ArrayList<>();
|
||||||
|
|
||||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
||||||
|
if (!isEnergyProvider()) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
} else {
|
||||||
|
schedule();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tickPropagatedActions() {
|
private void tickPropagatedActions() {
|
||||||
@ -116,7 +126,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProv
|
|||||||
@Override
|
@Override
|
||||||
public final void tick() {
|
public final void tick() {
|
||||||
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient()) {
|
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient()) {
|
||||||
scheduledTicks.add(this);
|
schedule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,43 +10,18 @@ import net.minecraft.nbt.IntArrayTag;
|
|||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Tickable;
|
import net.minecraft.util.Tickable;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntity implements Tickable {
|
public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntity implements Tickable {
|
||||||
private class SelfProvider implements EnergyProvider {
|
|
||||||
@Override
|
|
||||||
public void addPropagatedAction(Action.PropagatedAction action) {
|
|
||||||
action.pay(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNetwork(int network) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWithinDistance(Vec3d pos) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RegistryKey<World> getRegistryKey() {
|
|
||||||
return Objects.requireNonNull(getWorld()).getRegistryKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyReceiverBlockEntity(BlockEntityType<?> type) {
|
public EnergyReceiverBlockEntity(BlockEntityType<?> type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final List<Action.PropagatedAction> pendingPropagatedActions = new ArrayList<>();
|
||||||
private final List<Action.PropagatedAction> pendingActions = new ArrayList<>();
|
private final List<Action.PropagatedAction> pendingActions = new ArrayList<>();
|
||||||
private final EnergyProvider selfProvider = new SelfProvider();
|
|
||||||
private final List<EnergyProvider> providers = new ArrayList<>();
|
private final List<EnergyProvider> providers = new ArrayList<>();
|
||||||
private final List<Integer> networks = new ArrayList<>();
|
private final List<Integer> networks = new ArrayList<>();
|
||||||
|
|
||||||
@ -63,13 +38,13 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serverTick() {
|
public void serverTick() {
|
||||||
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient()) {
|
super.serverTick();
|
||||||
|
|
||||||
ServerWorld world = (ServerWorld) getWorld();
|
ServerWorld world = (ServerWorld) getWorld();
|
||||||
|
assert world != null;
|
||||||
NetworkComponent component = NetworkComponent.getInstance(world);
|
NetworkComponent component = NetworkComponent.getInstance(world);
|
||||||
|
|
||||||
providers.clear();
|
providers.clear();
|
||||||
// At Least One Energy Provider Is Always Required
|
|
||||||
providers.add(selfProvider);
|
|
||||||
for (int network : networks) {
|
for (int network : networks) {
|
||||||
List<EnergyProvider> potentialProviders = component.getSource(world, network);
|
List<EnergyProvider> potentialProviders = component.getSource(world, network);
|
||||||
for (EnergyProvider provider : potentialProviders) {
|
for (EnergyProvider provider : potentialProviders) {
|
||||||
@ -86,13 +61,19 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
pendingActions.clear();
|
pendingActions.clear();
|
||||||
tickEnergy();
|
tickEnergy();
|
||||||
|
|
||||||
super.serverTick();
|
for (Action.PropagatedAction action : pendingPropagatedActions) {
|
||||||
|
propagateAction(action);
|
||||||
|
}
|
||||||
|
pendingPropagatedActions.clear();
|
||||||
|
|
||||||
for (Action.PropagatedAction action : pendingActions) {
|
for (Action.PropagatedAction action : pendingActions) {
|
||||||
|
if (providers.size() > 0) {
|
||||||
action.expandPayments(providers.size());
|
action.expandPayments(providers.size());
|
||||||
for (EnergyProvider provider : providers) {
|
for (EnergyProvider provider : providers) {
|
||||||
provider.addPropagatedAction(action);
|
provider.addPropagatedAction(action);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
action.pay(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,9 +84,10 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
||||||
|
super.handlePropagatedAction(action);
|
||||||
// Propagate Action To Energy Providers
|
// Propagate Action To Energy Providers
|
||||||
if (isEnergyProviderActive()) {
|
if (isEnergyProviderActive()) {
|
||||||
propagateAction(action);
|
pendingPropagatedActions.add(action);
|
||||||
} else {
|
} else {
|
||||||
action.pay(0);
|
action.pay(0);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
||||||
|
super.handlePropagatedAction(action);
|
||||||
handlePropagatedActionWithGenerator(action);
|
handlePropagatedActionWithGenerator(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user