diff --git a/src/main/generated/.cache/684a20b6ff997062e678180dff3c571444f18410 b/src/main/generated/.cache/684a20b6ff997062e678180dff3c571444f18410 new file mode 100644 index 0000000..9dd78f3 --- /dev/null +++ b/src/main/generated/.cache/684a20b6ff997062e678180dff3c571444f18410 @@ -0,0 +1,2 @@ +// 1.21 2024-07-21T05:39:39.9208483 MITEequilibrium/Language (zh_cn) +582122e265b4c630127b356fab100a52fa8e8686 assets\miteequilibrium\lang\zh_cn.json diff --git a/src/main/generated/.cache/8ce55c2d46c78681d7eebf7cad72e9c2de67a045 b/src/main/generated/.cache/8ce55c2d46c78681d7eebf7cad72e9c2de67a045 deleted file mode 100644 index c480065..0000000 --- a/src/main/generated/.cache/8ce55c2d46c78681d7eebf7cad72e9c2de67a045 +++ /dev/null @@ -1,40 +0,0 @@ -// 1.21 2024-07-20T05:31:11.5795046 MITEequilibrium/Model Definitions -e3c5f07b3b54f7f6eea5fa00ed1823c80c519c14 assets\miteequilibrium\models\item\mithril_ore.json -dccf3bc904ca2659a45b1924b2b5dd8188a0ef27 assets\miteequilibrium\blockstates\gold_block.json -6aa639f29ea4e247aa818822152bded3ec0a0ef4 assets\miteequilibrium\blockstates\mithril_block.json -a3aa407225058101f487dc2d69a2323cff577294 assets\miteequilibrium\models\block\silver_ore.json -6deb1bf7820e58ac89e2411f78d6925861ce3cf5 assets\miteequilibrium\models\item\silver_nugget.json -46bfd511f5c0f2f1afc5d77cc9dbd0144377d522 assets\miteequilibrium\models\item\mithril_nugget.json -15c22b2ffa7c2dda180ffcadd87e26e7542db7c5 assets\miteequilibrium\blockstates\silver_ore.json -c6d473a5f7fb2189afdb6f6040f9449d6355e4c9 assets\miteequilibrium\models\block\copper_block.json -904f5b6be17869c8e9b6bc8b25fd229e15163b7e assets\miteequilibrium\models\block\gold_block.json -8a2002cdb9a1c1088eac1973807e01b3db6a8fc7 assets\miteequilibrium\blockstates\gold_ore.json -37a416ce5d40380df1321db7e7272faa4858973c assets\miteequilibrium\models\item\copper_nugget.json -cabffc3950e51bb500254bcd2a47053341050615 assets\miteequilibrium\blockstates\copper_block.json -88b2592c9e57bdfd9ff42721aee23f1879810fcc assets\miteequilibrium\models\block\gold_ore.json -1c76eeb8e434a4959a45a985f71e33bee98cef47 assets\miteequilibrium\blockstates\ancient_metal_block.json -3f58a7975e017e6f5e0aefeb9d6a28b58502a0d5 assets\miteequilibrium\models\item\ancient_metal_block.json -acd36f849f7545835bcd7c024a9c9c54e8d9e1c0 assets\miteequilibrium\models\item\gold_ore.json -d7f20ad7d635c2505ea669d0de4c217d2ea182ef assets\miteequilibrium\models\block\mithril_ore.json -c877c93eb6dc6b7db3a9f39f1d1a04de0e86dff7 assets\miteequilibrium\models\item\copper_ore.json -dd63bef5ea7f82d06c0c162106a2c5a9a1efee37 assets\miteequilibrium\blockstates\mithril_ore.json -d23ecf679ccfafb2cf9b62c3aec46729ba685fa0 assets\miteequilibrium\models\item\ancient_metal_nugget.json -ddd198fb1a94b797709f8a13de207a162ca83920 assets\miteequilibrium\blockstates\silver_block.json -3a0550b68023aeb8d1f2e05c3bc8b1683a5ec457 assets\miteequilibrium\models\block\copper_ore.json -daac16a0ec15119c4965bf7b42998bf7c30f46fc assets\miteequilibrium\blockstates\adamantium_ore.json -17f4433121884390a787d54ad0545574cd77e44e assets\miteequilibrium\models\item\adamantium_ore.json -ebbf1665c7578e664e339d1379497b8e68ceb9f9 assets\miteequilibrium\blockstates\adamantium_block.json -9ec74d6fe87cfb75b15b03a4686b020726e9a03a assets\miteequilibrium\models\item\adamantium_block.json -47b83ac7ffdcd4f349e7b9d2c9ecbaa7296cd2c1 assets\miteequilibrium\models\block\adamantium_ore.json -7167477d055461b8c0d0dd1ddff296c3e8739c1b assets\miteequilibrium\models\item\gold_nugget.json -71230db95fb36a59ca886b42a8578a7e5289f27e assets\miteequilibrium\models\block\mithril_block.json -9a8cfa18c20d09c688f214eb5e9fe03d14db7761 assets\miteequilibrium\models\item\gold_block.json -9c2092f86b72ce8167788a7d59bb2f6915f0caf6 assets\miteequilibrium\models\block\ancient_metal_block.json -f34fa81117489a9a66ea93f728f5f2bcbec9b953 assets\miteequilibrium\models\block\silver_block.json -e5733a090f394c136335c8aa0dc7e5083ef31458 assets\miteequilibrium\models\item\silver_ore.json -b834efa7e8d540313d35956439827b44a4cee03e assets\miteequilibrium\models\block\adamantium_block.json -72ccce82992032390968c1c5fd7bb5aba9f4b253 assets\miteequilibrium\models\item\silver_block.json -a4b0acfc4293fcf495f36a76bdda910db3f426ee assets\miteequilibrium\models\item\mithril_block.json -d918fe036accbdb8c8dad219ff5b3f769ac1b7ab assets\miteequilibrium\models\item\adamantium_nugget.json -5af9fa21466ac378f1f8783fc5934cb0e6c77eca assets\miteequilibrium\blockstates\copper_ore.json -8dc735515e111bfc53d1a0a639d4fb027e58abfe assets\miteequilibrium\models\item\copper_block.json diff --git a/src/main/java/com/equilibrium/MITEequilibriumDataGenerator.java b/src/main/java/com/equilibrium/MITEequilibriumDataGenerator.java index 7a18443..9a413d9 100644 --- a/src/main/java/com/equilibrium/MITEequilibriumDataGenerator.java +++ b/src/main/java/com/equilibrium/MITEequilibriumDataGenerator.java @@ -1,18 +1,17 @@ package com.equilibrium; +import com.equilibrium.gen.ModLanguageTranslatorZhCn; import com.equilibrium.gen.ModModelProvider; import com.equilibrium.gen.ModRecipeGenerator; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; -import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; -import net.minecraft.data.DataGenerator; public class MITEequilibriumDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator){ FabricDataGenerator.Pack pack=fabricDataGenerator.createPack(); // pack.addProvider(ModRecipeGenerator::new); - pack.addProvider(ModModelProvider::new); - +// pack.addProvider(ModModelProvider::new); + pack.addProvider(ModLanguageTranslatorZhCn::new); } } diff --git a/src/main/java/com/equilibrium/constant/ConstantString.java b/src/main/java/com/equilibrium/constant/ConstantString.java new file mode 100644 index 0000000..58535a6 --- /dev/null +++ b/src/main/java/com/equilibrium/constant/ConstantString.java @@ -0,0 +1,22 @@ +package com.equilibrium.constant; + + +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; +import com.equilibrium.MITEequilibrium; +import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries; +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; +import net.fabricmc.fabric.api.registry.FuelRegistry; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroups; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class ConstantString { + public static String TRANSPORT_TARGET1="You will transport to overworld"; + public static String TRANSPORT_TARGET2="You will transport to underworld"; + public static String TRANSPORT_TARGET3="You will transport to nether"; + +} diff --git a/src/main/java/com/equilibrium/gen/ModLanguageTranslatorZhCn.java b/src/main/java/com/equilibrium/gen/ModLanguageTranslatorZhCn.java new file mode 100644 index 0000000..dce328c --- /dev/null +++ b/src/main/java/com/equilibrium/gen/ModLanguageTranslatorZhCn.java @@ -0,0 +1,35 @@ +package com.equilibrium.gen; + +import com.equilibrium.block.ModBlocks; +import com.equilibrium.constant.ConstantString; +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; +import net.minecraft.registry.RegistryWrapper; + +import java.util.concurrent.CompletableFuture; + +public class ModLanguageTranslatorZhCn extends FabricLanguageProvider { + + + public ModLanguageTranslatorZhCn(FabricDataOutput dataOutput, CompletableFuture registryLookup) { + super(dataOutput,"zh_cn", registryLookup); + } + + /** + * Implement this method to register languages. + * + *

