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

Commit a85f675

Browse files
committed
[new] disablePlacedOnNetherPortalSides+
# New + disablePlacedOnNetherPortalSides
1 parent c8c4f11 commit a85f675

File tree

6 files changed

+148
-17
lines changed

6 files changed

+148
-17
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.taichiserver.taichitweaks.PackMigrator;
2+
3+
import java.nio.file.Path;
4+
5+
public class PackMigrator {
6+
private static PackMigrator Process;
7+
private Path newInstancePath;
8+
private boolean processing;
9+
public PackMigrator(Path path){
10+
this.newInstancePath = path;
11+
this.processing = false;
12+
}
13+
public boolean execute(){
14+
if(Process.isProcessing()) return false;
15+
this.processing = true;
16+
Process = this;
17+
18+
//unzip.init("","");
19+
20+
return true;
21+
}
22+
23+
public boolean isProcessing() {
24+
return processing;
25+
}
26+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.taichiserver.taichitweaks.PackMigrator;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.net.URL;
7+
import java.nio.charset.Charset;
8+
import java.nio.charset.StandardCharsets;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
12+
import java.util.zip.ZipEntry;
13+
import java.util.zip.ZipInputStream;
14+
15+
public class unzip {
16+
public static boolean init(File zipfile, File target) {
17+
target.mkdirs();
18+
19+
return unzipper(StandardCharsets.UTF_8, target, zipfile) ||
20+
unzipper(Charset.forName("MS932"), target, zipfile);
21+
}
22+
23+
private static Boolean unzipper(Charset charset, File target, File zipfile) {
24+
try {
25+
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipfile), charset);
26+
ZipEntry e;
27+
while ((e = zis.getNextEntry()) != null) {
28+
var dst = Paths.get(target.toString(), e.getName());
29+
if (e.isDirectory()) {
30+
Files.createDirectories(dst);
31+
} else {
32+
Files.createDirectories(dst.getParent());
33+
Files.write(dst, zis.readAllBytes());
34+
}
35+
//System.out.printf("inflating: %s%n", dst);
36+
}
37+
38+
zis.closeEntry();
39+
zis.close();
40+
} catch (IllegalArgumentException | IOException e) {
41+
return false;
42+
}
43+
return true;
44+
}
45+
}

