Skip to content

Commit

Permalink
Fix: accidentally deleted display mode tool item
Browse files Browse the repository at this point in the history
Add: A config disable teleport to the end
Bump version to 1.4.32

Took 49 minutes
  • Loading branch information
xkball committed Nov 21, 2024
1 parent c28da7e commit 0c06333
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod_name=Power Tool
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPL-3.0
# The mod version. See https://semver.org/
mod_version=1.4.31
mod_version=1.4.32
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/teacon/powertool/PowerToolConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
public class PowerToolConfig {

public static ModConfigSpec.ConfigValue<String> motdContent;

public static ModConfigSpec.ConfigValue<Boolean> disableTeleportToEnd;

public static void init(ModContainer container) {
var builder = new ModConfigSpec.Builder();
motdContent = builder
.comment("Message-of-the-day content.")
.define("motd","");
disableTeleportToEnd = builder.comment("Disable the access of the End.").define("disableTeleportToEnd", true);
container.registerConfig(ModConfig.Type.SERVER, builder.build());
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/teacon/powertool/PowerToolEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.world.level.chunk.LevelChunk;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.EntityTravelToDimensionEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.level.BlockEvent;
import net.neoforged.neoforge.event.level.ChunkWatchEvent;
import net.neoforged.neoforge.event.level.ExplosionEvent;
Expand Down Expand Up @@ -40,7 +42,7 @@ public static void on(ChunkWatchEvent.Sent event) {
}

@SubscribeEvent
public static void on(ExplosionEvent.Detonate event) {
public static void onExplosion(ExplosionEvent.Detonate event) {
Map<ChunkPos, List<BlockPos>> map = new HashMap<>();
for (BlockPos affectedBlock : event.getAffectedBlocks()) {
map.computeIfAbsent(new ChunkPos(affectedBlock), it -> new ArrayList<>())
Expand Down Expand Up @@ -118,7 +120,7 @@ private static void removeDisplayMode(
}

@SubscribeEvent
public static void on(BlockEvent.BreakEvent event) {
public static void onBlockBreak(BlockEvent.BreakEvent event) {
ServerLevel level = (ServerLevel) event.getLevel();
BlockPos pos = event.getPos();
removeDisplayMode(
Expand All @@ -127,4 +129,11 @@ public static void on(BlockEvent.BreakEvent event) {
(ServerPlayer) event.getPlayer()
);
}

@SubscribeEvent
public static void onChangeDimension(EntityTravelToDimensionEvent event) {
if(event.getDimension().equals(ServerLevel.END) && PowerToolConfig.disableTeleportToEnd.get()){
event.setCanceled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.teacon.powertool.block.entity.RegisterBlockEntity;
import org.teacon.powertool.client.gui.RegisterScreen;
import org.teacon.powertool.client.gui.TrashCanWithContainerScreen;
import org.teacon.powertool.client.renders.FenceKnotRenderer;
import org.teacon.powertool.client.renders.entity.FenceKnotRenderer;
import org.teacon.powertool.client.renders.TempleRenderer;
import org.teacon.powertool.client.renders.entity.MartingCarEntityRenderer;
import org.teacon.powertool.client.renders.entity.model.MartingCarEntityModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.teacon.powertool.client.renders;
package org.teacon.powertool.client.renders.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public boolean isFoil(ItemStack stack) {
AV_MANGROVE_BOAT = ITEMS.register("auto_vanish_mangrove_boat",() -> new AutoVanishBoatItem(Boat.Type.MANGROVE));
AV_BAMBOO_RAFT = ITEMS.register("auto_vanish_bamboo_raft",() -> new AutoVanishBoatItem(Boat.Type.BAMBOO));
AV_MINE_CART = ITEMS.register("auto_vanish_minecart",() -> new AutoVanishMinecartItem(new Item.Properties()));
DISPLAY_MODE_TOOL = ITEMS.register("display_mode_tool", () -> new DisplayModeToolItem(new Item.Properties()));
CREATIVE_MODE_TABS.register(bus);
PowerToolDataComponents.DATA_COMPONENTS.register(bus);
ARMOR_MATERIAL.register(bus);
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/teacon/powertool/mixin/MixinEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.teacon.powertool.mixin;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.RelativeMovement;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.teacon.powertool.PowerToolConfig;

import java.util.Set;

@Mixin(Entity.class)
public abstract class MixinEntity {

@Shadow public abstract Level level();

@Inject(method = "teleportTo(Lnet/minecraft/server/level/ServerLevel;DDDLjava/util/Set;FF)Z", at = @At("HEAD"),cancellable = true)
public void onTP(ServerLevel level, double x, double y, double z, Set<RelativeMovement> relativeMovements, float yRot, float xRot, CallbackInfoReturnable<Boolean> cir){
if(level != this.level() && level.dimension() == ServerLevel.END && PowerToolConfig.disableTeleportToEnd.get()){
cir.setReturnValue(true);
cir.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/powertool.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"CommandsMixin",
"CommandSourceStackMixin",
"MixinArmorStand",
"MixinEntity",
"MixinItemFrame",
"ServerGamePacketListenerImplMixin",
"ServerPlayerMixin"
Expand Down

0 comments on commit 0c06333

Please sign in to comment.