Call {@link TranslationBuilder#add(String, String)} to add a translation. + * + * @param registryLookup + * @param translationBuilder + */ + @Override + public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) { + translationBuilder.add(ConstantString.TRANSPORT_TARGET1,"该传送门会将你传送至主世界"); + translationBuilder.add(ConstantString.TRANSPORT_TARGET2,"该传送门会将你传送至地下世界"); + translationBuilder.add(ConstantString.TRANSPORT_TARGET3,"该传送门会将你传送至下界"); + + + + } +} diff --git a/src/main/java/com/equilibrium/mixin/NetherPortalBlockMixin.java b/src/main/java/com/equilibrium/mixin/NetherPortalBlockMixin.java index 0917529..18c64ab 100644 --- a/src/main/java/com/equilibrium/mixin/NetherPortalBlockMixin.java +++ b/src/main/java/com/equilibrium/mixin/NetherPortalBlockMixin.java @@ -1,17 +1,29 @@ package com.equilibrium.mixin; +import com.equilibrium.constant.ConstantString; +import com.equilibrium.util.ShouldSentText; +import com.mojang.brigadier.Message; +import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.block.NetherPortalBlock; import net.minecraft.block.Portal; +import net.minecraft.block.entity.VaultBlockEntity; +import net.minecraft.command.TranslatableBuiltInExceptions; import net.minecraft.enchantment.effect.AllOfEnchantmentEffects; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectUtil; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.message.SentMessage; +import net.minecraft.network.message.SignedMessage; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -26,12 +38,15 @@ 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.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Set; + + @Mixin(NetherPortalBlock.class) -public abstract class NetherPortalBlockMixin extends Block implements Portal { +public abstract class NetherPortalBlockMixin extends Block implements Portal{ @Shadow @Nullable protected abstract TeleportTarget getOrCreateExitPortalTarget(ServerWorld world, Entity entity, BlockPos pos, BlockPos scaledPos, boolean inNether, WorldBorder worldBorder); @@ -42,12 +57,84 @@ public NetherPortalBlockMixin(Settings settings) { super(settings); } + + + + + private static String getTeleportWorld(World world, Entity entity) { + + //获取目前的世界类型(访问注册方法) + RegistryKey registryKey = world.getRegistryKey(); + //传送后的世界类型 + RegistryKey teleport; + //避免空指针错误 + + if (registryKey == null) { + return "Not an illegal transportation"; + } else { + boolean atBottom = Math.abs(entity.getY()-world.getBottomY())<5; + if(world.getRegistryKey()==overworld && atBottom){ + teleport=underworld; + } else if (world.getRegistryKey()==overworld && !atBottom) { + teleport=overworld; + } else if (world.getRegistryKey()==underworld && !atBottom) { + teleport=overworld; + } else if (world.getRegistryKey()==underworld && atBottom) { + teleport=nether; + } else if(world.getRegistryKey()==nether){ + teleport=underworld; + } + else { + teleport=world.getRegistryKey(); + } + String worldType; + if(teleport==underworld){ + worldType=ConstantString.TRANSPORT_TARGET2; + } else if (teleport==overworld) { + worldType= ConstantString.TRANSPORT_TARGET1; + } else if (teleport==nether) { + worldType=ConstantString.TRANSPORT_TARGET3; + }else{ + worldType="Not an illegal transportation"; + } + + return worldType; + } + + + } + + + + + @Inject(method = "onEntityCollision",at = @At(value = "HEAD"),cancellable = true) + protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) { + ci.cancel(); + + if (entity.canUsePortals(false)) { + entity.tryUsePortal(this, pos); + if(ShouldSentText.count>=170) { + String teleport = getTeleportWorld(world, entity); + entity.sendMessage(Text.of(teleport)); + ShouldSentText.count=0; + } + + } + } + + + + + private static RegistryKey overworld = World.OVERWORLD; + private static RegistryKey nether = World.NETHER; + private static RegistryKey underworld = RegistryKey.of(RegistryKeys.WORLD, Identifier.of("miteequilibrium", "underworld")); + + + @Inject(method = "createTeleportTarget",at=@At(value = "HEAD"),cancellable = true) public void createTeleportTarget(ServerWorld world, Entity entity, BlockPos pos, CallbackInfoReturnable cir) { cir.cancel(); - RegistryKey overworld = World.OVERWORLD; - RegistryKey nether = World.NETHER; - RegistryKey underworld = RegistryKey.of(RegistryKeys.WORLD, Identifier.of("miteequilibrium", "underworld")); + //获取目前的世界类型(访问注册方法) RegistryKey registryKey = world.getRegistryKey(); //传送后的世界类型 @@ -65,7 +152,7 @@ public void createTeleportTarget(ServerWorld world, Entity entity, BlockPos pos, double d = DimensionType.getCoordinateScaleFactor(world.getDimension(), world.getDimension()); BlockPos blockPos = worldBorder.clamp(entity.getX() * d, entity.getY(), entity.getZ() * d); - boolean atBottom = Math.abs(blockPos.getY()-world.getBottomY())<5; + boolean atBottom = Math.abs(entity.getY()-world.getBottomY())<5; @@ -116,13 +203,19 @@ public void createTeleportTarget(ServerWorld world, Entity entity, BlockPos pos, return; } - + else{ + teleport=underworld; + } } else if (world.getRegistryKey()==underworld && !atBottom) { teleport=overworld; + + + } else if (world.getRegistryKey()==underworld && atBottom) { teleport=nether; } else if(world.getRegistryKey()==nether){ teleport=underworld; + } else { teleport=world.getRegistryKey(); @@ -130,6 +223,9 @@ public void createTeleportTarget(ServerWorld world, Entity entity, BlockPos pos, serverWorld=world.getServer().getWorld(teleport); + + //传送信息冷却 + ShouldSentText.count=-100; cir.setReturnValue(this.getOrCreateExitPortalTarget(serverWorld, entity, pos, blockPos, inNether, worldBorder)); }} diff --git a/src/main/java/com/equilibrium/mixin/NetherPortalMixin.java b/src/main/java/com/equilibrium/mixin/NetherPortalMixin.java index 3759595..190af1b 100644 --- a/src/main/java/com/equilibrium/mixin/NetherPortalMixin.java +++ b/src/main/java/com/equilibrium/mixin/NetherPortalMixin.java @@ -6,7 +6,10 @@ import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.BlockTags; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.CommandOutput; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.*; import net.minecraft.world.World; @@ -20,7 +23,44 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(NetherPortal.class) + + + + + + + public abstract class NetherPortalMixin { + + @Shadow + private BlockPos lowerCorner; + @Shadow + private int height; + @Shadow + @Final + private int width; + @Shadow + @Final + private WorldAccess world; + @Shadow + @Final + private Direction.Axis axis; + @Shadow + @Final + private Direction negativeDir; + + + + + + + + + + + + + // ///* 测试用 // @Inject(method = "getNewPortal",at = @At("HEAD")) diff --git a/src/main/java/com/equilibrium/mixin/PlayerEntityMixin.java b/src/main/java/com/equilibrium/mixin/PlayerEntityMixin.java index 6ade4b5..3243f2c 100644 --- a/src/main/java/com/equilibrium/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/equilibrium/mixin/PlayerEntityMixin.java @@ -1,9 +1,13 @@ package com.equilibrium.mixin; +import com.equilibrium.constant.ConstantString; import com.equilibrium.util.PlayerMaxHealthHelper; import com.equilibrium.util.PlayerMaxHungerHelper; +import com.equilibrium.util.ShouldSentText; import com.mojang.authlib.GameProfile; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.DefaultAttributeContainer; @@ -11,7 +15,10 @@ import net.minecraft.entity.player.HungerManager; import net.minecraft.entity.player.PlayerAbilities; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.message.SentMessage; +import net.minecraft.network.message.SignedMessage; import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.Difficulty; @@ -42,7 +49,6 @@ public void PlayerEntity(World world, BlockPos pos, float yaw, GameProfile gameP @Inject(method = "jump", at = @At("TAIL")) public void jump(CallbackInfo ci) { - } @@ -73,6 +79,10 @@ public void jump(CallbackInfo ci) { @Shadow public abstract boolean isCreative(); + @Shadow public abstract void sendMessage(Text message, boolean overlay); + + @Shadow public abstract void tickMovement(); + //调用CallbackInfo类,修改返回值 //以下是修改方块交互距离 @Inject(method = "getBlockInteractionRange", at = @At("HEAD"), cancellable = true) @@ -150,6 +160,7 @@ public void refreshPlayerFoodLevelAndMaxHealth(){ @Inject(method = "addExperienceLevels", at = @At("HEAD"), cancellable = true) public void addExperienceLevels(int levels, CallbackInfo ci) { + //触发器,用作增加经验值的后续处理,比如增加生命值和饥饿度等 //除了初始化会增加上限之外,只有该方法才能增加上限值 ci.cancel(); @@ -176,6 +187,16 @@ public void addExperienceLevels(int levels, CallbackInfo ci) { public void canFoodHeal(CallbackInfoReturnable cir){ cir.setReturnValue(false); } + + + + + @Inject(method = "tick",at = @At("HEAD")) + public void tick(CallbackInfo ci) { + ShouldSentText.count++; + } + + @Inject(method = "tickMovement",at = @At("HEAD")) public void tickMovement(CallbackInfo ci){ //刷新上限值,和Hud保持同步,都是1s20次刷新 @@ -191,6 +212,7 @@ public void tickMovement(CallbackInfo ci){ } + } diff --git a/src/main/java/com/equilibrium/mixin/PortalForcerMixin.java b/src/main/java/com/equilibrium/mixin/PortalForcerMixin.java index 6c63d09..356fa79 100644 --- a/src/main/java/com/equilibrium/mixin/PortalForcerMixin.java +++ b/src/main/java/com/equilibrium/mixin/PortalForcerMixin.java @@ -15,7 +15,7 @@ import net.minecraft.world.poi.PointOfInterest; import net.minecraft.world.poi.PointOfInterestStorage; import net.minecraft.world.poi.PointOfInterestType; -import net.minecraft.world.poi.PointOfInterestTypes; + import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -37,10 +37,7 @@ public abstract class PortalForcerMixin { @Final @Shadow private ServerWorld world; - @Inject(method = "getPortalPos",at = @At("TAIL"),cancellable = true) - public void getPortalPos(BlockPos pos, boolean destIsNether, WorldBorder worldBorder, CallbackInfoReturnable> cir) { - System.out.println(cir.getReturnValue()); - } + // @Inject(method = "createPortal",at = @At("HEAD")) // public void createPortal(BlockPos pos, Direction.Axis axis, CallbackInfoReturnable> cir) { // System.out.println("getPortalPos"); diff --git a/src/main/java/com/equilibrium/mixin/render/DebugHudMixin.java b/src/main/java/com/equilibrium/mixin/render/DebugHudMixin.java new file mode 100644 index 0000000..7b1d98a --- /dev/null +++ b/src/main/java/com/equilibrium/mixin/render/DebugHudMixin.java @@ -0,0 +1,319 @@ +package com.equilibrium.mixin.render; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.mojang.blaze3d.platform.GlDebugInfo; +import com.mojang.datafixers.DataFixUtils; +import it.unimi.dsi.fastutil.longs.LongSet; +import it.unimi.dsi.fastutil.longs.LongSets; +import net.minecraft.SharedConstants; +import net.minecraft.client.ClientBrandRetriever; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.DebugHud; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.ClientConnection; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.server.ServerTickManager; +import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.Util; +import net.minecraft.util.math.*; +import net.minecraft.world.*; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.tick.TickManager; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +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.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.*; +import java.util.concurrent.CompletableFuture; + +@Mixin(DebugHud.class) + +public abstract class DebugHudMixin { + + @Shadow + @Final + private MinecraftClient client; +@Shadow + private boolean showDebugHud; +@Shadow + private boolean renderingChartVisible; +@Shadow + private boolean renderingAndTickChartsVisible; +@Shadow + private boolean packetSizeAndPingChartsVisible; + + +@Shadow +@Final + private TextRenderer textRenderer; + + + + + + + + + + + @Shadow + private ChunkPos pos; + @Shadow + private CompletableFuture chunkFuture; + @Shadow + private WorldChunk chunk; + + + + public void resetChunk() { + this.chunkFuture = null; + this.chunk = null; + } + + + private World getWorld() { + return DataFixUtils.orElse( + Optional.ofNullable(this.client.getServer()).flatMap(server -> Optional.ofNullable(server.getWorld(this.client.world.getRegistryKey()))), this.client.world + ); + } + + private String getServerWorldDebugString() { + ServerWorld serverWorld = this.getServerWorld(); + return serverWorld != null ? serverWorld.asString() : null; + } + + @Nullable + private ServerWorld getServerWorld() { + IntegratedServer integratedServer = this.client.getServer(); + return integratedServer != null ? integratedServer.getWorld(this.client.world.getRegistryKey()) : null; + } + + private WorldChunk getClientChunk() { + if (this.chunk == null) { + this.chunk = this.client.world.getChunk(this.pos.x, this.pos.z); + } + + return this.chunk; + } + + @Nullable + private WorldChunk getChunk() { + if (this.chunkFuture == null) { + ServerWorld serverWorld = this.getServerWorld(); + if (serverWorld == null) { + return null; + } + + this.chunkFuture = serverWorld.getChunkManager() + .getChunkFutureSyncOnMainThread(this.pos.x, this.pos.z, ChunkStatus.FULL, false) + .thenApply(optionalChunk -> (WorldChunk)optionalChunk.orElse(null)); + } + + return (WorldChunk)this.chunkFuture.getNow(null); + } + @Shadow + private static final Map HEIGHT_MAP_TYPES = Util.make(new EnumMap(Heightmap.Type.class), types -> { + types.put(Heightmap.Type.WORLD_SURFACE_WG, "SW"); + types.put(Heightmap.Type.WORLD_SURFACE, "S"); + types.put(Heightmap.Type.OCEAN_FLOOR_WG, "OW"); + types.put(Heightmap.Type.OCEAN_FLOOR, "O"); + types.put(Heightmap.Type.MOTION_BLOCKING, "M"); + types.put(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, "ML"); + }); + + + @Shadow + private static String getBiomeString(RegistryEntry biome) { + return biome.getKeyOrValue().map(biomeKey -> biomeKey.getValue().toString(), biome_ -> "[unregistered " + biome_ + "]"); + } + + public List getLeftText() { + + IntegratedServer integratedServer = this.client.getServer(); + ClientPlayNetworkHandler clientPlayNetworkHandler = this.client.getNetworkHandler(); + ClientConnection clientConnection = clientPlayNetworkHandler.getConnection(); + float f = clientConnection.getAveragePacketsSent(); + float g = clientConnection.getAveragePacketsReceived(); + TickManager tickManager = this.getWorld().getTickManager(); + String string; + if (tickManager.isStepping()) { + string = " (frozen - stepping)"; + } else if (tickManager.isFrozen()) { + string = " (frozen)"; + } else { + string = ""; + } + + String string3; + if (integratedServer != null) { + ServerTickManager serverTickManager = integratedServer.getTickManager(); + boolean bl = serverTickManager.isSprinting(); + if (bl) { + string = " (sprinting)"; + } + + String string2 = bl ? "-" : String.format(Locale.ROOT, "%.1f", tickManager.getMillisPerTick()); + string3 = String.format(Locale.ROOT, "Integrated server @ %.1f/%s ms%s, %.0f tx, %.0f rx", integratedServer.getAverageTickTime(), string2, string, f, g); + } else { + string3 = String.format(Locale.ROOT, "\"%s\" server%s, %.0f tx, %.0f rx", clientPlayNetworkHandler.getBrand(), string, f, g); + } + + BlockPos blockPos = this.client.getCameraEntity().getBlockPos(); + if (this.client.hasReducedDebugInfo()) { + return Lists.newArrayList( + "Minecraft " + SharedConstants.getGameVersion().getName() + " (" + this.client.getGameVersion() + "/" + ClientBrandRetriever.getClientModName() + ")", + this.client.fpsDebugString, + string3, + this.client.worldRenderer.getChunksDebugString(), + this.client.worldRenderer.getEntitiesDebugString(), + "P: " + this.client.particleManager.getDebugString() + ". T: " + this.client.world.getRegularEntityCount(), + this.client.world.asString(), + "", + String.format(Locale.ROOT, "Chunk-relative: %d %d %d", blockPos.getX() & 15, blockPos.getY() & 15, blockPos.getZ() & 15) + ); + } else { + World world = this.getWorld(); + LongSet longSet = (LongSet)(world instanceof ServerWorld ? ((ServerWorld)world).getForcedChunks() : LongSets.EMPTY_SET); + List list = Lists.newArrayList( + "Minecraft " + SharedConstants.getGameVersion().getName() + " (" + + this.client.getGameVersion() + + "/" + + ClientBrandRetriever.getClientModName() + + ("release".equalsIgnoreCase(this.client.getVersionType()) ? "" : "/" + this.client.getVersionType()) + + ")", + this.client.fpsDebugString, + string3 + + ); + list.add( + String.format( + Locale.ROOT, "X: %.1f",this.client.getCameraEntity().getX() + ) + + ); + list.add( + String.format( + Locale.ROOT, "Y: %.1f",this.client.getCameraEntity().getY() + ) + + ); + list.add( + String.format( + Locale.ROOT, "Z: %.1f", this.client.getCameraEntity().getZ() + ) + + ); + return list; + } + + } + + + public void drawText(DrawContext context, List text, boolean left) { + int i = 9; + + for (int j = 0; j < text.size(); j++) { + String string = (String)text.get(j); + if (!Strings.isNullOrEmpty(string)) { + int k = this.textRenderer.getWidth(string); + int l = left ? 2 : context.getScaledWindowWidth() - 2 - k; + int m = 2 + i * j; + context.fill(l - 1, m - 1, l + k + 1, m + i - 1, -1873784752); + } + } + + for (int jx = 0; jx < text.size(); jx++) { + String string = (String)text.get(jx); + if (!Strings.isNullOrEmpty(string)) { + int k = this.textRenderer.getWidth(string); + int l = left ? 2 : context.getScaledWindowWidth() - 2 - k; + int m = 2 + i * jx; + context.drawText(this.textRenderer, string, l, m, 14737632, false); + } + } + } + + + + + + + + + + + + + @Inject(method = "drawLeftText",at = @At(value = "HEAD"),cancellable = true) + protected void drawLeftText(DrawContext context, CallbackInfo ci) { + ci.cancel(); + + List list = this.getLeftText(); + this.drawText(context, list, true); + } + + + private static long toMiB(long bytes) { + return bytes / 1024L / 1024L; + } + + + +@Shadow +@Final +private DebugHud.AllocationRateCalculator allocationRateCalculator; + + @Inject(method = "getRightText",at = @At(value = "HEAD"),cancellable = true) + protected void getRightText(CallbackInfoReturnable> cir) { + cir.cancel(); + long l = Runtime.getRuntime().maxMemory(); + long m = Runtime.getRuntime().totalMemory(); + long n = Runtime.getRuntime().freeMemory(); + long o = m - n; + List list = Lists.newArrayList( + String.format(Locale.ROOT, "Java: %s", System.getProperty("java.version")), + String.format(Locale.ROOT, "Mem: %2d%% %03d/%03dMB", o * 100L / l, toMiB(o), toMiB(l)), + String.format(Locale.ROOT, "Allocation rate: %03dMB/s", toMiB(allocationRateCalculator.get(o))), + String.format(Locale.ROOT, "Allocated: %2d%% %03dMB", m * 100L / l, toMiB(m)), + "", + String.format(Locale.ROOT, "CPU: %s", GlDebugInfo.getCpuInfo()), + "", + String.format( + Locale.ROOT, + "Display: %dx%d (%s)", + MinecraftClient.getInstance().getWindow().getFramebufferWidth(), + MinecraftClient.getInstance().getWindow().getFramebufferHeight(), + GlDebugInfo.getVendor() + ), + GlDebugInfo.getRenderer(), + GlDebugInfo.getVersion() + ); + + cir.setReturnValue(list); + + + + } + + + + + + + + + +} + + diff --git a/src/main/java/com/equilibrium/mixin/InGameHudMixin.java b/src/main/java/com/equilibrium/mixin/render/InGameHudMixin.java similarity index 99% rename from src/main/java/com/equilibrium/mixin/InGameHudMixin.java rename to src/main/java/com/equilibrium/mixin/render/InGameHudMixin.java index 9626dc6..20814f3 100644 --- a/src/main/java/com/equilibrium/mixin/InGameHudMixin.java +++ b/src/main/java/com/equilibrium/mixin/render/InGameHudMixin.java @@ -1,4 +1,4 @@ -package com.equilibrium.mixin; +package com.equilibrium.mixin.render; import com.equilibrium.util.PlayerMaxHealthHelper; import com.equilibrium.util.PlayerMaxHungerHelper; diff --git a/src/main/java/com/equilibrium/mixin/WorldRendererMixin.java b/src/main/java/com/equilibrium/mixin/render/WorldRendererMixin.java similarity index 99% rename from src/main/java/com/equilibrium/mixin/WorldRendererMixin.java rename to src/main/java/com/equilibrium/mixin/render/WorldRendererMixin.java index 85c580a..750f558 100644 --- a/src/main/java/com/equilibrium/mixin/WorldRendererMixin.java +++ b/src/main/java/com/equilibrium/mixin/render/WorldRendererMixin.java @@ -1,4 +1,4 @@ -package com.equilibrium.mixin; +package com.equilibrium.mixin.render; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; diff --git a/src/main/java/com/equilibrium/util/ChangePortalColor.java b/src/main/java/com/equilibrium/util/ChangePortalColor.java new file mode 100644 index 0000000..d378894 --- /dev/null +++ b/src/main/java/com/equilibrium/util/ChangePortalColor.java @@ -0,0 +1,22 @@ +package com.equilibrium.util; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; + +public class ChangePortalColor extends Block { + public static final BooleanProperty CHANGE_PORTAL_COLOR_INTO_BLUE = BooleanProperty.of("change_portal_color_into_blue"); + + public ChangePortalColor(Settings settings) { + super(settings); + setDefaultState(getDefaultState().with(CHANGE_PORTAL_COLOR_INTO_BLUE, false)); + } + + + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(CHANGE_PORTAL_COLOR_INTO_BLUE); + } +} diff --git a/src/main/java/com/equilibrium/util/ShouldSentText.java b/src/main/java/com/equilibrium/util/ShouldSentText.java new file mode 100644 index 0000000..0b51cec --- /dev/null +++ b/src/main/java/com/equilibrium/util/ShouldSentText.java @@ -0,0 +1,7 @@ +package com.equilibrium.util; + +public class ShouldSentText { + //一次性触发器,互斥访问,是临界资源 + + public static int count = 170; +} diff --git a/src/main/resources/assets/miteequilibrium/lang/en_us.json b/src/main/resources/assets/miteequilibrium/lang/en_us.json index f8bfe3c..72ddff3 100644 --- a/src/main/resources/assets/miteequilibrium/lang/en_us.json +++ b/src/main/resources/assets/miteequilibrium/lang/en_us.json @@ -1,6 +1,6 @@ { "item.miteequilibrium.test": "Test", "block.miteequilibrium.example_block": "TestBlock", - "itemgroup.testgroup": "MITEequilibrium" + "itemgroup.testgroup": "MITEequilibrium", } diff --git a/src/main/resources/assets/miteequilibrium/lang/zh_cn.json b/src/main/resources/assets/miteequilibrium/lang/zh_cn.json index 1dba04a..81f87b8 100644 --- a/src/main/resources/assets/miteequilibrium/lang/zh_cn.json +++ b/src/main/resources/assets/miteequilibrium/lang/zh_cn.json @@ -1,5 +1,9 @@ { "item.miteequilibrium.test": "测试物品", "block.miteequilibrium.example_block": "测试方块", - "itemgroup.testgroup": "测试物品栏" + "itemgroup.testgroup": "测试物品栏", + "You will transport to nether": "该传送门会将你传送至下界", + "You will transport to overworld": "该传送门会将你传送至主世界", + "You will transport to underworld": "该传送门会将你传送至地下世界" + } diff --git a/src/main/resources/miteequilibrium.mixins.json b/src/main/resources/miteequilibrium.mixins.json index a5fc1f2..9e54495 100644 --- a/src/main/resources/miteequilibrium.mixins.json +++ b/src/main/resources/miteequilibrium.mixins.json @@ -25,8 +25,9 @@ }, "client": [ "BlockModelRendererMixin", - "InGameHudMixin", - "WorldRendererMixin", - "color.LightmapTextureManagerMixin" + "color.LightmapTextureManagerMixin", + "render.DebugHudMixin", + "render.InGameHudMixin", + "render.WorldRendererMixin" ] } \ No newline at end of file diff --git a/src/main/resources/name.accesswidener b/src/main/resources/name.accesswidener index 79fbf81..c8b402a 100644 --- a/src/main/resources/name.accesswidener +++ b/src/main/resources/name.accesswidener @@ -1,5 +1,7 @@ accessWidener v1 named +accessible method net/minecraft/client/gui/hud/DebugHud$AllocationRateCalculator get (J)J +accessible class net/minecraft/client/gui/hud/DebugHud$AllocationRateCalculator accessible field net/minecraft/entity/LivingEntity HEALTH Lnet/minecraft/entity/data/TrackedData; accessible method net/minecraft/block/NetherPortalBlock getOrCreateExitPortalTarget (Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/world/border/WorldBorder;)Lnet/minecraft/world/TeleportTarget; accessible method net/minecraft/world/dimension/NetherPortal validStateInsidePortal (Lnet/minecraft/block/BlockState;)Z @@ -22,4 +24,12 @@ accessible field net/minecraft/structure/StrongholdGenerator$PieceData weight I accessible field net/minecraft/structure/StrongholdGenerator$PieceData pieceType Ljava/lang/Class; accessible field net/minecraft/structure/StrongholdGenerator$PieceData generatedCount I accessible method net/minecraft/structure/StrongholdGenerator createPiece (Ljava/lang/Class;Lnet/minecraft/structure/StructurePiecesHolder;Lnet/minecraft/util/math/random/Random;IIILnet/minecraft/util/math/Direction;I)Lnet/minecraft/structure/StrongholdGenerator$Piece; -accessible method net/minecraft/structure/StrongholdGenerator pickPiece (Lnet/minecraft/structure/StrongholdGenerator$Start;Lnet/minecraft/structure/StructurePiecesHolder;Lnet/minecraft/util/math/random/Random;IIILnet/minecraft/util/math/Direction;I)Lnet/minecraft/structure/StrongholdGenerator$Piece; \ No newline at end of file +accessible method net/minecraft/structure/StrongholdGenerator pickPiece (Lnet/minecraft/structure/StrongholdGenerator$Start;Lnet/minecraft/structure/StructurePiecesHolder;Lnet/minecraft/util/math/random/Random;IIILnet/minecraft/util/math/Direction;I)Lnet/minecraft/structure/StrongholdGenerator$Piece; + + + + + + +accessible method net/minecraft/client/gui/hud/DebugHud drawText (Lnet/minecraft/client/gui/DrawContext;Ljava/util/List;Z)V +accessible method net/minecraft/client/gui/hud/DebugHud getLeftText ()Ljava/util/List; \ No newline at end of file