Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 104 lines 4.9 kB view raw
1package net.lerariemann.infinity.mixin.fixes; 2 3import net.lerariemann.infinity.util.platform.InfinityPlatform; 4import net.minecraft.tags.FluidTags; 5import net.minecraft.tags.TagKey; 6import net.minecraft.world.entity.Entity; 7import net.minecraft.world.level.material.Fluid; 8import org.spongepowered.asm.mixin.Mixin; 9import org.spongepowered.asm.mixin.injection.*; 10import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 11 12//? if <1.21 { 13/*import net.lerariemann.infinity.block.entity.InfinityPortalBlockEntity; 14import net.lerariemann.infinity.util.teleport.InfinityPortal; 15import net.lerariemann.infinity.util.teleport.PortalCreator; 16import net.lerariemann.infinity.util.InfinityMethods; 17import net.minecraft.core.registries.Registries; 18import net.minecraft.resources.ResourceKey; 19import net.minecraft.core.BlockPos; 20import net.minecraft.world.level.Level; 21import net.minecraft.server.level.ServerLevel; 22import net.minecraft.world.level.block.Blocks; 23import net.minecraft.world.level.portal.PortalInfo; 24import org.spongepowered.asm.mixin.Shadow; 25*///?} 26 27@Mixin(Entity.class) 28public abstract class EntityMixin { 29 //? if <1.21 { 30 /*@Shadow 31 protected BlockPos portalEntrancePos; 32 33 @Shadow public abstract Level level(); 34 35 @ModifyArg(method = "handleNetherPortal()V", at = @At(value = "INVOKE", target = 36 "Lnet/minecraft/world/entity/Entity;changeDimension(Lnet/minecraft/server/level/ServerLevel;)Lnet/minecraft/world/entity/Entity;")) 37 private ServerLevel injected(ServerLevel originalWorldTo) { 38 if (level() instanceof ServerLevel worldFrom) { 39 BlockPos pos = this.portalEntrancePos; 40 if (worldFrom.getBlockEntity(pos) instanceof InfinityPortalBlockEntity portal) { 41 ResourceKey<Level> keyTo = ResourceKey.create(Registries.DIMENSION, 42 portal.getDimension()); //redirect teleportation to infdims 43 ServerLevel worldTo = worldFrom.getServer().getLevel(keyTo); 44 return (InfinityMethods.dimExists(worldTo) 45 && portal.isOpen()) ? worldTo : worldFrom; 46 } 47 else if (worldFrom.getBlockState(pos).is(Blocks.NETHER_PORTAL) 48 && InfinityMethods.isInfinity(worldFrom)) { //redirect returning from infdims and make portals in them infinity (for sync reasons) 49 PortalCreator.modifyPortalRecursive(worldFrom, pos, Level.OVERWORLD.location(), true); 50 return worldFrom.getServer().overworld(); 51 } 52 else return originalWorldTo; 53 } 54 return originalWorldTo; 55 } 56 57 @Inject(method = "findDimensionEntryPoint", at = @At(value = "HEAD"), cancellable = true) 58 private void injected(ServerLevel destination, CallbackInfoReturnable<PortalInfo> cir) { 59 if (level() instanceof ServerLevel worldFrom) { 60 BlockPos posFrom = portalEntrancePos; 61 if (worldFrom.getBlockEntity(posFrom) instanceof InfinityPortalBlockEntity ipbe) { 62 cir.setReturnValue((new InfinityPortal(ipbe, worldFrom, posFrom)).getTeleportTarget((Entity)(Object)this)); 63 } 64 } 65 } 66 *///?} 67 68 /* (Neo)forge-exclusive mixins working around its code (which causes mobs to be unable to swim in iridescence) */ 69 @Inject(method="updateFluidHeightAndDoFluidPushing", at = @At(value = "RETURN"), cancellable = true) 70 void neoMobsSwim(TagKey<Fluid> tag, double speed, CallbackInfoReturnable<Boolean> cir) { 71 if (tag.equals(FluidTags.WATER)) 72 if (InfinityPlatform.INSTANCE.acidTest((Entity)(Object)this, false)) 73 cir.setReturnValue(true); 74 } 75 76 @Inject(method = "isEyeInFluid", at = @At("RETURN"), cancellable = true) 77 void neoMobsSwim2(TagKey<Fluid> fluidTag, CallbackInfoReturnable<Boolean> cir) { 78 if (fluidTag.equals(FluidTags.WATER)) 79 if (InfinityPlatform.INSTANCE.acidTest((Entity)(Object)this, true)) 80 cir.setReturnValue(true); 81 } 82 83 @Inject(method = "getFluidHeight", at = @At("RETURN"), cancellable = true) 84 void neoMobsSwim3(TagKey<Fluid> fluid, CallbackInfoReturnable<Double> cir) { 85 if (fluid.equals(FluidTags.WATER)) 86 cir.setReturnValue(Math.max(cir.getReturnValue(), InfinityPlatform.INSTANCE.acidHeightTest((Entity)(Object)this))); 87 } 88 89 //? if forge { 90 /*@Shadow 91 private Level level; 92 93 @Redirect(method = "findDimensionEntryPoint", 94 at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;dimension()Lnet/minecraft/resources/ResourceKey;"), 95 slice = @Slice(from = @At( 96 value = "INVOKE", target = "Lnet/minecraft/world/level/Level;dimension()Lnet/minecraft/resources/ResourceKey;" 97 ), to = @At("TAIL"))) 98 ResourceKey<Level> smuggle(Level w) { 99 if (w == this.level) return Level.NETHER; 100 return w.dimension(); 101 } 102 *///?} 103} 104