Fix Bugs
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-07-22 19:51:42 -04:00
parent 40580ec504
commit cc4795c9d3
6 changed files with 44 additions and 50 deletions

View File

@ -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());
} }
} }

View File

@ -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);
} }

View File

@ -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

View File

@ -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) {
throw new UnsupportedOperationException(); if (!isEnergyProvider()) {
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();
} }
} }

View File

@ -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,36 +38,42 @@ 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();
NetworkComponent component = NetworkComponent.getInstance(world);
providers.clear(); ServerWorld world = (ServerWorld) getWorld();
// At Least One Energy Provider Is Always Required assert world != null;
providers.add(selfProvider); NetworkComponent component = NetworkComponent.getInstance(world);
for (int network : networks) {
List<EnergyProvider> potentialProviders = component.getSource(world, network); providers.clear();
for (EnergyProvider provider : potentialProviders) { for (int network : networks) {
if (provider.getRegistryKey().equals(getWorld().getRegistryKey())) { List<EnergyProvider> potentialProviders = component.getSource(world, network);
Vec3d pos = new Vec3d(getPos().getX() + 0.5d, getPos().getY() + 0.5d, getPos().getZ() + 0.5d); for (EnergyProvider provider : potentialProviders) {
if (provider.isWithinDistance(pos)) { if (provider.getRegistryKey().equals(getWorld().getRegistryKey())) {
providers.add(provider); Vec3d pos = new Vec3d(getPos().getX() + 0.5d, getPos().getY() + 0.5d, getPos().getZ() + 0.5d);
} if (provider.isWithinDistance(pos)) {
providers.add(provider);
} }
} }
} }
}
totalCost = 0; totalCost = 0;
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);
} }

View File

@ -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);
} }