Skip to content

Commit

Permalink
use nbt keys and put move back
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Feb 28, 2024
1 parent a698280 commit bfe1fcd
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 146 deletions.
1 change: 1 addition & 0 deletions src/core/java/com/enderio/core/CoreNBTKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CoreNBTKeys {
public static final String ITEMS = "Items";
public static final String FLUID = "Fluid";
public static final String FLUIDS = "Fluids";
public static final String TANKS = "Tanks";
public static final String ENERGY = "Energy";
public static final String BLOCK_ENTITY_TAG = BlockItem.BLOCK_ENTITY_TAG;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.enderio.machines.common.init.MachineAttachments;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.io.FixedIOConfig;
import com.enderio.machines.common.io.TransferUtil;
import com.enderio.machines.common.io.fluid.MachineFluidHandler;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
import com.enderio.machines.common.io.fluid.MachineTankLayout;
Expand All @@ -24,7 +23,6 @@
import com.enderio.machines.common.menu.DrainMenu;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
Expand All @@ -35,7 +33,6 @@
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
Expand Down Expand Up @@ -253,23 +250,4 @@ public void load(CompoundTag pTag) {
consumed = pTag.getInt(CONSUMED);
loadTank(pTag);
}

/**
* Move fluids to and fro via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

@Override
public void moveResource(Direction direction) {
super.moveResource(direction);
moveFluids(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.enderio.machines.common.blockentity.base.MachineBlockEntity;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.init.MachineRecipes;
import com.enderio.machines.common.io.TransferUtil;
import com.enderio.machines.common.io.fluid.IFluidItemInteractive;
import com.enderio.machines.common.io.fluid.MachineFluidHandler;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
Expand All @@ -18,7 +17,6 @@
import com.enderio.machines.common.menu.FluidTankMenu;
import com.enderio.machines.common.recipe.TankRecipe;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -371,23 +369,4 @@ public void load(CompoundTag pTag) {
}

// endregion

/**
* Move fluids to and fro via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

@Override
public void moveResource(Direction direction) {
super.moveResource(direction);
moveFluids(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.enderio.machines.common.config.MachinesConfig;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.init.MachineRecipes;
import com.enderio.machines.common.io.TransferUtil;
import com.enderio.machines.common.io.fluid.MachineFluidHandler;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
import com.enderio.machines.common.io.fluid.MachineTankLayout;
Expand All @@ -28,7 +27,6 @@
import com.enderio.machines.common.recipe.RecipeCaches;
import com.enderio.machines.common.recipe.SoulBindingRecipe;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
Expand All @@ -39,7 +37,6 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.fml.LogicalSide;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -228,23 +225,4 @@ public void load(CompoundTag pTag) {
}

// endregion

/**
* Move fluids to and fro via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

@Override
public void moveResource(Direction direction) {
super.moveResource(direction);
moveFluids(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity;
import com.enderio.machines.common.config.MachinesConfig;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.io.TransferUtil;
import com.enderio.machines.common.io.energy.MachineEnergyStorage;
import com.enderio.machines.common.io.fluid.MachineFluidHandler;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
Expand All @@ -23,7 +22,6 @@
import com.enderio.machines.common.menu.SoulEngineMenu;
import com.enderio.machines.common.souldata.EngineSoul;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand All @@ -40,7 +38,6 @@
import net.minecraft.world.level.material.Fluids;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.client.event.RecipesUpdatedEvent;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.FluidType;
Expand Down Expand Up @@ -257,23 +254,4 @@ public void setLevel(Level level) {
static void onReload(RecipesUpdatedEvent event) {
reload = !reload;
}

/**
* Move fluids to and fro via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

@Override
public void moveResource(Direction direction) {
super.moveResource(direction);
moveFluids(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
import com.enderio.machines.common.attachment.IFluidTankUser;
import com.enderio.machines.common.blockentity.base.MachineBlockEntity;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.io.TransferUtil;
import com.enderio.machines.common.io.fluid.MachineFluidHandler;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
import com.enderio.machines.common.io.fluid.MachineTankLayout;
import com.enderio.machines.common.io.fluid.TankAccess;
import com.enderio.machines.common.menu.XPObeliskMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -139,23 +136,4 @@ public void load(CompoundTag pTag) {
}

// endregion

/**
* Move fluids to and fro via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

@Override
public void moveResource(Direction direction) {
super.moveResource(direction);
moveFluids(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
import com.enderio.machines.common.blockentity.base.VacuumMachineBlockEntity;
import com.enderio.machines.common.config.MachinesConfig;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.io.TransferUtil;
import com.enderio.machines.common.io.fluid.MachineFluidHandler;
import com.enderio.machines.common.io.fluid.MachineFluidTank;
import com.enderio.machines.common.io.fluid.MachineTankLayout;
import com.enderio.machines.common.io.fluid.TankAccess;
import com.enderio.machines.common.menu.XPVacuumMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction;

import static com.enderio.base.common.util.ExperienceUtil.EXP_TO_FLUID;
Expand Down Expand Up @@ -105,23 +101,4 @@ public void load(CompoundTag pTag) {
}

// endregion

/**
* Move fluids to and fro via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

@Override
public void moveResource(Direction direction) {
super.moveResource(direction);
moveFluids(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.client.model.data.ModelData;
import net.neoforged.neoforge.client.model.data.ModelProperty;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -338,17 +339,14 @@ private void forceResources() {
for (Direction direction : Direction.values()) {
if (ioConfig.getMode(direction).canForce()) {
// TODO: Maybe some kind of resource distributor so that items are transmitted evenly around? rather than taking the order of Direction.values()
moveResource(direction);
moveItems(direction);
moveFluids(direction);
}
}
}

public void moveResource(Direction direction) {
moveItems(direction);
}

/**
* Move items to and fro via the given side.
* Move items to and from via the given side.
*/
private void moveItems(Direction side) {
IItemHandler selfHandler = getSelfCapability(Capabilities.ItemHandler.BLOCK, side);
Expand All @@ -360,6 +358,19 @@ private void moveItems(Direction side) {
TransferUtil.distributeItems(ioConfig.getMode(side), selfHandler, otherHandler);
}

/**
* Move fluids to and from via the given side.
*/
private void moveFluids(Direction side) {
IFluidHandler selfHandler = getSelfCapability(Capabilities.FluidHandler.BLOCK, side);
IFluidHandler otherHandler = getNeighbouringCapability(Capabilities.FluidHandler.BLOCK, side);
if (selfHandler == null || otherHandler == null) {
return;
}

TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler);
}

// endregion

// region Serialization
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.enderio.machines.common.io.fluid;

import com.enderio.api.io.IIOConfig;
import com.enderio.core.CoreNBTKeys;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -11,7 +12,6 @@
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -23,7 +23,6 @@
public class MachineFluidHandler implements IFluidHandler, INBTSerializable<CompoundTag> {

public static final String TANK_INDEX = "Index";
public static final String TANKS = "Tanks";
private final IIOConfig config;
private final MachineTankLayout layout;
private Map<Integer, MachineFluidTank> tanks = new HashMap<>();
Expand Down Expand Up @@ -219,13 +218,13 @@ public CompoundTag serializeNBT() {
nbtTagList.add(tankTag);
}
CompoundTag nbt = new CompoundTag();
nbt.put(TANKS, nbtTagList);
nbt.put(CoreNBTKeys.TANKS, nbtTagList);
return nbt;
}

@Override
public void deserializeNBT(CompoundTag nbt) {
ListTag tagList = nbt.getList(TANKS, Tag.TAG_COMPOUND);
ListTag tagList = nbt.getList(CoreNBTKeys.TANKS, Tag.TAG_COMPOUND);
for (int i = 0; i < tagList.size(); i++) {
CompoundTag tankTag = tagList.getCompound(i);
int index = tankTag.getInt(TANK_INDEX);
Expand Down
Loading

0 comments on commit bfe1fcd

Please sign in to comment.