适配扩展样板供应器
This commit is contained in:
parent
af9f75082e
commit
6877145bbb
|
|
@ -10,6 +10,7 @@ import appeng.helpers.patternprovider.PatternProviderLogic;
|
|||
import appeng.util.CustomNameUtil;
|
||||
import appeng.util.SettingsFrom;
|
||||
import appeng.util.inv.AppEngInternalInventory;
|
||||
import com.extendedae_plus.config.ModConfig;
|
||||
import com.extendedae_plus.init.ModBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
|
|
@ -34,6 +35,8 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
private static final String TAG_MASTER_DIMENSION = "dimension";
|
||||
private static final String TAG_MASTER_POS = "pos";
|
||||
private static final int SYNC_INTERVAL = 2;
|
||||
private static final int AE2_PATTERN_SLOTS = 9;
|
||||
private static final int EXTENDED_PATTERN_PROVIDER_BASE_SLOTS = 36;
|
||||
private static final InternalInventory DISABLED_PATTERN_INVENTORY = new AppEngInternalInventory(0);
|
||||
|
||||
@Nullable
|
||||
|
|
@ -58,7 +61,7 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
|
||||
@Override
|
||||
protected PatternProviderLogic createLogic() {
|
||||
return new MirrorLogic(this.getMainNode(), this);
|
||||
return new MirrorLogic(this.getMainNode(), this, getMirrorPatternSlotCapacity());
|
||||
}
|
||||
|
||||
public static void serverTick(Level level, BlockPos pos, BlockState state,
|
||||
|
|
@ -146,7 +149,8 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
if (masterLevel != null && masterLevel.hasChunkAt(master.pos())) {
|
||||
var blockEntity = masterLevel.getBlockEntity(master.pos());
|
||||
if (isValidMaster(blockEntity)) {
|
||||
return this.syncFromMaster((PatternProviderBlockEntity) blockEntity);
|
||||
this.syncFromMaster((PatternProviderBlockEntity) blockEntity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -311,15 +315,15 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
|
||||
private boolean syncMirroredPatterns(PatternProviderBlockEntity master) {
|
||||
var mirrorInventory = this.getPatternInventory();
|
||||
var masterInventory = asPatternInventory(master.getLogic().getPatternInv());
|
||||
var desiredInventory = this.createDesiredPatternInventory(master);
|
||||
|
||||
if (this.hasSamePatterns(masterInventory, mirrorInventory)) {
|
||||
if (this.hasSamePatterns(desiredInventory, mirrorInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.clearInventory(mirrorInventory);
|
||||
for (int slot = 0; slot < masterInventory.size(); slot++) {
|
||||
mirrorInventory.setItemDirect(slot, masterInventory.getStackInSlot(slot).copy());
|
||||
for (int slot = 0; slot < desiredInventory.size(); slot++) {
|
||||
mirrorInventory.setItemDirect(slot, desiredInventory.getStackInSlot(slot).copy());
|
||||
}
|
||||
this.getLogic().updatePatterns();
|
||||
return true;
|
||||
|
|
@ -364,6 +368,18 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
return ((MirrorLogic) this.getLogic()).getActualPatternInventory();
|
||||
}
|
||||
|
||||
private AppEngInternalInventory createDesiredPatternInventory(PatternProviderBlockEntity master) {
|
||||
var desiredInventory = new AppEngInternalInventory(this.getPatternInventory().size());
|
||||
var masterInventory = asPatternInventory(master.getLogic().getPatternInv());
|
||||
var copySlotCount = Math.min(masterInventory.size(), desiredInventory.size());
|
||||
|
||||
for (int slot = 0; slot < copySlotCount; slot++) {
|
||||
desiredInventory.setItemDirect(slot, masterInventory.getStackInSlot(slot).copy());
|
||||
}
|
||||
|
||||
return desiredInventory;
|
||||
}
|
||||
|
||||
private ItemStack[] copyInventoryContents(AppEngInternalInventory inventory) {
|
||||
var contents = new ItemStack[inventory.size()];
|
||||
for (int slot = 0; slot < inventory.size(); slot++) {
|
||||
|
|
@ -397,6 +413,16 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
return (AppEngInternalInventory) inventory;
|
||||
}
|
||||
|
||||
private static int getMirrorPatternSlotCapacity() {
|
||||
int pageMultiplier = 1;
|
||||
if (ModConfig.INSTANCE != null) {
|
||||
pageMultiplier = ModConfig.INSTANCE.pageMultiplier;
|
||||
}
|
||||
|
||||
pageMultiplier = Math.max(1, Math.min(64, pageMultiplier));
|
||||
return Math.max(AE2_PATTERN_SLOTS, EXTENDED_PATTERN_PROVIDER_BASE_SLOTS * pageMultiplier);
|
||||
}
|
||||
|
||||
private static boolean sameStack(ItemStack left, ItemStack right) {
|
||||
if (left.isEmpty() && right.isEmpty()) {
|
||||
return true;
|
||||
|
|
@ -406,8 +432,8 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
}
|
||||
|
||||
public static boolean isSupportedMaster(@Nullable BlockEntity blockEntity) {
|
||||
return blockEntity != null
|
||||
&& blockEntity.getClass() == PatternProviderBlockEntity.class
|
||||
return blockEntity instanceof PatternProviderBlockEntity
|
||||
&& !(blockEntity instanceof MirrorPatternProviderBlockEntity)
|
||||
&& !blockEntity.isRemoved();
|
||||
}
|
||||
|
||||
|
|
@ -416,8 +442,9 @@ public class MirrorPatternProviderBlockEntity extends PatternProviderBlockEntity
|
|||
}
|
||||
|
||||
private static final class MirrorLogic extends PatternProviderLogic {
|
||||
private MirrorLogic(IManagedGridNode mainNode, MirrorPatternProviderBlockEntity mirrorHost) {
|
||||
super(mainNode, mirrorHost);
|
||||
private MirrorLogic(IManagedGridNode mainNode, MirrorPatternProviderBlockEntity mirrorHost,
|
||||
int patternInventorySize) {
|
||||
super(mainNode, mirrorHost, patternInventorySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class MirrorPatternBindingToolItem extends Item {
|
|||
} else {
|
||||
player.displayClientMessage(
|
||||
Component.translatable(
|
||||
"extendedae_plus.message.mirror_binding_tool.only_normal_provider"),
|
||||
"extendedae_plus.message.mirror_binding_tool.unsupported_provider"),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@
|
|||
"item.extendedae_plus.channel_card.owner.cleared": "Owner binding cleared",
|
||||
"item.extendedae_plus.mirror_pattern_provider": "Mirror Pattern Provider",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool": "Mirror Pattern Binder",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.select": "Sneak-right-click a standard pattern provider to record it",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.select": "Sneak-right-click a bindable pattern provider to record it",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.bind": "Right-click a mirror pattern provider to bind it to the recorded master",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.clear": "Sneak-right-click air to clear the recorded master",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.selected": "Recorded master provider: (%d, %d, %d)",
|
||||
|
|
@ -208,12 +208,12 @@
|
|||
"extendedae_plus.message.config_delete_failed": "Mapping file delete failed: %s",
|
||||
"extendedae_plus.message.mirror_pattern_provider.bound": "Mirror pattern provider bound to master provider: (%d, %d, %d)",
|
||||
"extendedae_plus.message.mirror_pattern_provider.following": "Mirror pattern provider is following master provider: (%d, %d, %d)",
|
||||
"extendedae_plus.message.mirror_pattern_provider.missing_master": "No standard master pattern provider is bound. Use the binder to bind one manually.",
|
||||
"extendedae_plus.message.mirror_pattern_provider.missing_master": "No master pattern provider is bound. Use the binder to bind one manually.",
|
||||
"extendedae_plus.message.mirror_pattern_provider.readonly": "Mirror pattern provider has no standalone UI and follows the master's state and direction.",
|
||||
"extendedae_plus.message.mirror_binding_tool.selected": "Recorded master pattern provider: (%d, %d, %d)",
|
||||
"extendedae_plus.message.mirror_binding_tool.no_selection": "Sneak-right-click a standard pattern provider first to record it.",
|
||||
"extendedae_plus.message.mirror_binding_tool.bind_failed": "Binding failed: the recorded position is not a valid standard pattern provider.",
|
||||
"extendedae_plus.message.mirror_binding_tool.only_normal_provider": "This mirror binder only supports the standard pattern provider, not the extended one.",
|
||||
"extendedae_plus.message.mirror_binding_tool.no_selection": "Sneak-right-click a bindable pattern provider first to record it.",
|
||||
"extendedae_plus.message.mirror_binding_tool.bind_failed": "Binding failed: the recorded position is not a valid pattern provider.",
|
||||
"extendedae_plus.message.mirror_binding_tool.unsupported_provider": "This mirror binder only supports bindable pattern provider targets.",
|
||||
"extendedae_plus.message.mirror_binding_tool.cleared": "Cleared the master pattern provider recorded in the binding tool.",
|
||||
|
||||
"config.jade.plugin_extendedae_plus.wireless_transceiver_info": "Wireless Transceiver Info",
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@
|
|||
"item.extendedae_plus.channel_card.owner.cleared": "已清除所有者绑定",
|
||||
"item.extendedae_plus.mirror_pattern_provider": "镜像样板供应器",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool": "镜像样板绑定器",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.select": "潜行右键普通样板供应器:记录主供应器",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.select": "潜行右键可绑定的样板供应器:记录主供应器",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.bind": "右键镜像样板供应器:绑定到当前记录的主供应器",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.tip.clear": "潜行右键空气:清空当前记录的主供应器",
|
||||
"item.extendedae_plus.mirror_pattern_binding_tool.selected": "当前记录主供应器:(%d, %d, %d)",
|
||||
|
|
@ -207,12 +207,12 @@
|
|||
"extendedae_plus.message.config_delete_failed": "映射文件删除失败: %s",
|
||||
"extendedae_plus.message.mirror_pattern_provider.bound": "镜像样板供应器已绑定到主供应器:(%d, %d, %d)",
|
||||
"extendedae_plus.message.mirror_pattern_provider.following": "镜像样板供应器当前跟随主供应器:(%d, %d, %d)",
|
||||
"extendedae_plus.message.mirror_pattern_provider.missing_master": "未绑定普通主样板供应器,请使用绑定器手动绑定",
|
||||
"extendedae_plus.message.mirror_pattern_provider.missing_master": "未绑定主样板供应器,请使用绑定器手动绑定",
|
||||
"extendedae_plus.message.mirror_pattern_provider.readonly": "镜像样板供应器没有独立界面,状态与朝向会跟随主供应器",
|
||||
"extendedae_plus.message.mirror_binding_tool.selected": "已记录主样板供应器:(%d, %d, %d)",
|
||||
"extendedae_plus.message.mirror_binding_tool.no_selection": "请先潜行右键一个普通样板供应器进行记录",
|
||||
"extendedae_plus.message.mirror_binding_tool.bind_failed": "绑定失败:记录的位置不是可用的普通样板供应器",
|
||||
"extendedae_plus.message.mirror_binding_tool.only_normal_provider": "当前镜像样板绑定器只支持普通样板供应器,不支持扩展样板供应器",
|
||||
"extendedae_plus.message.mirror_binding_tool.no_selection": "请先潜行右键一个可绑定的样板供应器进行记录",
|
||||
"extendedae_plus.message.mirror_binding_tool.bind_failed": "绑定失败:记录的位置不是可用的样板供应器",
|
||||
"extendedae_plus.message.mirror_binding_tool.unsupported_provider": "当前镜像样板绑定器仅支持可绑定的样板供应器目标",
|
||||
"extendedae_plus.message.mirror_binding_tool.cleared": "已清空绑定工具中记录的主样板供应器",
|
||||
|
||||
"config.jade.plugin_extendedae_plus.wireless_transceiver_info": "无线收发器信息",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user