Remove Workaround To Fixed Bug
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-07-24 14:02:42 -04:00
parent a86581d913
commit 94a4364826
7 changed files with 13 additions and 55 deletions

View File

@ -1,6 +1,5 @@
package com.thebrokenrail.energonrelics.block.entity; package com.thebrokenrail.energonrelics.block.entity;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.BlockBreakerBlock; import com.thebrokenrail.energonrelics.block.BlockBreakerBlock;
import com.thebrokenrail.energonrelics.config.HardcodedConfig; import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity; import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
@ -10,7 +9,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.explosion.Explosion; import net.minecraft.world.explosion.Explosion;
@ -42,7 +40,7 @@ public class BlockBreakerBlockEntity extends EnergyReceiverBlockEntity {
@Override @Override
protected void tickEnergy() { protected void tickEnergy() {
addAction(Action.createBlockStatePropertyAction(HardcodedConfig.BLOCK_BREAKER_ENERGY_REQUIRED_IDLE, BlockBreakerBlock.POWERED, true, false, new Identifier(EnergonRelics.NAMESPACE, "block_breaker_idle"))); addAction(Action.createBlockStatePropertyAction(HardcodedConfig.BLOCK_BREAKER_ENERGY_REQUIRED_IDLE, BlockBreakerBlock.POWERED, true, false));
if (getCachedState().get(BlockBreakerBlock.POWERED)) { if (getCachedState().get(BlockBreakerBlock.POWERED)) {
BlockPos targetPos = getPos().offset(getCachedState().get(BlockBreakerBlock.FACING)); BlockPos targetPos = getPos().offset(getCachedState().get(BlockBreakerBlock.FACING));
@ -55,7 +53,7 @@ public class BlockBreakerBlockEntity extends EnergyReceiverBlockEntity {
Block.dropStacks(target, world, targetPos, target.getBlock().hasBlockEntity() ? world.getBlockEntity(targetPos) : null, null, new ItemStack(HardcodedConfig.BLOCK_BREAKER_ITEM)); Block.dropStacks(target, world, targetPos, target.getBlock().hasBlockEntity() ? world.getBlockEntity(targetPos) : null, null, new ItemStack(HardcodedConfig.BLOCK_BREAKER_ITEM));
world.breakBlock(targetPos, false); world.breakBlock(targetPos, false);
progress = 0; progress = 0;
}, (world, pos, state) -> progress = 0, new Identifier(EnergonRelics.NAMESPACE, "block_breaker_break"))); }, (world, pos, state) -> progress = 0));
} }
progress++; progress++;

View File

