Jump to content

balex25

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by balex25

  1. Hi, Is it possible to simulate a shift press? I need to get hasShiftDown() true from Screen.class (try to get a tooltip with shift press and without from itemStack#getTooltipLines()). Also, I tried with follow, but it did not trigger: // Simulate holding down the shift key Minecraft.getInstance().player.setShiftKeyDown(true); Minecraft.getInstance().options.keyShift.setDown(true); KeyMapping.set(Minecraft.getInstance().options.keyShift.getKey(), true); Leave code here, maybe some still need it. ScreenMixin.class import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; 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 ShiftStateUtility; @Mixin(Screen.class) public class ScreenMixin { @Inject(method = "hasShiftDown", at = @At("HEAD"), cancellable = true) private static void onHasShiftDown(CallbackInfoReturnable<Boolean> cir) { if(ShiftStateUtility.shouldShiftBeDown) { cir.setReturnValue(ShiftStateUtility.shouldShiftBeDown); } else { // Call a method that checks the actual key state. cir.setReturnValue(checkActualShiftState()); } } @Inject(method = "hasControlDown", at = @At("HEAD"), cancellable = true) private static void hasControlDown(CallbackInfoReturnable<Boolean> cir) { if(ShiftStateUtility.shouldControlBeDown) { cir.setReturnValue(ShiftStateUtility.shouldControlBeDown); } else { // Call a method that checks the actual key state. cir.setReturnValue(checkActualControlState()); } } @Inject(method = "hasAltDown", at = @At("HEAD"), cancellable = true) private static void hasAltDown(CallbackInfoReturnable<Boolean> cir) { if(ShiftStateUtility.shouldAltBeDown) { cir.setReturnValue(ShiftStateUtility.shouldAltBeDown); } else { // Call a method that checks the actual key state. cir.setReturnValue(checkActualAltState()); } } private static boolean checkActualShiftState() { return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 340) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 344); } private static boolean checkActualControlState() { if (Minecraft.ON_OSX) { return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 343) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 347); } else { return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 341) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 345); } } private static boolean checkActualAltState() { return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 342) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), 346); } } ShiftStateUtility.class public class ShiftStateUtility { public static boolean shouldShiftBeDown = false; public static boolean shouldControlBeDown = false; public static boolean shouldAltBeDown = false; } Usage: ShiftStateUtility.shouldShiftBeDown = true / false; ShiftStateUtility.shouldControlBeDown = true / false; ShiftStateUtility.shouldAltBeDown = true / false; The default behavior of hasShiftDown, hasAltDown, and hasControlDown still work as default, and you can control if want to simulate a press of any key.
  2. // Get all dimensions MinecraftServer server = ... Registry<DimensionType> dimensionRegistry = server.registryAccess().registryOrThrow(Registries.DIMENSION_TYPE); for (Map.Entry<ResourceKey<DimensionType>, DimensionType> dimensionEntry : dimensionRegistry.entrySet()) { ResourceKey<DimensionType> dimensionKey = dimensionEntry.getKey(); DimensionType dimension = dimensionEntry.getValue(); } Working on 1.20.1, if someone is still interested in the latest version of Minecraft.
  3. Did someone figure out how to get all the biomes? I try to run: ForgeRegistries.BIOMES.getKeys() ForgeRegistries.BIOMES.getEntries() ForgeRegistries.BIOMES.getValues() All give me an empty list. ------------- Updated (working on 1.20.1): // Get server MinecraftServer server = ... get current server // Get all registered biomes Registry<Biome> allBiomes = server.registryAccess().registryOrThrow(Registries.BIOME); // Check each biome for (Map.Entry<ResourceKey<Biome>, Biome> biomeEntry : allBiomes.entrySet()) { ResourceKey<Biome> biomeKey = biomeEntry.getKey(); Biome biome = biomeEntry.getValue(); String modId = biomeKey.location().getNamespace(); String translationKey = "biome." + modId + "." + biomeKey.location().getPath(); String biomeName = I18n.get(translationKey); }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.