src/main/java/org/taichiserver/taichitweaks/config/Configs.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static class Generic {
4949
public static ConfigBooleanHotkeyed GAMMA_OVERRIDE_FIX = new ConfigBooleanHotkeyed("gammaOverrideFix", false, "", "Fixes gamma override not applying when starting the game");
5050

5151
public static final ConfigBooleanHotkeyed DISABLE_MASSCRAFT_PLAYER_INVENTORY = new ConfigBooleanHotkeyed("disableMassCraftPlayerInventory", false, "", "disableMassCraftPlayerInventory");
52+
public static final ConfigBooleanHotkeyed DISABLE_PLACED_ON_PORTAL_SIDES = new ConfigBooleanHotkeyed("disablePlacedOnNetherPortalSides+", false, "", "disableMassCraftPlayerInventory");
53+
5254

5355
public static final ImmutableList<IConfigBase> OPTIONS = ImmutableList.of(
5456
OPEN_CONFIG_GUI,
@@ -74,7 +76,8 @@ public static class Generic {
7476
//OVERLAY_LIGHTNING_ROD_RANGE,
7577
//OVERLAY_LIGHTNING_ROD_COLOR,
7678
GAMMA_OVERRIDE_FIX,
77-
DISABLE_MASSCRAFT_PLAYER_INVENTORY
79+
DISABLE_MASSCRAFT_PLAYER_INVENTORY,
80+
DISABLE_PLACED_ON_PORTAL_SIDES
7881
);
7982
}
8083

src/main/java/org/taichiserver/taichitweaks/config/PackMigratorGui.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void initGui() {
2626
int x = 12;
2727
int y = 50;
2828

29-
this.addLabel(x, y, 100, 20, 0xFFFFFFFF, "");
29+
this.addLabel(x, y, 100, 20, 0xFFFFFFFF, "folder");
3030

3131
y += 20;
3232

@@ -36,7 +36,7 @@ public void initGui() {
3636

3737
y += 40;
3838

39-
ButtonListenerChangeMenu.ButtonType buttonType = ButtonListenerChangeMenu.ButtonType.LOAD_PACK;
39+
ButtonListenerChangeMenu.ButtonType buttonType = ButtonListenerChangeMenu.ButtonType.SUBMIT;
4040
ButtonGeneric button = new ButtonGeneric(x, y, 100, 20, buttonType.getDisplayName());
4141
this.addButton(button, new ButtonListenerChangeMenu(buttonType, this));
4242
}
@@ -45,35 +45,27 @@ public static class ButtonListenerChangeMenu implements IButtonActionListener {
4545
private final ButtonType type;
4646
@Nullable
4747
private final Screen parent;
48-
4948
public ButtonListenerChangeMenu(ButtonType type, @Nullable Screen parent) {
5049
this.type = type;
5150
this.parent = parent;
5251
}
53-
5452
@Override
5553
public void actionPerformedWithButton(ButtonBase buttonBase, int i) {
56-
//LOGGER.info("actionPerformedWithButton(): {}, {}", this.type.getDisplayName(), i);
57-
GuiBase gui = null;
54+
if (this.type == ButtonType.SUBMIT) {
55+
System.out.println(TextFieldListener.INSTANCE_PATH);
5856

59-
if (Objects.requireNonNull(this.type) == ButtonType.LOAD_PACK) {
6057
// PackManager modpack = new PackManager(TextFieldListener.URL);
6158
// PackManager.packManagerThread thread = new PackManager.packManagerThread(modpack);
6259
// thread.start();
6360
return;
6461
}
65-
66-
if (gui != null) {
67-
gui.setParent(this.parent);
68-
GuiBase.openGui(gui);
69-
}
7062
}
7163

7264
public enum ButtonType {
73-
LOAD_PACK ("Load");
65+
SUBMIT ("Submit");
7466
private final String label;
7567

76-
private ButtonType(String labelKey) {
68+
ButtonType(String labelKey) {
7769
this.label = labelKey;
7870
}
7971

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

9082

9183
public static class TextFieldListener implements ITextFieldListener<GuiTextFieldGeneric> {
92-
public static String URL = "";
84+
public static String INSTANCE_PATH = "";
9385
@Override
9486
public boolean onTextChange(GuiTextFieldGeneric textField) {
95-
URL = textField.getText();
87+
INSTANCE_PATH = textField.getText();
9688
return false;
9789
}
9890
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.taichiserver.taichitweaks.mixins.restrictionPlacementOnNetherPortalSides;
2+
3+
import fi.dy.masa.malilib.util.PositionUtils;
4+
import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.Blocks;
7+
import net.minecraft.block.NetherPortalBlock;
8+
import net.minecraft.client.network.ClientPlayerEntity;
9+
import net.minecraft.client.network.ClientPlayerInteractionManager;
10+
import net.minecraft.client.world.ClientWorld;
11+
import net.minecraft.util.ActionResult;
12+
import net.minecraft.util.Hand;
13+
import net.minecraft.util.math.BlockPos;
14+
import net.minecraft.util.math.Direction;
15+
import net.minecraft.util.math.Vec3d;
16+
import net.minecraft.world.World;
17+
import org.spongepowered.asm.mixin.Mixin;
18+
import org.spongepowered.asm.mixin.injection.At;
19+
import org.spongepowered.asm.mixin.injection.Inject;
20+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
21+
import org.taichiserver.taichitweaks.config.Configs;
22+
23+
@Mixin(PlacementTweaks.class)
24+
public class PlacementTweaksMixin {
25+
@Inject(method = "tryPlaceBlock", at = @At("HEAD"), cancellable = true)
26+
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){
27+
if(!Configs.Generic.DISABLE_PLACED_ON_PORTAL_SIDES.getBooleanValue()) return;
28+
29+
// if (!Configs.disablePlacedOnNetherPortalSides.getBool()) {
30+
// return;
31+
// }
32+
if (checkNeighbors(world, posIn.north(), Direction.Axis.Z, cir)) {
33+
return;
34+
}
35+
if (checkNeighbors(world, posIn.south(), Direction.Axis.Z, cir)) {
36+
return;
37+
}
38+
if (checkNeighbors(world, posIn.east(), Direction.Axis.X, cir)) {
39+
return;
40+
}
41+
if (checkNeighbors(world, posIn.west(), Direction.Axis.X, cir)) {
42+
return;
43+
}
44+
if (checkNeighbors(world, posIn.up(), Direction.Axis.Y, cir)) {
45+
return;
46+
}
47+
if (checkNeighbors(world, posIn.down(), Direction.Axis.Y, cir)) {
48+
return;
49+
}
50+
}
51+
private static boolean checkNeighbors(World world, BlockPos blockPos, Direction.Axis axis, CallbackInfoReturnable<ActionResult> cir) {
52+
BlockState blockState = world.getBlockState(blockPos);
53+
if (blockState.isOf(Blocks.NETHER_PORTAL)) {
54+
if (Direction.Axis.Y == axis || blockState.get(NetherPortalBlock.AXIS) == axis) {
55+
cir.setReturnValue(ActionResult.CONSUME);
56+
cir.cancel();
57+
//sendRestrictionMessage("placed on Nether Portal sides");
58+
System.out.println("placed on Nether Portal sides");
59+
return true;
60+
}
61+
}
62+
return false;
63+
}
64+
}

src/main/resources/taichi-tweaks.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"schemBlockPlacementRestcintionSmartCheck.LooseCaseCheckerMixin",
1616
"schemBlockPlacementRestcintionSmartCheck.PlacementRestrictorMixin",
1717
"schemBlockPlacementRestcintionSmartCheck.SchematicBlockPickerMixin",
18+
"restrictionPlacementOnNetherPortalSides.PlacementTweaksMixin",
1819
"selectiveEntityRendering.WorldRendererMixin"
1920
],
2021
"injectors": {

0 commit comments

Comments
 (0)