Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ dependencies {
implementation(rfg.deobf("curse.maven:thermal-expansion-69163:2926431"))

// AE2 Compat
// implementation(rfg.deobf("curse.maven:applied-energistics-2-223794:2747063"))
// implementation(rfg.deobf("curse.maven:applied-energistics-2-223794:2747063"))
implementation(rfg.deobf("curse.maven:ae2-extended-life-570458:6302098"))
implementation(rfg.deobf("curse.maven:ae2-fluid-crafting-rework-623955:5504001"))
implementation(rfg.deobf("curse.maven:mekanism-energistics-1027681:5408319"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package github.kasuminova.mmce.common.block.appeng;

import appeng.api.implementations.items.IMemoryCard;
import github.kasuminova.mmce.common.tile.MEFluidInputBus;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.CommonProxy;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
Expand All @@ -20,7 +22,15 @@ public class BlockMEFluidInputBus extends BlockMEFluidBus {
public boolean onBlockActivated(@Nonnull final World worldIn, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, @Nonnull final EntityPlayer playerIn, @Nonnull final EnumHand hand, @Nonnull final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
if (!worldIn.isRemote) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof MEFluidInputBus) {
if (te instanceof MEFluidInputBus inputBus) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.getItem() instanceof IMemoryCard memoryCard) {
boolean handled = handleSettingsTransfer(inputBus, memoryCard, playerIn, heldItem);
if (handled) {
return true;
}
}

playerIn.openGui(ModularMachinery.MODID, CommonProxy.GuiType.ME_FLUID_INPUT_BUS.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package github.kasuminova.mmce.common.block.appeng;

import appeng.api.implementations.items.IMemoryCard;
import github.kasuminova.mmce.common.tile.MEGasInputBus;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.CommonProxy;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
Expand All @@ -20,7 +22,15 @@ public class BlockMEGasInputBus extends BlockMEGasBus {
public boolean onBlockActivated(@Nonnull final World worldIn, @Nonnull final BlockPos pos, @Nonnull final IBlockState state, @Nonnull final EntityPlayer playerIn, @Nonnull final EnumHand hand, @Nonnull final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
if (!worldIn.isRemote) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof MEGasInputBus) {
if (te instanceof MEGasInputBus gasInputBus) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.getItem() instanceof IMemoryCard memoryCard) {
boolean handled = handleSettingsTransfer(gasInputBus, memoryCard, playerIn, heldItem);
if (handled) {
return true;
}
}

playerIn.openGui(ModularMachinery.MODID, CommonProxy.GuiType.ME_GAS_INPUT_BUS.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package github.kasuminova.mmce.common.block.appeng;

import appeng.api.implementations.items.IMemoryCard;
import github.kasuminova.mmce.common.tile.MEItemInputBus;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.CommonProxy;
Expand Down Expand Up @@ -31,7 +32,15 @@ public boolean onBlockActivated(
{
if (!worldIn.isRemote) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof MEItemInputBus) {
if (te instanceof MEItemInputBus itemInputBus) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.getItem() instanceof IMemoryCard memoryCard) {
boolean handled = handleSettingsTransfer(itemInputBus, memoryCard, playerIn, heldItem);
if (handled) {
return true;
}
}

playerIn.openGui(ModularMachinery.MODID, CommonProxy.GuiType.ME_ITEM_INPUT_BUS.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package github.kasuminova.mmce.common.block.appeng;

import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import github.kasuminova.mmce.common.tile.SettingsTransfer;
import hellfirepvp.modularmachinery.common.CommonProxy;
import hellfirepvp.modularmachinery.common.block.BlockMachineComponent;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
Expand Down Expand Up @@ -48,4 +53,25 @@ public EnumBlockRenderType getRenderType(@Nonnull IBlockState state) {
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.CUTOUT;
}

protected boolean handleSettingsTransfer(@Nonnull SettingsTransfer settingsProvider, @Nonnull IMemoryCard memoryCard, @Nonnull EntityPlayer player, @Nonnull ItemStack heldItem) {
if (player.isSneaking()) {
NBTTagCompound tag = settingsProvider.downloadSettings();
if (tag != null) {
memoryCard.setMemoryCardContents(heldItem, getTranslationKey(), tag);
return true;
}
} else {
String savedName = memoryCard.getSettingsName(heldItem);
NBTTagCompound tag = memoryCard.getData(heldItem);
if (getTranslationKey().equals(savedName)) {
settingsProvider.uploadSettings(tag);
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
return true;
} else {
memoryCard.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import appeng.me.GridAccessException;
import appeng.util.Platform;
import github.kasuminova.mmce.common.tile.base.MEFluidBus;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.lib.ItemsMM;
import hellfirepvp.modularmachinery.common.machine.IOType;
import hellfirepvp.modularmachinery.common.machine.MachineComponent;
Expand All @@ -21,7 +22,10 @@
import javax.annotation.Nullable;
import java.util.concurrent.locks.ReadWriteLock;

public class MEFluidInputBus extends MEFluidBus {
public class MEFluidInputBus extends MEFluidBus implements SettingsTransfer {

private static final String CONFIG_TAG_KEY = "config";

private final AEFluidInventory config = new AEFluidInventory(this, MEFluidBus.TANK_SLOT_AMOUNT);

@Override
Expand All @@ -32,13 +36,13 @@ public ItemStack getVisualItemStack() {
@Override
public void readCustomNBT(final NBTTagCompound compound) {
super.readCustomNBT(compound);
config.readFromNBT(compound, "config");
config.readFromNBT(compound, CONFIG_TAG_KEY);
}

@Override
public void writeCustomNBT(final NBTTagCompound compound) {
super.writeCustomNBT(compound);
config.writeToNBT(compound, "config");
config.writeToNBT(compound, CONFIG_TAG_KEY);
}

public IAEFluidTank getConfig() {
Expand Down Expand Up @@ -198,4 +202,22 @@ public void markNoUpdate() {

super.markNoUpdate();
}

@Override
public NBTTagCompound downloadSettings() {
NBTTagCompound tag = new NBTTagCompound();
config.writeToNBT(tag, CONFIG_TAG_KEY);
return tag;
}

@Override
public void uploadSettings(NBTTagCompound settings) {
config.readFromNBT(settings, CONFIG_TAG_KEY);
this.markForUpdate();
try {
proxy.getTick().alertDevice(proxy.getNode());
} catch (GridAccessException e) {
ModularMachinery.log.warn("Error while uploading settings", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mekeng.github.common.me.inventory.impl.GasInventory;
import github.kasuminova.mmce.common.tile.base.MEGasBus;
import github.kasuminova.mmce.common.util.IExtendedGasHandler;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.crafting.ComponentType;
import hellfirepvp.modularmachinery.common.lib.ComponentTypesMM;
import hellfirepvp.modularmachinery.common.lib.ItemsMM;
Expand All @@ -24,7 +25,10 @@
import javax.annotation.Nullable;
import java.util.Objects;

public class MEGasInputBus extends MEGasBus {
public class MEGasInputBus extends MEGasBus implements SettingsTransfer {

private static final String CONFIG_TAG_KEY = "config";

private final GasInventory config = new GasInventory(MEGasBus.TANK_SLOT_AMOUNT, this);

@Override
Expand All @@ -35,13 +39,13 @@ public ItemStack getVisualItemStack() {
@Override
public void readCustomNBT(final NBTTagCompound compound) {
super.readCustomNBT(compound);
config.load(compound.getCompoundTag("config"));
config.load(compound.getCompoundTag(CONFIG_TAG_KEY));
}

@Override
public void writeCustomNBT(final NBTTagCompound compound) {
super.writeCustomNBT(compound);
compound.setTag("config", config.save());
compound.setTag(CONFIG_TAG_KEY, config.save());
upgrades.writeToNBT(compound, "upgrades");
}

Expand Down Expand Up @@ -206,4 +210,21 @@ public void markNoUpdate() {

super.markNoUpdate();
}

@Override
public NBTTagCompound downloadSettings() {
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(CONFIG_TAG_KEY, config.save());
return tag;
}

@Override
public void uploadSettings(NBTTagCompound settings) {
config.load(settings.getCompoundTag(CONFIG_TAG_KEY));
try {
proxy.getTick().alertDevice(proxy.getNode());
} catch (GridAccessException e) {
ModularMachinery.log.warn("Error while uploading settings", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import appeng.me.GridAccessException;
import appeng.util.Platform;
import github.kasuminova.mmce.common.tile.base.MEItemBus;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.lib.ItemsMM;
import hellfirepvp.modularmachinery.common.machine.IOType;
import hellfirepvp.modularmachinery.common.machine.MachineComponent;
Expand All @@ -22,7 +23,10 @@
import java.util.WeakHashMap;
import java.util.concurrent.locks.ReadWriteLock;

public class MEItemInputBus extends MEItemBus {
public class MEItemInputBus extends MEItemBus implements SettingsTransfer {

private static final String CONFIG_TAG_KEY = "configInventory";

// A simple cache for AEItemStack.
private static final Map<ItemStack, IAEItemStack> AE_STACK_CACHE = new WeakHashMap<>();
private IOInventory configInventory = buildConfigInventory();
Expand Down Expand Up @@ -71,16 +75,16 @@ public IOInventory buildConfigInventory() {
public void readCustomNBT(final NBTTagCompound compound) {
super.readCustomNBT(compound);

if (compound.hasKey("configInventory")) {
readConfigInventoryNBT(compound.getCompoundTag("configInventory"));
if (compound.hasKey(CONFIG_TAG_KEY)) {
readConfigInventoryNBT(compound.getCompoundTag(CONFIG_TAG_KEY));
}
}

@Override
public void writeCustomNBT(final NBTTagCompound compound) {
super.writeCustomNBT(compound);

compound.setTag("configInventory", configInventory.writeNBT());
compound.setTag(CONFIG_TAG_KEY, configInventory.writeNBT());
}

public IOInventory getConfigInventory() {
Expand Down Expand Up @@ -281,4 +285,21 @@ public void readConfigInventoryNBT(final NBTTagCompound compound) {
}
configInventory.setStackLimit(Integer.MAX_VALUE, slotIDs);
}

@Override
public NBTTagCompound downloadSettings() {
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(CONFIG_TAG_KEY, configInventory.writeNBT());
return tag;
}

@Override
public void uploadSettings(NBTTagCompound settings) {
readConfigInventoryNBT(settings.getCompoundTag(CONFIG_TAG_KEY));
try {
proxy.getTick().alertDevice(proxy.getNode());
} catch (GridAccessException e) {
ModularMachinery.log.warn("Error while uploading settings", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package github.kasuminova.mmce.common.tile;

import net.minecraft.nbt.NBTTagCompound;

public interface SettingsTransfer {
NBTTagCompound downloadSettings();
void uploadSettings(NBTTagCompound settings);
}
Loading