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: 2 additions & 0 deletions docs/content/Modpacks/Changes/v7.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ title: "Version 7.5.0"
# Updating from `7.4.1` to `7.5.0`
## MachineBuilder Generics
We have added a second Generic argument to our (Multiblock)MachineBuilder. This effectively means that anywhere where you used to store a partially finished `MachineBuilder<?>`, you now need to store a `MachineBuilder<?, ?>`. The same holds for `MultiblockMachineBuilder<?,?>`.
## Machine & Cover Copy/Paste System
A new system for copying machines using the Machine Memory Card has been added, see [this page](../Other-Topics/Cover-Machine-Copy-Paste-Support.md) if you want to add extra copy/paste behaviour to your own machines and covers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Adding Copy & Paste support to covers and machines
---

The Machine Memory Card item allows for machine settings and covers to be copied to other machines.

To add extra fields to copy, override the following methods on a machine or cover:
```java
/// Copies the current machine/cover config to a CompoundTag.
public CompoundTag copyConfig(CompoundTag tag);
/// Loads a machine/cover config from a CompoundTag.
public void pasteConfig(ServerPlayer player, CompoundTag tag);
/// Returns a list of items (covers, filters, etc) which are needed to copy and paste this machine.
public List<ItemStack> getItemsRequiredToPaste();
```
26 changes: 19 additions & 7 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@
"behaviour.lighter.tooltip.description": "ǝɹıɟ uo sbuıɥʇ ʇɥbıן uɐƆ",
"behaviour.lighter.tooltip.usage": "ǝsoןɔ/uǝdo oʇ ʞɔıןɔ ʇɥbıɹ-ʇɟıɥS",
"behaviour.lighter.uses": "%d :sǝsn buıuıɐɯǝᴚ",
"behaviour.meta.machine.config.copy.tooltip": "uoıʇɐɹnbıɟuoɔ ǝuıɥɔɐɯ ʎdoɔ oʇ ʞɔıןƆ-ᴚ + ʞɐǝuSㄥ§",
"behaviour.meta.machine.config.paste.tooltip": "uoıʇɐɹnbıɟuoɔ ǝuıɥɔɐɯ ǝʇsɐd oʇ ʞɔıןƆ-ᴚㄥ§",
"behaviour.memory_card.client_msg.cleared": "pǝɹɐǝןɔ uoıʇɐɹnbıɟuoɔ pǝɹoʇS",
"behaviour.memory_card.client_msg.copied": "uoıʇɐɹnbıɟuoɔ ǝuıɥɔɐɯ pǝıdoƆ",
"behaviour.memory_card.client_msg.pasted": "uoıʇɐɹnbıɟuoɔ ǝuıɥɔɐɯ pǝıןddⱯ",
"behaviour.memory_card.copy_target": "%s :buıʎdoƆ",
"behaviour.memory_card.disabled": "ɹ§pǝןqɐsıᗡɔ§",
"behaviour.memory_card.enabled": "ɹ§pǝןqɐuƎɐ§",
"behaviour.memory_card.tooltip.copy": "˙pǝʇǝbɹɐʇ sı ǝdıd ɹo ǝuıɥɔɐɯ ɐ uɐɥʇ ɹǝɥʇo ʞɔoןq ɐ ɟı ɐʇɐp pǝɹoʇs ɹɐǝןɔ ɹo 'uoıʇɐɹnbıɟuoɔ ʎdoɔ oʇ ʞɔıןƆ-ᴚ + ʞɐǝuSㄥ§",
"behaviour.memory_card.tooltip.items_to_paste": ":uoıʇɐɹnbıɟuoɔ sıɥʇ ǝʇsɐd oʇ pǝpǝǝu ǝɹɐ sɯǝʇı buıʍoןןoɟ ǝɥ⟘",
"behaviour.memory_card.tooltip.paste": "uoıʇɐɹnbıɟuoɔ ǝuıɥɔɐɯ ǝʇsɐd oʇ ʞɔıןƆ-ᴚㄥ§",
"behaviour.memory_card.tooltip.view_stored": ">uoıʇɐɹnbıɟuoɔ pǝɹoʇs ʍǝıʌ oʇ ʞɐǝuS<8§",
"behaviour.paintspray.black.tooltip": "ʞɔɐןᗺ uı sbuıɥʇ ʇuıɐd uɐƆ",
"behaviour.paintspray.blue.tooltip": "ǝnןᗺ uı sbuıɥʇ ʇuıɐd uɐƆ",
"behaviour.paintspray.brown.tooltip": "uʍoɹᗺ uı sbuıɥʇ ʇuıɐd uɐƆ",
Expand All @@ -85,10 +93,15 @@
"behaviour.paintspray.white.tooltip": "ǝʇıɥM uı sbuıɥʇ ʇuıɐd uɐƆ",
"behaviour.paintspray.yellow.tooltip": "ʍoןןǝʎ uı sbuıɥʇ ʇuıɐd uɐƆ",
"behaviour.prospecting": "buıʇɔǝdsoɹԀ ɹoɟ ǝןqɐs∩",
"behaviour.setting.allow.input.from.output.tooltip": "%s sı ǝpıs ʇndʇno ɯoɹɟ ʇnduı %s",
"behaviour.setting.item_auto_output.tooltip": "%s sı ʇndʇno-oʇnɐ %s",
"behaviour.setting.muffled.tooltip": "%s buıןɟɟnW",
"behaviour.setting.output.direction.tooltip": "%s :uoıʇɔǝɹıp ʇndʇno %s",
"behaviour.setting.tooltip.allow_input": "ɹ§ʇnduI ʍoןןⱯᄅ§",
"behaviour.setting.tooltip.auto_output": "ɹ§ʇndʇnO oʇnⱯᄅ§",
"behaviour.setting.tooltip.auto_output_allow_input": "ɹ§ʇnduI ʍoןןⱯ/ʇndʇnO oʇnⱯᄅ§",
"behaviour.setting.tooltip.circuit_config": " :ʇınɔɹıƆ pǝɯɯɐɹboɹԀ",
"behaviour.setting.tooltip.fluid_io": ")%s( %s :ʇndʇnO pınןℲ",
"behaviour.setting.tooltip.item_io": ")%s( %s :ʇndʇnO ɯǝʇI",
"behaviour.setting.tooltip.muffled": "%s buıןɟɟnW",
"behaviour.setting.tooltip.pipe_blocked_connections": "%s :sǝpıs pǝɹǝʇʇnɥs ǝdıԀ",
"behaviour.setting.tooltip.pipe_connections": "%s :suoıʇɔǝuuoɔ ǝdıԀ",
"behaviour.soft_hammer": "sǝuıɥɔɐW sǝʇɐʌıʇɔɐǝᗡ puɐ sǝʇɐʌıʇɔⱯ",
"behaviour.soft_hammer.disabled": "pǝןqɐsıᗡ buıʞɹoM",
"behaviour.soft_hammer.disabled_cycle": "ǝןɔʎɔ ʇuǝɹɹnɔ ɹǝʇɟɐ pǝןqɐsıᗡ buıʞɹoM",
Expand Down Expand Up @@ -4978,7 +4991,6 @@
"item.gtceu.zpm_voltage_coil.tooltip": "ןıoƆ ɹǝdnS",
"item.invalid.name": "ɯǝʇı pıןɐʌuI",
"item.netherrack_nether_quartz": "ǝɹO zʇɹɐnὉ ɹǝɥʇǝN",
"item.toggle.advanced.info.tooltip": ">uoıʇɐɹnbıɟuoɔ pǝɹoʇs ʍǝıʌ oʇ ʞɐǝuS<8§",
"itemGroup.gtceu.decoration": "sʞɔoןᗺ uoıʇɐɹoɔǝᗡ nƎƆɥɔǝ⟘bǝɹ⅁",
"itemGroup.gtceu.item": "sɯǝʇI nƎƆɥɔǝ⟘bǝɹ⅁",
"itemGroup.gtceu.machine": "sǝuıɥɔɐW nƎƆɥɔǝ⟘bǝɹ⅁",
Expand Down
26 changes: 19 additions & 7 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@
"behaviour.lighter.tooltip.description": "Can light things on fire",
"behaviour.lighter.tooltip.usage": "Shift-right click to open/close",
"behaviour.lighter.uses": "Remaining uses: %d",
"behaviour.meta.machine.config.copy.tooltip": "§7Sneak + R-Click to copy machine configuration",
"behaviour.meta.machine.config.paste.tooltip": "§7R-Click to paste machine configuration",
"behaviour.memory_card.client_msg.cleared": "Stored configuration cleared",
"behaviour.memory_card.client_msg.copied": "Copied machine configuration",
"behaviour.memory_card.client_msg.pasted": "Applied machine configuration",
"behaviour.memory_card.copy_target": "Copying: %s",
"behaviour.memory_card.disabled": "§cDisabled§r",
"behaviour.memory_card.enabled": "§aEnabled§r",
"behaviour.memory_card.tooltip.copy": "§7Sneak + R-Click to copy configuration, or clear stored data if a block other than a machine or pipe is targeted.",
"behaviour.memory_card.tooltip.items_to_paste": "The following items are needed to paste this configuration:",
"behaviour.memory_card.tooltip.paste": "§7R-Click to paste machine configuration",
"behaviour.memory_card.tooltip.view_stored": "§8<Sneak to view stored configuration>",
"behaviour.paintspray.black.tooltip": "Can paint things in Black",
"behaviour.paintspray.blue.tooltip": "Can paint things in Blue",
"behaviour.paintspray.brown.tooltip": "Can paint things in Brown",
Expand All @@ -85,10 +93,15 @@
"behaviour.paintspray.white.tooltip": "Can paint things in White",
"behaviour.paintspray.yellow.tooltip": "Can paint things in Yellow",
"behaviour.prospecting": "Usable for Prospecting",
"behaviour.setting.allow.input.from.output.tooltip": "%s input from output side is %s",
"behaviour.setting.item_auto_output.tooltip": "%s auto-output is %s",
"behaviour.setting.muffled.tooltip": "Muffling %s",
"behaviour.setting.output.direction.tooltip": "%s output direction: %s",
"behaviour.setting.tooltip.allow_input": "§2Allow Input§r",
"behaviour.setting.tooltip.auto_output": "§2Auto Output§r",
"behaviour.setting.tooltip.auto_output_allow_input": "§2Auto Output/Allow Input§r",
"behaviour.setting.tooltip.circuit_config": "Programmed Circuit: ",
"behaviour.setting.tooltip.fluid_io": "Fluid Output: %s (%s)",
"behaviour.setting.tooltip.item_io": "Item Output: %s (%s)",
"behaviour.setting.tooltip.muffled": "Muffling %s",
"behaviour.setting.tooltip.pipe_blocked_connections": "Pipe shuttered sides: %s",
"behaviour.setting.tooltip.pipe_connections": "Pipe connections: %s",
"behaviour.soft_hammer": "Activates and Deactivates Machines",
"behaviour.soft_hammer.disabled": "Working Disabled",
"behaviour.soft_hammer.disabled_cycle": "Working Disabled after current cycle",
Expand Down Expand Up @@ -4978,7 +4991,6 @@
"item.gtceu.zpm_voltage_coil.tooltip": "Super Coil",
"item.invalid.name": "Invalid item",
"item.netherrack_nether_quartz": "Nether Quartz Ore",
"item.toggle.advanced.info.tooltip": "§8<Sneak to view stored configuration>",
"itemGroup.gtceu.decoration": "GregTechCEu Decoration Blocks",
"itemGroup.gtceu.item": "GregTechCEu Items",
"itemGroup.gtceu.machine": "GregTechCEu Machines",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gregtechceu.gtceu.api.blockentity;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;

