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
protected void serverTick() {
setEnergy(getDisplayEnergy());
super.serverTick();
setEnergy(getDisplayEnergy());
}
}

View File

@ -97,6 +97,7 @@ public class PassiveBatteryControllerBlockEntity extends EnergyReceiverBlockEnti
@Override
protected void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
handlePropagatedActionWithGenerator(action);
}

View File

@ -33,6 +33,7 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
@Override
protected void serverTick() {
super.serverTick();
if (getCachedState().get(ReactorControllerBlock.POWERED)) {
Reactor reactor = getReactor();
if (reactor != null && !reactor.core.isReacting()) {
@ -62,7 +63,6 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
}
}
setEnergy(getDisplayEnergy());
super.serverTick();
}
@Override

View File

@ -36,6 +36,12 @@ public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProv
scheduledTicks.clear();
}
private void schedule() {
if (!scheduledTicks.contains(this)) {
scheduledTicks.add(this);
}
}
public EnergyProviderBlockEntity(BlockEntityType<?> type) {
super(type);
}
@ -95,7 +101,11 @@ public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProv
private final List<Action.PropagatedAction> completedActions = new ArrayList<>();
protected void handlePropagatedAction(Action.PropagatedAction action) {
throw new UnsupportedOperationException();
if (!isEnergyProvider()) {
throw new UnsupportedOperationException();
} else {
schedule();
}
}
private void tickPropagatedActions() {
@ -116,7 +126,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements EnergyProv
@Override
public final void tick() {
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.util.Tickable;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
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) {
super(type);
}
private final List<Action.PropagatedAction> pendingPropagatedActions = 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<Integer> networks = new ArrayList<>();
@ -63,36 +38,42 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
@Override
public void serverTick() {
if (hasWorld() && !Objects.requireNonNull(getWorld()).isClient()) {
ServerWorld world = (ServerWorld) getWorld();
NetworkComponent component = NetworkComponent.getInstance(world);
super.serverTick();
providers.clear();
// At Least One Energy Provider Is Always Required
providers.add(selfProvider);
for (int network : networks) {
List<EnergyProvider> potentialProviders = component.getSource(world, network);
for (EnergyProvider provider : potentialProviders) {
if (provider.getRegistryKey().equals(getWorld().getRegistryKey())) {
Vec3d pos = new Vec3d(getPos().getX() + 0.5d, getPos().getY() + 0.5d, getPos().getZ() + 0.5d);
if (provider.isWithinDistance(pos)) {
providers.add(provider);
}
ServerWorld world = (ServerWorld) getWorld();
assert world != null;
NetworkComponent component = NetworkComponent.getInstance(world);
providers.clear();
for (int network : networks) {
List<EnergyProvider> potentialProviders = component.getSource(world, network);
for (EnergyProvider provider : potentialProviders) {
if (provider.getRegistryKey().equals(getWorld().getRegistryKey())) {
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;
pendingActions.clear();
tickEnergy();
totalCost = 0;
pendingActions.clear();
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());
for (EnergyProvider provider : providers) {
provider.addPropagatedAction(action);
}
} else {
action.pay(0);
}
}
}
@ -103,9 +84,10 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
@Override
protected void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
// Propagate Action To Energy Providers
if (isEnergyProviderActive()) {
propagateAction(action);
pendingPropagatedActions.add(action);
} else {
action.pay(0);
}

View File

@ -28,6 +28,7 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
@Override
protected void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
handlePropagatedActionWithGenerator(action);
}