@ -16,7 +16,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
@ -225,7 +224,7 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
@Override @Override
protected void tickEnergy() { protected void tickEnergy() {
assert getWorld() != null; assert getWorld() != null;
addAction(Action.createBlockStatePropertyAction(HardcodedConfig.DEFENSIVE_LASER_IDLE_ENERGY_REQUIRED, DefensiveLaserBlock.POWERED, true, false, new Identifier(EnergonRelics.NAMESPACE, "defensive_laser_idle"))); addAction(Action.createBlockStatePropertyAction(HardcodedConfig.DEFENSIVE_LASER_IDLE_ENERGY_REQUIRED, DefensiveLaserBlock.POWERED, true, false));
if (getCachedState().get(DefensiveLaserBlock.POWERED)) { if (getCachedState().get(DefensiveLaserBlock.POWERED)) {
if (countdown > 0) { if (countdown > 0) {
countdown--; countdown--;
@ -234,7 +233,7 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
addAction(new Action(HardcodedConfig.DEFENSIVE_LASER_FIRE_ENERGY_REQUIRED, (world, pos, state) -> { addAction(new Action(HardcodedConfig.DEFENSIVE_LASER_FIRE_ENERGY_REQUIRED, (world, pos, state) -> {
firing = false; firing = false;
fire(world, pos); fire(world, pos);
}, (world, pos, state) -> firing = false, new Identifier(EnergonRelics.NAMESPACE, "defensive_laser_fire"))); }, (world, pos, state) -> firing = false));
target = null; target = null;
firing = true; firing = true;
} else if (countdown < 1 && !firing) { } else if (countdown < 1 && !firing) {

View File

@ -1,12 +1,10 @@
package com.thebrokenrail.energonrelics.block.entity; package com.thebrokenrail.energonrelics.block.entity;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.config.HardcodedConfig; import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import com.thebrokenrail.energonrelics.block.EnergonLightBlock; import com.thebrokenrail.energonrelics.block.EnergonLightBlock;
import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity; import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.energy.core.util.Action; import com.thebrokenrail.energonrelics.energy.core.util.Action;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.Identifier;
public class EnergonLightBlockEntity extends EnergyReceiverBlockEntity { public class EnergonLightBlockEntity extends EnergyReceiverBlockEntity {
public EnergonLightBlockEntity(BlockEntityType<?> type) { public EnergonLightBlockEntity(BlockEntityType<?> type) {
@ -15,6 +13,6 @@ public class EnergonLightBlockEntity extends EnergyReceiverBlockEntity {
@Override @Override
protected void tickEnergy() { protected void tickEnergy() {
addAction(Action.createBlockStatePropertyAction(HardcodedConfig.ENERGON_LIGHT_ENERGY_REQUIRED, EnergonLightBlock.POWERED, true, false, new Identifier(EnergonRelics.NAMESPACE, "energon_light"))); addAction(Action.createBlockStatePropertyAction(HardcodedConfig.ENERGON_LIGHT_ENERGY_REQUIRED, EnergonLightBlock.POWERED, true, false));
} }
} }

View File

@ -9,7 +9,6 @@ import com.thebrokenrail.energonrelics.energy.helper.EnergyGenerator;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -19,12 +18,11 @@ public class PassiveBatteryControllerBlockEntity extends EnergyReceiverBlockEnti
super(type); super(type);
} }
private static class UnlimitedAction extends Action.UniqueAction implements Action.PropagatedAction { private static class UnlimitedAction implements Action.PropagatedAction {
private final World world; private final World world;
private final BlockPos pos; private final BlockPos pos;
private UnlimitedAction(World world, BlockPos pos) { private UnlimitedAction(World world, BlockPos pos) {
super(new Identifier(EnergonRelics.NAMESPACE, "active_battery_controller"), pos);
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;
} }
@ -58,7 +56,7 @@ public class PassiveBatteryControllerBlockEntity extends EnergyReceiverBlockEnti
PassiveBatteryControllerBlockEntity battery = (PassiveBatteryControllerBlockEntity) entity; PassiveBatteryControllerBlockEntity battery = (PassiveBatteryControllerBlockEntity) entity;
battery.setEnergy(battery.getEnergy() + charge); battery.setEnergy(battery.getEnergy() + charge);
} }
}, (world, pos, state) -> {}, new Identifier(EnergonRelics.NAMESPACE, "passive_battery_controller"))); }, (world, pos, state) -> {}));
} else { } else {
propagateAction(new UnlimitedAction(getWorld(), getPos())); propagateAction(new UnlimitedAction(getWorld(), getPos()));
} }

View File

