Skip to content

Commit

Permalink
添加使用闪存绑定slave逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
DancingSnow0517 committed Jun 10, 2024
1 parent 27c610c commit 9146982
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/generated/resources/assets/gregiceng/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"block.gregiceng.zpm_output_buffer": "ɹǝɟɟnᗺ ʇndʇnO WԀZɔ§",
"config.gregiceng.option.enableMoreAbility": "ǝʌɐןS/ɹǝɟɟnᗺ OI buıʇɟɐɹƆ ɹoɟ ʎʇıןıqⱯ ǝɹoW ǝןqɐuƎ",
"config.jade.plugin_gregiceng.crafting_io_buffer": "ɹǝɟɟnᗺ OI buıʇɟɐɹƆ",
"gregiceng.tooltip.buffer_bind": "ɹǝɟɟnᗺ OI buıʇɟɐɹƆ %s :Z '%s :ʎ '%s :X oʇ puıᗺ",
"gui.gregiceng.auto_pull_me.desc.disabled": "pǝןqɐsıp sı ןןnd ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.auto_pull_me.desc.enabled": "uo sı ןןnd ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.automatic_return.desc.disabled": "pǝןqɐsıp sı uɹnʇǝᴚ ɔıʇɐɯoʇnⱯ",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gregiceng/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"block.gregiceng.zpm_output_buffer": "§cZPM Output Buffer",
"config.gregiceng.option.enableMoreAbility": "Enable More Ability for Crafting IO Buffer/Slave",
"config.jade.plugin_gregiceng.crafting_io_buffer": "Crafting IO Buffer",
"gregiceng.tooltip.buffer_bind": "Bind to X: %s, Y: %s, Z: %s Crafting IO Buffer",
"gui.gregiceng.auto_pull_me.desc.disabled": "Automatic pull is disabled",
"gui.gregiceng.auto_pull_me.desc.enabled": "Automatic pull is on",
"gui.gregiceng.automatic_return.desc.disabled": "Automatic Return is disabled",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gregiceng/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"block.gregiceng.zpm_output_buffer": "§cZPM§r输出总成",
"config.gregiceng.option.enableMoreAbility": "为样板IO总成/镜像启用更多能力",
"config.jade.plugin_gregiceng.crafting_io_buffer": "样板IO总成",
"gregiceng.tooltip.buffer_bind": "绑定至 X: %s, Y: %s, Z: %s 样板IO总成",
"gui.gregiceng.auto_pull_me.desc.disabled": "自动拉取已禁用",
"gui.gregiceng.auto_pull_me.desc.enabled": "自动拉取已开启",
"gui.gregiceng.automatic_return.desc.disabled": "自动回流已禁用",
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/epimorphismmc/gregiceng/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.epimorphismmc.gregiceng.GregicEng;
import com.epimorphismmc.gregiceng.common.data.GECreativeModeTabs;
import com.epimorphismmc.gregiceng.common.data.GEMachines;
import com.epimorphismmc.gregiceng.common.item.GEDataStickBehavior;
import com.epimorphismmc.monomorphism.proxy.base.ICommonProxyBase;
import com.gregtechceu.gtceu.api.GTCEuAPI;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.common.data.GTItems;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

public class CommonProxy implements ICommonProxyBase {

Expand All @@ -31,4 +34,11 @@ public void registerMachineDefinitions(GTCEuAPI.RegisterEvent<ResourceLocation,
GECreativeModeTabs.init();
GEMachines.init();
}

/* -------------------------------------------------- Life Cycle Methods ---------------------------------------------------- */

@Override
public void onCommonSetupEvent(FMLCommonSetupEvent event) {
GTItems.TOOL_DATA_STICK.get().attachComponents(new GEDataStickBehavior());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.epimorphismmc.gregiceng.common.item;

import com.epimorphismmc.gregiceng.common.machine.multiblock.part.appeng.CraftingIOBufferPartMachine;
import com.epimorphismmc.gregiceng.common.machine.multiblock.part.appeng.CraftingIOSlavePartMachine;
import com.gregtechceu.gtceu.api.item.component.IAddInformation;
import com.gregtechceu.gtceu.api.item.component.IInteractionItem;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class GEDataStickBehavior implements IInteractionItem, IAddInformation {
@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockEntity blockEntity = level.getBlockEntity(pos);
ItemStack stack = context.getItemInHand();
if (level.isClientSide()) {
return InteractionResult.PASS;
}
if (blockEntity instanceof IMachineBlockEntity machineBlockEntity) {
MetaMachine machine = machineBlockEntity.getMetaMachine();
if (machine instanceof CraftingIOBufferPartMachine) {
stack.getOrCreateTag().putIntArray("pos", new int[]{pos.getX(), pos.getY(), pos.getZ()});
return InteractionResult.SUCCESS;
} else if (machine instanceof CraftingIOSlavePartMachine slave) {
if (stack.hasTag()) {
if (stack.getOrCreateTag().contains("pos", Tag.TAG_INT_ARRAY)) {
int[] posArray = stack.getOrCreateTag().getIntArray("pos");
BlockPos bufferPos = new BlockPos(posArray[0], posArray[1], posArray[2]);
slave.setIOBuffer(bufferPos);
return InteractionResult.SUCCESS;
}
}
}
}
return IInteractionItem.super.useOn(context);
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, TooltipFlag isAdvanced) {
if (stack.hasTag()) {
if (stack.getOrCreateTag().contains("pos", Tag.TAG_INT_ARRAY)) {
int[] posArray = stack.getOrCreateTag().getIntArray("pos");
tooltipComponents.add(Component.translatable(
"gregiceng.tooltip.buffer_bind",
Component.literal("" + posArray[0]).withStyle(ChatFormatting.LIGHT_PURPLE),
Component.literal("" + posArray[1]).withStyle(ChatFormatting.LIGHT_PURPLE),
Component.literal("" + posArray[2]).withStyle(ChatFormatting.LIGHT_PURPLE)
));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CraftingIOSlavePartMachine(IMachineBlockEntity holder) {
this.circuitHandler = new WrappedRecipeHandlerTrait<>(IO.IN, ItemRecipeCapability.CAP);
}

private boolean setIOBuffer(BlockPos pos) {
public boolean setIOBuffer(BlockPos pos) {
if (pos == null) return false;
if (MetaMachine.getMachine(getLevel(), pos) instanceof CraftingIOBufferPartMachine) {
this.pos = pos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public static void init(MOLangProvider provider) {

provider.add("gui.gregiceng.rename.desc",
"Rename",
"重命名");
"重命名"
);

provider.add("config.jade.plugin_gregiceng.crafting_io_buffer",
"Crafting IO Buffer",
Expand All @@ -136,7 +137,13 @@ public static void init(MOLangProvider provider) {

provider.add("config.gregiceng.option.enableMoreAbility",
"Enable More Ability for Crafting IO Buffer/Slave",
"为样板IO总成/镜像启用更多能力")
;
"为样板IO总成/镜像启用更多能力"
);

provider.add(
"gregiceng.tooltip.buffer_bind",
"Bind to X: %s, Y: %s, Z: %s Crafting IO Buffer",
"绑定至 X: %s, Y: %s, Z: %s 样板IO总成"
);
}
}

0 comments on commit 9146982

Please sign in to comment.