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

Improve Documentation
This commit is contained in:
TheBrokenRail 2020-08-03 16:36:20 -04:00
parent 66a64a31ad
commit 77e332404e
6 changed files with 24 additions and 23 deletions

View File

@ -12,7 +12,7 @@
An Energy Provider provides energy to the Energy Receivers in its network. An Energy Provider can also be an Energy Receiver. An Energy Provider can only provide energy to an Energy provider that is in the same dimension and is at most 64 blocks away. An Energy Provider provides energy to the Energy Receivers in its network. An Energy Provider can also be an Energy Receiver. An Energy Provider can only provide energy to an Energy provider that is in the same dimension and is at most 64 blocks away.
## Network Chip ## Network Chip
The Network Chip is used to create and manipulate networks. To add an Energy Receiver to a network, right-click it with the network's Network Chip. To add an Energy Provider to a network, right-click it with the Network Chip, the Network Chip will be removed from your inventory. If a block is both an Energy Receiver and an Energy Provider, shift-right-click it to add it as an Energy Receiver to the network, and right-click it to add it as an Energy Provider to the network. To duplicate a Network Chip combine it with a [Circuit Board](ITEMS.md#user-content-circuit-board) in a crafting area. The Network Chip is used to create and manipulate networks. To add an Energy Receiver to a network, use it with the Network Chip. To add an Energy Provider to a network, use it with the Network Chip, the Network Chip will be removed from your inventory. If a block is both an Energy Receiver and an Energy Provider, use it while sneaking to add it as an Energy Receiver to the network, and use it to add it as an Energy Provider to the network. To duplicate a Network Chip combine it with a [Circuit Board](ITEMS.md#user-content-circuit-board) in a crafting area.
## Switch ## Switch
The Switch block is used to selectively activate different devices. It is an Energy Provider and an Energy Receiver. If it is receiving a Redstone signal it will propagate all the Energy Receivers in its sub-network to the Energy Providers in its main-network. The Switch block is used to selectively activate different devices. It is an Energy Provider and an Energy Receiver. If it is receiving a Redstone signal it will propagate all the Energy Receivers in its sub-network to the Energy Providers in its main-network.

View File

@ -3,6 +3,7 @@ package com.thebrokenrail.energonrelics.block.battery;
import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.entity.battery.BatteryCoreBlockEntity; import com.thebrokenrail.energonrelics.block.entity.battery.BatteryCoreBlockEntity;
import com.thebrokenrail.energonrelics.block.util.SimpleBlockWithEntity; import com.thebrokenrail.energonrelics.block.util.SimpleBlockWithEntity;
import com.thebrokenrail.energonrelics.item.MultimeterItem;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -15,7 +16,6 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.item.TooltipContext; import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@ -40,7 +40,7 @@ public class BatteryCoreBlock extends SimpleBlockWithEntity {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, BlockView world, List<Text> tooltip, TooltipContext options) { public void appendTooltip(ItemStack stack, BlockView world, List<Text> tooltip, TooltipContext options) {
super.appendTooltip(stack, world, tooltip, options); super.appendTooltip(stack, world, tooltip, options);
tooltip.add(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".battery_core_tooltip", new LiteralText(String.valueOf(stack.getOrCreateTag().getCompound("BlockEntityTag").getInt("Energy")))).formatted(Formatting.GRAY)); tooltip.add(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".battery_core_tooltip", MultimeterItem.format(stack.getOrCreateTag().getCompound("BlockEntityTag").getLong("Energy")).formatted(Formatting.GRAY)).formatted(Formatting.GRAY));
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package com.thebrokenrail.energonrelics.block.entity;
import com.thebrokenrail.energonrelics.block.SwitchBlock; import com.thebrokenrail.energonrelics.block.SwitchBlock;
import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity; import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.energy.core.util.Action;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
public class SwitchBlockEntity extends EnergyReceiverBlockEntity { public class SwitchBlockEntity extends EnergyReceiverBlockEntity {
@ -19,7 +20,17 @@ public class SwitchBlockEntity extends EnergyReceiverBlockEntity {
} }
@Override @Override
protected boolean isEnergyProviderActive() { protected void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
// Propagate Action To Energy Providers
if (isActive() && !hasSent(action)) {
propagateAction(action);
} else {
action.pay(0);
}
}
private boolean isActive() {
return getCachedState().get(SwitchBlock.POWERED); return getCachedState().get(SwitchBlock.POWERED);
} }
} }