@ -8,7 +8,6 @@ import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.energy.core.util.Action; import com.thebrokenrail.energonrelics.energy.core.util.Action;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -21,7 +20,7 @@ public class ForcefieldProjectorBlockEntity extends EnergyReceiverBlockEntity {
protected void tickEnergy() { protected void tickEnergy() {
assert getWorld() != null; assert getWorld() != null;
addAction(Action.createBlockStatePropertyAction(HardcodedConfig.FORCEFIELD_PROJECTOR_ENERGY_REQUIRED, ForcefieldProjectorBlock.POWERED, true, false, new Identifier(EnergonRelics.NAMESPACE, "forcefield_projector"))); addAction(Action.createBlockStatePropertyAction(HardcodedConfig.FORCEFIELD_PROJECTOR_ENERGY_REQUIRED, ForcefieldProjectorBlock.POWERED, true, false));
if (getCachedState().get(ForcefieldProjectorBlock.POWERED)) { if (getCachedState().get(ForcefieldProjectorBlock.POWERED)) {
Direction facing = getCachedState().get(ForcefieldProjectorBlock.FACING); Direction facing = getCachedState().get(ForcefieldProjectorBlock.FACING);
BlockState state = EnergonRelics.FORCEFIELD_BLOCK.getDefaultState().with(ForcefieldBlock.FACING, facing); BlockState state = EnergonRelics.FORCEFIELD_BLOCK.getDefaultState().with(ForcefieldBlock.FACING, facing);

View File

@ -20,7 +20,6 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -32,10 +31,7 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
public final void addPropagatedAction(Action.PropagatedAction action) { public final void addPropagatedAction(Action.PropagatedAction action) {
if (isEnergyProvider()) { if (isEnergyProvider()) {
if (!completedActions.contains(action)) { handlePropagatedAction(action);
handlePropagatedAction(action);
completedActions.add(action);
}
} else { } else {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -78,8 +74,6 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
return false; return false;
} }
private final List<Action.PropagatedAction> completedActions = new ArrayList<>();
protected void handlePropagatedAction(Action.PropagatedAction action) { protected void handlePropagatedAction(Action.PropagatedAction action) {
if (!isEnergyProvider()) { if (!isEnergyProvider()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
@ -90,7 +84,6 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
} }
public List<EnergyProviderBlockEntity> startTick() { public List<EnergyProviderBlockEntity> startTick() {
completedActions.clear();
if (isEnergyProvider()) { if (isEnergyProvider()) {
NetworkComponent component = NetworkComponent.getInstance((ServerWorld) Objects.requireNonNull(getWorld())); NetworkComponent component = NetworkComponent.getInstance((ServerWorld) Objects.requireNonNull(getWorld()));
List<BlockPosWithDimension> sources = component.getSourcePos(EnergonRelics.NETWORK_CHIP_ITEM.getID(stack)); List<BlockPosWithDimension> sources = component.getSourcePos(EnergonRelics.NETWORK_CHIP_ITEM.getID(stack));

View File

@ -3,12 +3,9 @@ package com.thebrokenrail.energonrelics.energy.core.util;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.state.property.Property; import net.minecraft.state.property.Property;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.Objects;
public class Action { public class Action {
public interface ActionFunction { public interface ActionFunction {
void run(World world, BlockPos pos, BlockState state); void run(World world, BlockPos pos, BlockState state);
@ -17,16 +14,14 @@ public class Action {
private final long cost; private final long cost;
private final ActionFunction success; private final ActionFunction success;
private final ActionFunction fail; private final ActionFunction fail;
private final Identifier id;
public Action(long cost, ActionFunction success, ActionFunction fail, Identifier id) { public Action(long cost, ActionFunction success, ActionFunction fail) {
this.cost = cost; this.cost = cost;
this.success = success; this.success = success;
this.fail = fail; this.fail = fail;
this.id = id;
} }
public static <T extends Comparable<T>> Action createBlockStatePropertyAction(long cost, Property<T> property, T successValue, T failureValue, Identifier id) { public static <T extends Comparable<T>> Action createBlockStatePropertyAction(long cost, Property<T> property, T successValue, T failureValue) {
return new Action(cost, (world, pos, state) -> { return new Action(cost, (world, pos, state) -> {
if (!state.get(property).equals(successValue)) { if (!state.get(property).equals(successValue)) {
world.setBlockState(pos, state.with(property, successValue)); world.setBlockState(pos, state.with(property, successValue));
@ -35,7 +30,7 @@ public class Action {
if (!state.get(property).equals(failureValue)) { if (!state.get(property).equals(failureValue)) {
world.setBlockState(pos, state.with(property, failureValue)); world.setBlockState(pos, state.with(property, failureValue));
} }
}, id); });
} }
public interface PropagatedAction { public interface PropagatedAction {
@ -44,28 +39,7 @@ public class Action {
void pay(long amount); void pay(long amount);
} }
public static class UniqueAction { public static class PropagatedActionImpl implements PropagatedAction {
private final Identifier id;
private final BlockPos pos;
public UniqueAction(Identifier id, BlockPos pos) {
this.id = id;
this.pos = pos;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof UniqueAction) {
return Objects.equals(id, ((UniqueAction) obj).id) && Objects.equals(pos, ((UniqueAction) obj).pos);
} else {
return false;
}
}
}
public static class PropagatedActionImpl extends UniqueAction implements PropagatedAction {
private final Action action; private final Action action;
private final World world; private final World world;
private final BlockPos pos; private final BlockPos pos;
@ -75,7 +49,6 @@ public class Action {
private long amountPaid = 0; private long amountPaid = 0;
public PropagatedActionImpl(Action action, World world, BlockPos pos, Block block) { public PropagatedActionImpl(Action action, World world, BlockPos pos, Block block) {
super(action.id, pos);
this.action = action; this.action = action;
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;