import java.util.List;

/// An interface for machines and machine traits which have settings that can be copied using the machine memory card.
public interface ICopyable {

/// Saves the current config into a CompoundTag.
default CompoundTag copyConfig(CompoundTag tag) {
return tag;
}

/// Loads a saved config from a CompoundTag and applies it to an existing object.
default void pasteConfig(ServerPlayer player, CompoundTag tag) {}

/// Returns a `List<ItemStack>` of items required to paste the saved config.
default List<ItemStack> getItemsRequiredToPaste() {
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -61,7 +62,8 @@
@MethodsReturnNonnullByDefault
public abstract class PipeBlockEntity<PipeType extends Enum<PipeType> & IPipeType<NodeDataType>, NodeDataType>
extends BlockEntity implements IPipeNode<PipeType, NodeDataType>, IEnhancedManaged,
IAsyncAutoSyncBlockEntity, IAutoPersistBlockEntity, IToolGridHighlight, IToolable {
IAsyncAutoSyncBlockEntity, IAutoPersistBlockEntity, IToolGridHighlight, IToolable,
ICopyable {

public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(PipeBlockEntity.class);
@Getter
Expand Down Expand Up @@ -453,4 +455,19 @@ public void load(CompoundTag tag) {
TagFixer.fixFluidTags(tag);
super.load(tag);
}

@Override
public CompoundTag copyConfig(CompoundTag tag) {
return ICopyable.super.copyConfig(tag);
}

@Override
public void pasteConfig(ServerPlayer player, CompoundTag tag) {
ICopyable.super.pasteConfig(player, tag);
}

@Override
public List<ItemStack> getItemsRequiredToPaste() {
return coverContainer.getItemsRequiredToPaste();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.gregtechceu.gtceu.api.capability;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.blockentity.ICopyable;
import com.gregtechceu.gtceu.api.blockentity.ITickSubscription;
import com.gregtechceu.gtceu.api.cover.CoverBehavior;
import com.gregtechceu.gtceu.api.cover.CoverDefinition;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable;
import com.gregtechceu.gtceu.utils.GTUtil;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.Level;
Expand All @@ -25,13 +30,10 @@

import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

public interface ICoverable extends ITickSubscription {
public interface ICoverable extends ITickSubscription, ICopyable {

Level getLevel();

Expand Down Expand Up @@ -219,15 +221,6 @@ default boolean hasDynamicCovers() {
return false;
}

class PrimaryBoxData {

public final boolean usePlacementGrid;

public PrimaryBoxData(boolean usePlacementGrid) {
this.usePlacementGrid = usePlacementGrid;
}
}

@Nullable
static Direction traceCoverSide(@Nullable BlockHitResult result) {
return determineGridSideHit(result);
Expand Down Expand Up @@ -273,4 +266,74 @@ default BlockState getBlockAppearance(BlockState state, BlockAndTintGetter level
}
return null;
}

private CompoundTag createCoverConfigTag(@Nullable CoverBehavior cover) {
if (cover == null) return new CompoundTag();
var tag = new CompoundTag();
tag.putString("id", GTRegistries.COVERS.getKey(cover.coverDefinition).toString());
tag.put("item", cover.getAttachItem().serializeNBT());
tag.put("data", cover.copyConfig(new CompoundTag()));
return tag;
}

private void applyCoverConfigTag(ServerPlayer player, Direction dir, CompoundTag tag) {
if (tag.isEmpty()) return;
var def = GTRegistries.COVERS.get(new ResourceLocation(tag.getString("id")));
ItemStack stack = ItemStack.of(tag.getCompound("item"));
if (def == null) return;

placeCoverOnSide(dir, stack, def, player);

CoverBehavior placedCover = getCoverAtSide(dir);
if (placedCover != null && tag.contains("data") && !tag.getCompound("data").isEmpty())
placedCover.pasteConfig(player, tag.getCompound("data"));
}

@Override
default CompoundTag copyConfig(CompoundTag tag) {
for (Direction dir : GTUtil.DIRECTIONS) {
tag.put(dir.getName(), hasCover(dir) ? createCoverConfigTag(getCoverAtSide(dir)) : new CompoundTag());
}

return tag;
}

@Override
default void pasteConfig(ServerPlayer player, CompoundTag tag) {
for (Direction side : GTUtil.DIRECTIONS) {
removeCover(side, player);
}

for (Direction dir : GTUtil.DIRECTIONS) {
applyCoverConfigTag(player, dir, tag.getCompound(dir.getName()));
}
}

@Override
default List<ItemStack> getItemsRequiredToPaste() {
Map<Item, Integer> allDrops = new HashMap<>();
List<ItemStack> rawDrops = new ArrayList<>();

for (Direction side : GTUtil.DIRECTIONS) {
var cover = getCoverAtSide(side);
if (cover != null) rawDrops.add(cover.getAttachItem());
}

for (Direction side : GTUtil.DIRECTIONS) {
var cover = getCoverAtSide(side);
if (cover != null) rawDrops.addAll(cover.getAdditionalDrops());
}

for (var drop : rawDrops) {
if (allDrops.containsKey(drop.getItem())) {
allDrops.put(drop.getItem(), allDrops.get(drop.getItem()) + drop.getCount());
} else {
allDrops.put(drop.getItem(), drop.getCount());
}
}

List<ItemStack> mergedStacks = new ArrayList<>();
allDrops.forEach((k, v) -> mergedStacks.add(new ItemStack(k, v)));
return mergedStacks;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.cover;

import com.gregtechceu.gtceu.api.blockentity.ICopyable;
import com.gregtechceu.gtceu.api.capability.ICoverable;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.factory.CoverUIFactory;
Expand Down Expand Up @@ -48,7 +49,7 @@
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public abstract class CoverBehavior implements IEnhancedManaged, IToolGridHighlight {
public abstract class CoverBehavior implements IEnhancedManaged, IToolGridHighlight, ICopyable {

public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(CoverBehavior.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public int getSlotLimit(int slot) {
return this.filterSlot;
}

public void setFilterItem(ItemStack item) {
getFilterSlot().setStackInSlot(0, item);
updateFilter();
}

private void updateFilter() {
var filterContainer = getFilterSlot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.block.MetaMachineBlock;
import com.gregtechceu.gtceu.api.block.property.GTBlockStateProperties;
import com.gregtechceu.gtceu.api.blockentity.ICopyable;
import com.gregtechceu.gtceu.api.blockentity.IPaintable;
import com.gregtechceu.gtceu.api.blockentity.ITickSubscription;
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
Expand Down Expand Up @@ -50,6 +51,7 @@
import net.minecraft.locale.Language;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -95,7 +97,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class MetaMachine implements IEnhancedManaged, IToolable, ITickSubscription, IToolGridHighlight,
IFancyTooltip, IPaintable, IRedstoneSignalMachine {
IFancyTooltip, IPaintable, IRedstoneSignalMachine, ICopyable {

protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(MetaMachine.class);
@Getter
Expand Down Expand Up @@ -860,4 +862,19 @@ public void onAddFancyInformationTooltip(List<Component> tooltips) {
public int getDefaultPaintingColor() {
return getDefinition().getDefaultPaintingColor();
}

@Override
public CompoundTag copyConfig(CompoundTag tag) {
return ICopyable.super.copyConfig(tag);
}

@Override
public void pasteConfig(ServerPlayer player, CompoundTag tag) {
ICopyable.super.pasteConfig(player, tag);
}

@Override
public List<ItemStack> getItemsRequiredToPaste() {
return coverContainer.getItemsRequiredToPaste();
}
}
Loading