View File

@ -27,6 +27,10 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
private final List<Action.PropagatedAction> sent = new ArrayList<>(); private final List<Action.PropagatedAction> sent = new ArrayList<>();
protected boolean hasSent(Action.PropagatedAction action) {
return sent.contains(action);
}
protected void propagateAction(Action.PropagatedAction action) { protected void propagateAction(Action.PropagatedAction action) {
sent.add(action); sent.add(action);
@ -89,17 +93,6 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
return previousTotalCost; return previousTotalCost;
} }
@Override
protected void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
// Propagate Action To Energy Providers
if (isEnergyProviderActive() && !sent.contains(action)) {
propagateAction(action);
} else {
action.pay(0);
}
}
@Override @Override
public CompoundTag toTag(CompoundTag tag) { public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag); super.toTag(tag);
@ -117,10 +110,6 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
} }
} }
protected boolean isEnergyProviderActive() {
throw new UnsupportedOperationException();
}
protected abstract void energyTick(); protected abstract void energyTick();
public void toggle(int network) { public void toggle(int network) {

View File

@ -25,7 +25,7 @@ public class MultimeterItem extends Item {
MutableText getExtra(); MutableText getExtra();
} }
private Text numberToText(long value) { public static MutableText format(long value) {
String str; String str;
if (value >= Long.MAX_VALUE) { if (value >= Long.MAX_VALUE) {
str = "\u221e"; str = "\u221e";
@ -46,7 +46,7 @@ public class MultimeterItem extends Item {
Text separator = new TranslatableText("text." + EnergonRelics.NAMESPACE + ".multimeter_separator").formatted(Formatting.YELLOW); Text separator = new TranslatableText("text." + EnergonRelics.NAMESPACE + ".multimeter_separator").formatted(Formatting.YELLOW);
if (entity instanceof EnergyGenerator) { if (entity instanceof EnergyGenerator) {
if (!world.isClient() && context.getPlayer() != null) { if (!world.isClient() && context.getPlayer() != null) {
text.append(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".energy_available", numberToText(((EnergyGenerator) entity).getDisplayEnergy())).formatted(Formatting.YELLOW)); text.append(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".energy_available", format(((EnergyGenerator) entity).getDisplayEnergy())).formatted(Formatting.YELLOW));
} }
success = true; success = true;
} }
@ -55,7 +55,7 @@ public class MultimeterItem extends Item {
if (success) { if (success) {
text.append(separator); text.append(separator);
} }
text.append(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".energy_required", numberToText(((EnergyReceiverBlockEntity) entity).getTotalCost())).formatted(Formatting.YELLOW)); text.append(new TranslatableText("text." + EnergonRelics.NAMESPACE + ".energy_required", format(((EnergyReceiverBlockEntity) entity).getTotalCost())).formatted(Formatting.YELLOW));
} }
success = true; success = true;
} }

View File

@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -71,7 +72,7 @@ public class NetworkChipItem extends Item {
super.appendTooltip(stack, world, tooltip, context); super.appendTooltip(stack, world, tooltip, context);
int id = getID(stack); int id = getID(stack);
if (id != -1) { if (id != -1) {
tooltip.add(new TranslatableText("item." + EnergonRelics.NAMESPACE + ".network_chip.tooltip", String.valueOf(id)).formatted(Formatting.GRAY)); tooltip.add(new TranslatableText("item." + EnergonRelics.NAMESPACE + ".network_chip.tooltip", new LiteralText(String.valueOf(id)).formatted(Formatting.GRAY)).formatted(Formatting.GRAY));
} }
} }