Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
[new] disablePlacedOnNetherPortalSides+
Browse files Browse the repository at this point in the history
# New
+ disablePlacedOnNetherPortalSides
  • Loading branch information
topi-banana committed Apr 8, 2024
1 parent c8c4f11 commit a85f675
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IConfigBase> OPTIONS = ImmutableList.of(
OPEN_CONFIG_GUI,
Expand All @@ -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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
Expand All @@ -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;
}

Expand All @@ -89,10 +81,10 @@ public String getDisplayName() {


public static class TextFieldListener implements ITextFieldListener<GuiTextFieldGeneric> {
public static String URL = "";
public static String INSTANCE_PATH = "";
@Override
public boolean onTextChange(GuiTextFieldGeneric textField) {
URL = textField.getText();
INSTANCE_PATH = textField.getText();
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ActionResult> 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<ActionResult> 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;
}
}
1 change: 1 addition & 0 deletions src/main/resources/taichi-tweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"schemBlockPlacementRestcintionSmartCheck.LooseCaseCheckerMixin",
"schemBlockPlacementRestcintionSmartCheck.PlacementRestrictorMixin",
"schemBlockPlacementRestcintionSmartCheck.SchematicBlockPickerMixin",
"restrictionPlacementOnNetherPortalSides.PlacementTweaksMixin",
"selectiveEntityRendering.WorldRendererMixin"
],
"injectors": {
Expand Down

0 comments on commit a85f675

Please sign in to comment.