Fix controller not persisting energy across drops
This commit is contained in:
@@ -35,6 +35,7 @@ import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
|
|||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
@@ -82,7 +83,13 @@ public class Network implements INetwork, IRedstoneConfigurable {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.root = new RootNetworkNode(this, world, pos);
|
this.root = new RootNetworkNode(this, world, pos);
|
||||||
this.nodeGraph.addListener(() -> ((ControllerTile) world.getTileEntity(pos)).getDataManager().sendParameterToWatchers(ControllerTile.NODES));
|
this.nodeGraph.addListener(() -> {
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof ControllerTile) {
|
||||||
|
((ControllerTile) tile).getDataManager().sendParameterToWatchers(ControllerTile.NODES);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public RootNetworkNode getRoot() {
|
public RootNetworkNode getRoot() {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.loottable;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.ControllerTile;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.storage.loot.LootContext;
|
||||||
|
import net.minecraft.world.storage.loot.LootParameters;
|
||||||
|
import net.minecraft.world.storage.loot.functions.ILootFunction;
|
||||||
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
|
|
||||||
|
public class ControllerLootFunction implements ILootFunction {
|
||||||
|
@Override
|
||||||
|
public ItemStack apply(ItemStack itemStack, LootContext lootContext) {
|
||||||
|
TileEntity tile = lootContext.get(LootParameters.BLOCK_ENTITY);
|
||||||
|
|
||||||
|
if (tile instanceof ControllerTile) {
|
||||||
|
INetwork network = ((ControllerTile) tile).getRemovedNetwork() == null ? ((ControllerTile) tile).getNetwork() : ((ControllerTile) tile).getRemovedNetwork();
|
||||||
|
|
||||||
|
itemStack.getCapability(CapabilityEnergy.ENERGY).ifPresent(energy -> energy.receiveEnergy(network.getEnergyStorage().getEnergyStored(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.raoulvdberge.refinedstorage.loottable;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.world.storage.loot.functions.ILootFunction;
|
||||||
|
|
||||||
|
public class ControllerLootFunctionSerializer extends ILootFunction.Serializer<ControllerLootFunction> {
|
||||||
|
public ControllerLootFunctionSerializer() {
|
||||||
|
super(new ResourceLocation(RS.ID, "controller"), ControllerLootFunction.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(JsonObject jsonObject, ControllerLootFunction controllerLootFunction, JsonSerializationContext jsonSerializationContext) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ControllerLootFunction deserialize(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
|
||||||
|
return new ControllerLootFunction();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ import com.raoulvdberge.refinedstorage.container.*;
|
|||||||
import com.raoulvdberge.refinedstorage.container.factory.*;
|
import com.raoulvdberge.refinedstorage.container.factory.*;
|
||||||
import com.raoulvdberge.refinedstorage.item.*;
|
import com.raoulvdberge.refinedstorage.item.*;
|
||||||
import com.raoulvdberge.refinedstorage.item.blockitem.*;
|
import com.raoulvdberge.refinedstorage.item.blockitem.*;
|
||||||
|
import com.raoulvdberge.refinedstorage.loottable.ControllerLootFunctionSerializer;
|
||||||
import com.raoulvdberge.refinedstorage.loottable.CrafterLootFunctionSerializer;
|
import com.raoulvdberge.refinedstorage.loottable.CrafterLootFunctionSerializer;
|
||||||
import com.raoulvdberge.refinedstorage.loottable.PortableGridBlockLootFunctionSerializer;
|
import com.raoulvdberge.refinedstorage.loottable.PortableGridBlockLootFunctionSerializer;
|
||||||
import com.raoulvdberge.refinedstorage.loottable.StorageBlockLootFunctionSerializer;
|
import com.raoulvdberge.refinedstorage.loottable.StorageBlockLootFunctionSerializer;
|
||||||
@@ -132,6 +133,7 @@ public class CommonSetup {
|
|||||||
LootFunctionManager.registerFunction(new StorageBlockLootFunctionSerializer());
|
LootFunctionManager.registerFunction(new StorageBlockLootFunctionSerializer());
|
||||||
LootFunctionManager.registerFunction(new PortableGridBlockLootFunctionSerializer());
|
LootFunctionManager.registerFunction(new PortableGridBlockLootFunctionSerializer());
|
||||||
LootFunctionManager.registerFunction(new CrafterLootFunctionSerializer());
|
LootFunctionManager.registerFunction(new CrafterLootFunctionSerializer());
|
||||||
|
LootFunctionManager.registerFunction(new ControllerLootFunctionSerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private INetworkNode readAndReturn(CompoundNBT tag, NetworkNode node) {
|
private INetworkNode readAndReturn(CompoundNBT tag, NetworkNode node) {
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ public class ControllerTile extends BaseTile implements INetworkNodeProxy<RootNe
|
|||||||
private final LazyOptional<INetworkNodeProxy<RootNetworkNode>> networkNodeProxyCap = LazyOptional.of(() -> this);
|
private final LazyOptional<INetworkNodeProxy<RootNetworkNode>> networkNodeProxyCap = LazyOptional.of(() -> this);
|
||||||
|
|
||||||
private final NetworkType type;
|
private final NetworkType type;
|
||||||
|
|
||||||
|
private INetwork removedNetwork;
|
||||||
|
|
||||||
private Network dummyNetwork;
|
private Network dummyNetwork;
|
||||||
|
|
||||||
public ControllerTile(NetworkType type) {
|
public ControllerTile(NetworkType type) {
|
||||||
@@ -117,6 +120,8 @@ public class ControllerTile extends BaseTile implements INetworkNodeProxy<RootNe
|
|||||||
|
|
||||||
INetwork network = manager.getNetwork(pos);
|
INetwork network = manager.getNetwork(pos);
|
||||||
|
|
||||||
|
removedNetwork = network;
|
||||||
|
|
||||||
manager.removeNetwork(pos);
|
manager.removeNetwork(pos);
|
||||||
manager.markForSaving();
|
manager.markForSaving();
|
||||||
|
|
||||||
@@ -124,6 +129,10 @@ public class ControllerTile extends BaseTile implements INetworkNodeProxy<RootNe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public INetwork getRemovedNetwork() {
|
||||||
|
return removedNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public RootNetworkNode getNode() {
|
public RootNetworkNode getNode() {
|
||||||
|
|||||||
@@ -9,24 +9,7 @@
|
|||||||
"name": "refinedstorage:controller",
|
"name": "refinedstorage:controller",
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"function": "minecraft:copy_nbt",
|
"function": "refinedstorage:controller"
|
||||||
"source": "block_entity",
|
|
||||||
"ops": [
|
|
||||||
{
|
|
||||||
"source": "Energy",
|
|
||||||
"target": "Energy",
|
|
||||||
"op": "replace"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"function": "minecraft:set_contents",
|
|
||||||
"entries": [
|
|
||||||
{
|
|
||||||
"type": "minecraft:dynamic",
|
|
||||||
"name": "minecraft:contents"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:block",
|
||||||
|
"pools": [
|
||||||
|
{
|
||||||
|
"rolls": 1,
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"type": "minecraft:item",
|
||||||
|
"name": "refinedstorage:creative_controller"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"conditions": [
|
||||||
|
{
|
||||||
|
"condition": "minecraft:survives_explosion"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user