From a85f6757efee4d0d66e20127dc8e3f3b9f41d56e Mon Sep 17 00:00:00 2001 From: topi-banana Date: Mon, 8 Apr 2024 19:10:05 +0900 Subject: [PATCH] [new] disablePlacedOnNetherPortalSides+ # New + disablePlacedOnNetherPortalSides --- .../PackMigrator/PackMigrator.java | 26 ++++++++ .../taichitweaks/PackMigrator/unzip.java | 45 +++++++++++++ .../taichitweaks/config/Configs.java | 5 +- .../taichitweaks/config/PackMigratorGui.java | 24 +++---- .../PlacementTweaksMixin.java | 64 +++++++++++++++++++ src/main/resources/taichi-tweaks.mixins.json | 1 + 6 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 src/main/java/org/taichiserver/taichitweaks/PackMigrator/PackMigrator.java create mode 100644 src/main/java/org/taichiserver/taichitweaks/PackMigrator/unzip.java create mode 100644 src/main/java/org/taichiserver/taichitweaks/mixins/restrictionPlacementOnNetherPortalSides/PlacementTweaksMixin.java diff --git a/src/main/java/org/taichiserver/taichitweaks/PackMigrator/PackMigrator.java b/src/main/java/org/taichiserver/taichitweaks/PackMigrator/PackMigrator.java new file mode 100644 index 0000000..b33d7eb --- /dev/null +++ b/src/main/java/org/taichiserver/taichitweaks/PackMigrator/PackMigrator.java @@ -0,0 +1,26 @@ +package org.taichiserver.taichitweaks.PackMigrator; + +import java.nio.file.Path; + +public class PackMigrator { + private static PackMigrator Process; + private Path newInstancePath; + private boolean processing; + public PackMigrator(Path path){ + this.newInstancePath = path; + this.processing = false; + } + public boolean execute(){ + if(Process.isProcessing()) return false; + this.processing = true; + Process = this; + + //unzip.init("",""); + + return true; + } + + public boolean isProcessing() { + return processing; + } +} diff --git a/src/main/java/org/taichiserver/taichitweaks/PackMigrator/unzip.java b/src/main/java/org/taichiserver/taichitweaks/PackMigrator/unzip.java new file mode 100644 index 0000000..661da5e --- /dev/null +++ b/src/main/java/org/taichiserver/taichitweaks/PackMigrator/unzip.java @@ -0,0 +1,45 @@ +package org.taichiserver.taichitweaks.PackMigrator; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class unzip { + public static boolean init(File zipfile, File target) { + target.mkdirs(); + + return unzipper(StandardCharsets.UTF_8, target, zipfile) || + unzipper(Charset.forName("MS932"), target, zipfile); + } + + private static Boolean unzipper(Charset charset, File target, File zipfile) { + try { + ZipInputStream zis = new ZipInputStream(new FileInputStream(zipfile), charset); + ZipEntry e; + while ((e = zis.getNextEntry()) != null) { + var dst = Paths.get(target.toString(), e.getName()); + if (e.isDirectory()) { + Files.createDirectories(dst); + } else { + Files.createDirectories(dst.getParent()); + Files.write(dst, zis.readAllBytes()); + } + //System.out.printf("inflating: %s%n", dst); + } + + zis.closeEntry(); + zis.close(); + } catch (IllegalArgumentException | IOException e) { + return false; + } + return true; + } +} diff --git a/src/main/java/org/taichiserver/taichitweaks/config/Configs.java b/src/main/java/org/taichiserver/taichitweaks/config/Configs.java index a0156a7..c3324ed 100644 --- a/src/main/java/org/taichiserver/taichitweaks/config/Configs.java +++ b/src/main/java/org/taichiserver/taichitweaks/config/Configs.java @@ -49,6 +49,8 @@ public static class Generic { public static ConfigBooleanHotkeyed GAMMA_OVERRIDE_FIX = new ConfigBooleanHotkeyed("gammaOverrideFix", false, "", "Fixes gamma override not applying when starting the game"); public static final ConfigBooleanHotkeyed DISABLE_MASSCRAFT_PLAYER_INVENTORY = new ConfigBooleanHotkeyed("disableMassCraftPlayerInventory", false, "", "disableMassCraftPlayerInventory"); + public static final ConfigBooleanHotkeyed DISABLE_PLACED_ON_PORTAL_SIDES = new ConfigBooleanHotkeyed("disablePlacedOnNetherPortalSides+", false, "", "disableMassCraftPlayerInventory"); + public static final ImmutableList OPTIONS = ImmutableList.of( OPEN_CONFIG_GUI, @@ -74,7 +76,8 @@ public static class Generic { //OVERLAY_LIGHTNING_ROD_RANGE, //OVERLAY_LIGHTNING_ROD_COLOR, GAMMA_OVERRIDE_FIX, - DISABLE_MASSCRAFT_PLAYER_INVENTORY + DISABLE_MASSCRAFT_PLAYER_INVENTORY, + DISABLE_PLACED_ON_PORTAL_SIDES ); } diff --git a/src/main/java/org/taichiserver/taichitweaks/config/PackMigratorGui.java b/src/main/java/org/taichiserver/taichitweaks/config/PackMigratorGui.java index 93f753d..9f3af52 100644 --- a/src/main/java/org/taichiserver/taichitweaks/config/PackMigratorGui.java +++ b/src/main/java/org/taichiserver/taichitweaks/config/PackMigratorGui.java @@ -26,7 +26,7 @@ public void initGui() { int x = 12; int y = 50; - this.addLabel(x, y, 100, 20, 0xFFFFFFFF, ""); + this.addLabel(x, y, 100, 20, 0xFFFFFFFF, "folder"); y += 20; @@ -36,7 +36,7 @@ public void initGui() { y += 40; - ButtonListenerChangeMenu.ButtonType buttonType = ButtonListenerChangeMenu.ButtonType.LOAD_PACK; + ButtonListenerChangeMenu.ButtonType buttonType = ButtonListenerChangeMenu.ButtonType.SUBMIT; ButtonGeneric button = new ButtonGeneric(x, y, 100, 20, buttonType.getDisplayName()); this.addButton(button, new ButtonListenerChangeMenu(buttonType, this)); } @@ -45,35 +45,27 @@ public static class ButtonListenerChangeMenu implements IButtonActionListener { private final ButtonType type; @Nullable private final Screen parent; - public ButtonListenerChangeMenu(ButtonType type, @Nullable Screen parent) { this.type = type; this.parent = parent; } - @Override public void actionPerformedWithButton(ButtonBase buttonBase, int i) { - //LOGGER.info("actionPerformedWithButton(): {}, {}", this.type.getDisplayName(), i); - GuiBase gui = null; + if (this.type == ButtonType.SUBMIT) { + System.out.println(TextFieldListener.INSTANCE_PATH); - if (Objects.requireNonNull(this.type) == ButtonType.LOAD_PACK) { // PackManager modpack = new PackManager(TextFieldListener.URL); // PackManager.packManagerThread thread = new PackManager.packManagerThread(modpack); // thread.start(); return; } - - if (gui != null) { - gui.setParent(this.parent); - GuiBase.openGui(gui); - } } public enum ButtonType { - LOAD_PACK ("Load"); + SUBMIT ("Submit"); private final String label; - private ButtonType(String labelKey) { + ButtonType(String labelKey) { this.label = labelKey; } @@ -89,10 +81,10 @@ public String getDisplayName() { public static class TextFieldListener implements ITextFieldListener { - public static String URL = ""; + public static String INSTANCE_PATH = ""; @Override public boolean onTextChange(GuiTextFieldGeneric textField) { - URL = textField.getText(); + INSTANCE_PATH = textField.getText(); return false; } } diff --git a/src/main/java/org/taichiserver/taichitweaks/mixins/restrictionPlacementOnNetherPortalSides/PlacementTweaksMixin.java b/src/main/java/org/taichiserver/taichitweaks/mixins/restrictionPlacementOnNetherPortalSides/PlacementTweaksMixin.java new file mode 100644 index 0000000..519092b --- /dev/null +++ b/src/main/java/org/taichiserver/taichitweaks/mixins/restrictionPlacementOnNetherPortalSides/PlacementTweaksMixin.java @@ -0,0 +1,64 @@ +package org.taichiserver.taichitweaks.mixins.restrictionPlacementOnNetherPortalSides; + +import fi.dy.masa.malilib.util.PositionUtils; +import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.NetherPortalBlock; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.taichiserver.taichitweaks.config.Configs; + +@Mixin(PlacementTweaks.class) +public class PlacementTweaksMixin { + @Inject(method = "tryPlaceBlock", at = @At("HEAD"), cancellable = true) + private static void tryPlaceBlock(ClientPlayerInteractionManager controller, ClientPlayerEntity player, ClientWorld world, BlockPos posIn, Direction sideIn, Direction sideRotatedIn, float playerYaw, Vec3d hitVec, Hand hand, PositionUtils.HitPart hitPart, boolean isFirstClick, CallbackInfoReturnable cir){ + if(!Configs.Generic.DISABLE_PLACED_ON_PORTAL_SIDES.getBooleanValue()) return; + + // if (!Configs.disablePlacedOnNetherPortalSides.getBool()) { + // return; + // } + if (checkNeighbors(world, posIn.north(), Direction.Axis.Z, cir)) { + return; + } + if (checkNeighbors(world, posIn.south(), Direction.Axis.Z, cir)) { + return; + } + if (checkNeighbors(world, posIn.east(), Direction.Axis.X, cir)) { + return; + } + if (checkNeighbors(world, posIn.west(), Direction.Axis.X, cir)) { + return; + } + if (checkNeighbors(world, posIn.up(), Direction.Axis.Y, cir)) { + return; + } + if (checkNeighbors(world, posIn.down(), Direction.Axis.Y, cir)) { + return; + } + } + private static boolean checkNeighbors(World world, BlockPos blockPos, Direction.Axis axis, CallbackInfoReturnable cir) { + BlockState blockState = world.getBlockState(blockPos); + if (blockState.isOf(Blocks.NETHER_PORTAL)) { + if (Direction.Axis.Y == axis || blockState.get(NetherPortalBlock.AXIS) == axis) { + cir.setReturnValue(ActionResult.CONSUME); + cir.cancel(); + //sendRestrictionMessage("placed on Nether Portal sides"); + System.out.println("placed on Nether Portal sides"); + return true; + } + } + return false; + } +} diff --git a/src/main/resources/taichi-tweaks.mixins.json b/src/main/resources/taichi-tweaks.mixins.json index 8200b36..d79ff10 100644 --- a/src/main/resources/taichi-tweaks.mixins.json +++ b/src/main/resources/taichi-tweaks.mixins.json @@ -15,6 +15,7 @@ "schemBlockPlacementRestcintionSmartCheck.LooseCaseCheckerMixin", "schemBlockPlacementRestcintionSmartCheck.PlacementRestrictorMixin", "schemBlockPlacementRestcintionSmartCheck.SchematicBlockPickerMixin", + "restrictionPlacementOnNetherPortalSides.PlacementTweaksMixin", "selectiveEntityRendering.WorldRendererMixin" ], "injectors": {