Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.

1.21 update

+675 -1119
+2 -2
build.gradle
··· 1 1 plugins { 2 - id 'fabric-loom' version '1.6-SNAPSHOT' 2 + id 'fabric-loom' version '1.7-SNAPSHOT' 3 3 id 'maven-publish' 4 4 } 5 5 ··· 47 47 48 48 tasks.withType(JavaCompile).configureEach { 49 49 // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. 50 - it.options.release = 17 50 + it.options.release = 21 51 51 } 52 52 53 53 java {
+5 -5
gradle.properties
··· 4 4 5 5 # Fabric Properties 6 6 # check these on https://fabricmc.net/develop 7 - minecraft_version=1.20.1 8 - yarn_mappings=1.20.1+build.9 9 - loader_version=0.15.7 7 + minecraft_version=1.21.1 8 + yarn_mappings=1.21.1+build.3 9 + loader_version=0.16.2 10 10 11 11 # Mod Properties 12 - mod_version = 1.11.2-1.20.1 12 + mod_version = 1.12.0-1.21.1 13 13 maven_group = net.lerariemann 14 14 archives_base_name = infinity 15 15 16 16 # Dependencies 17 - fabric_version=0.85.0+1.20.1 17 + fabric_version=0.102.1+1.21.1
+1 -1
gradle/wrapper/gradle-wrapper.properties
··· 1 1 distributionBase=GRADLE_USER_HOME 2 2 distributionPath=wrapper/dists 3 - distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip 3 + distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip 4 4 networkTimeout=10000 5 5 zipStoreBase=GRADLE_USER_HOME 6 6 zipStorePath=wrapper/dists
+1 -1
src/main/java/me/basiqueevangelist/dynreg/DynReg.java
··· 11 11 public static MinecraftServer SERVER; 12 12 13 13 public static Identifier id(String path) { 14 - return new Identifier(MODID, path); 14 + return Identifier.of(MODID, path); 15 15 } 16 16 17 17 @Override
-56
src/main/java/me/basiqueevangelist/dynreg/mixin/SimpleRegistryMixin.java
··· 3 3 import com.mojang.serialization.Lifecycle; 4 4 import it.unimi.dsi.fastutil.ints.IntArrayList; 5 5 import it.unimi.dsi.fastutil.ints.IntList; 6 - import it.unimi.dsi.fastutil.objects.Object2IntMap; 7 - import it.unimi.dsi.fastutil.objects.ObjectList; 8 6 import me.basiqueevangelist.dynreg.access.ExtendedRegistry; 9 7 import me.basiqueevangelist.dynreg.event.RegistryEntryDeletedCallback; 10 8 import me.basiqueevangelist.dynreg.event.RegistryFrozenCallback; 11 9 import me.basiqueevangelist.dynreg.util.StackTracingMap; 12 10 import net.fabricmc.fabric.api.event.Event; 13 11 import net.fabricmc.fabric.api.event.EventFactory; 14 - import net.fabricmc.fabric.api.event.registry.RegistryEntryRemovedCallback; 15 12 import net.minecraft.registry.Registry; 16 13 import net.minecraft.registry.RegistryKey; 17 14 import net.minecraft.registry.SimpleRegistry; ··· 21 18 import org.spongepowered.asm.mixin.*; 22 19 import org.spongepowered.asm.mixin.injection.At; 23 20 import org.spongepowered.asm.mixin.injection.Inject; 24 - import org.spongepowered.asm.mixin.injection.Redirect; 25 21 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 26 22 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 27 23 ··· 40 36 @Shadow 41 37 public abstract Optional<RegistryEntry.Reference<T>> getEntry(RegistryKey<T> key); 42 38 43 - @Shadow 44 - @Final 45 - private Object2IntMap<T> entryToRawId; 46 - @Shadow 47 - @Final 48 - private ObjectList<RegistryEntry.Reference<T>> rawIdToEntry; 49 39 @Mutable 50 40 @Shadow 51 41 @Final 52 42 private Map<Identifier, RegistryEntry.Reference<T>> idToEntry; 53 - @Shadow 54 - @Final 55 - private Map<RegistryKey<T>, RegistryEntry.Reference<T>> keyToEntry; 56 - @Shadow 57 - @Final 58 - private Map<T, RegistryEntry.Reference<T>> valueToEntry; 59 - @Shadow 60 - @Final 61 - private Map<T, Lifecycle> entryToLifecycle; 62 - @Shadow 63 - @Nullable 64 - private List<RegistryEntry.Reference<T>> cachedEntries; 65 - @Shadow private int nextId; 66 43 67 44 @Unique 68 45 @SuppressWarnings("unchecked") private final Event<RegistryEntryDeletedCallback<T>> dynreg$entryDeletedEvent = EventFactory.createArrayBacked(RegistryEntryDeletedCallback.class, callbacks -> (rawId, entry) -> { ··· 100 77 } 101 78 102 79 @Override 103 - public void dynreg$remove(RegistryKey<T> key) { 104 - if (frozen) { 105 - throw new IllegalStateException("Registry is frozen (trying to remove key " + key + ")"); 106 - } 107 - 108 - RegistryEntry.Reference<T> entry = getEntry(key).orElseThrow(); 109 - 110 - int rawId = entryToRawId.getInt(entry.value()); 111 - dynreg$entryDeletedEvent.invoker().onEntryDeleted(rawId, entry); 112 - RegistryEntryRemovedCallback.event(this).invoker().onEntryRemoved(rawId, entry.registryKey().getValue(), entry.value()); 113 - 114 - rawIdToEntry.set(rawId, null); 115 - entryToRawId.removeInt(entry.value()); 116 - idToEntry.remove(key.getValue()); 117 - keyToEntry.remove(key); 118 - valueToEntry.remove(entry.value()); 119 - entryToLifecycle.remove(entry.value()); 120 - dynreg$freeIds.add(rawId); 121 - 122 - cachedEntries = null; 123 - } 124 - 125 - @Redirect(method = "add", at = @At(value = "FIELD", target = "Lnet/minecraft/registry/SimpleRegistry;nextId:I")) 126 - private int getNextId(SimpleRegistry<T> instance) { 127 - if (!dynreg$freeIds.isEmpty()) 128 - return dynreg$freeIds.removeInt(0); 129 - 130 - return nextId; 131 - } 132 - 133 - @Override 134 80 public void dynreg$unfreeze() { 135 81 frozen = false; 136 82 if (dynreg$intrusive) 137 83 this.intrusiveValueToEntry = new IdentityHashMap<>(); 138 - 139 - cachedEntries = null; 140 84 } 141 85 142 86 @Inject(method = "freeze", at = @At("HEAD"))
+2 -4
src/main/java/net/lerariemann/infinity/InfinityMod.java
··· 14 14 15 15 public class InfinityMod implements ModInitializer { 16 16 public static final String MOD_ID = "infinity"; 17 - public static final Identifier WORLD_ADD = getId("reload_worlds"); 18 - public static final Identifier SHADER_RELOAD = getId("reload_shader"); 19 - public static final Identifier STARS_RELOAD = getId("reload_stars"); 20 17 public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); 21 18 22 19 public static Identifier getId(String value){ 23 - return new Identifier(MOD_ID, value); 20 + return Identifier.of(MOD_ID, value); 24 21 } 25 22 26 23 @Override ··· 41 38 ModFeatures.registerFeatures(); 42 39 ModStats.registerStats(); 43 40 ModCriteria.registerCriteria(); 41 + ModPayloads.registerPayloadsServer(); 44 42 } 45 43 }
+3 -23
src/main/java/net/lerariemann/infinity/InfinityModClient.java
··· 2 2 3 3 import net.fabricmc.api.ClientModInitializer; 4 4 import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; 5 - import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; 6 5 import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; 7 6 import net.lerariemann.infinity.block.ModBlocks; 8 7 import net.lerariemann.infinity.block.entity.NeitherPortalBlockEntity; 9 - import net.lerariemann.infinity.options.PacketTransiever; 10 8 import net.lerariemann.infinity.entity.ModEntities; 11 - import net.lerariemann.infinity.loading.DimensionGrabber; 9 + import net.lerariemann.infinity.var.ModPayloads; 12 10 import net.minecraft.block.entity.BlockEntity; 13 11 import net.minecraft.client.render.RenderLayer; 14 - import net.minecraft.nbt.NbtCompound; 15 - import net.minecraft.util.Identifier; 16 12 import net.minecraft.util.math.BlockPos; 17 13 import net.minecraft.util.math.noise.DoublePerlinNoiseSampler; 18 14 import net.minecraft.util.math.random.CheckedRandom; 19 15 20 - import java.util.ArrayList; 21 - import java.util.List; 22 - 23 16 public class InfinityModClient implements ClientModInitializer { 24 17 final static DoublePerlinNoiseSampler sampler = DoublePerlinNoiseSampler.create(new CheckedRandom(0L), -3, 1.0, 1.0, 1.0, 0.0); 25 18 ··· 39 32 if (world != null && pos != null) { 40 33 BlockEntity blockEntity = world.getBlockEntity(pos); 41 34 if (blockEntity instanceof NeitherPortalBlockEntity) { 42 - Object j = ((NeitherPortalBlockEntity)blockEntity).getRenderAttachmentData(); 35 + Object j = blockEntity.getRenderData(); 43 36 if (j == null) return 0; 44 37 return (int)j & 0xFFFFFF; 45 38 } ··· 54 47 } 55 48 return 16777215; 56 49 }, ModBlocks.BOOK_BOX); 57 - ClientPlayNetworking.registerGlobalReceiver(InfinityMod.WORLD_ADD, (client, handler, buf, responseSender) -> { 58 - Identifier id = buf.readIdentifier(); 59 - NbtCompound optiondata = buf.readNbt(); 60 - int i = buf.readInt(); 61 - List<Identifier> biomeids = new ArrayList<>(); 62 - List<NbtCompound> biomes = new ArrayList<>(); 63 - for (int j = 0; j < i; j++) { 64 - biomeids.add(buf.readIdentifier()); 65 - biomes.add(buf.readNbt()); 66 - } 67 - client.execute(() -> (new DimensionGrabber(client.getNetworkHandler().getRegistryManager())).grab_for_client(id, optiondata, biomeids, biomes)); 68 - }); 69 - ClientPlayNetworking.registerGlobalReceiver(InfinityMod.SHADER_RELOAD, PacketTransiever::receive); 70 - ClientPlayNetworking.registerGlobalReceiver(InfinityMod.STARS_RELOAD, PacketTransiever::receiveStars); 50 + ModPayloads.registerPayloadsClient(); 71 51 ModEntities.registerEntityRenderers(); 72 52 } 73 53 }
+2 -2
src/main/java/net/lerariemann/infinity/access/InfinityOptionsAccess.java
··· 3 3 import net.lerariemann.infinity.options.InfinityOptions; 4 4 5 5 public interface InfinityOptionsAccess { 6 - InfinityOptions getInfinityOptions(); 7 - void setInfinityOptions(InfinityOptions options); 6 + InfinityOptions projectInfinity$getInfinityOptions(); 7 + void projectInfinity$setInfinityOptions(InfinityOptions options); 8 8 }
+1 -1
src/main/java/net/lerariemann/infinity/access/MavityInterface.java
··· 10 10 default double getMavity() { 11 11 double mavity; 12 12 try { 13 - mavity = ((InfinityOptionsAccess) getWorld()).getInfinityOptions().getMavity(); 13 + mavity = ((InfinityOptionsAccess) getWorld()).projectInfinity$getInfinityOptions().getMavity(); 14 14 } catch (Exception e) { 15 15 mavity = 1.0; 16 16 }
+6 -6
src/main/java/net/lerariemann/infinity/access/MinecraftServerAccess.java
··· 7 7 8 8 public interface MinecraftServerAccess { 9 9 10 - void addWorld(RegistryKey<World> key, DimensionOptions options); 10 + void projectInfinity$addWorld(RegistryKey<World> key, DimensionOptions options); 11 11 12 - boolean hasToAdd(RegistryKey<World> key); 12 + boolean projectInfinity$hasToAdd(RegistryKey<World> key); 13 13 14 - boolean needsInvocation(); 15 - void onInvocation(); 14 + boolean projectInfinity$needsInvocation(); 15 + void projectInfinity$onInvocation(); 16 16 17 - RandomProvider getDimensionProvider(); 18 - void setDimensionProvider(); 17 + RandomProvider projectInfinity$getDimensionProvider(); 18 + void projectInfinity$setDimensionProvider(); 19 19 }
+1 -1
src/main/java/net/lerariemann/infinity/access/MobEntityAccess.java
··· 1 1 package net.lerariemann.infinity.access; 2 2 3 3 public interface MobEntityAccess { 4 - void setPersistent(boolean bl); 4 + void projectInfinity$setPersistent(boolean bl); 5 5 }
+1 -1
src/main/java/net/lerariemann/infinity/access/ServerPlayerEntityAccess.java
··· 1 1 package net.lerariemann.infinity.access; 2 2 3 3 public interface ServerPlayerEntityAccess { 4 - void setWarpTimer(long ticks, long dim); 4 + void projectInfinity$setWarpTimer(long ticks, long dim); 5 5 }
+2 -2
src/main/java/net/lerariemann/infinity/access/Timebombable.java
··· 1 1 package net.lerariemann.infinity.access; 2 2 3 3 public interface Timebombable { 4 - void timebomb(int i); 4 + void projectInfinity$timebomb(int i); 5 5 6 - int isTimebobmed(); 6 + int projectInfinity$isTimebobmed(); 7 7 }
+1 -1
src/main/java/net/lerariemann/infinity/access/WorldRendererAccess.java
··· 1 1 package net.lerariemann.infinity.access; 2 2 3 3 public interface WorldRendererAccess { 4 - void setNeedsStars(boolean b); 4 + void projectInfinity$setNeedsStars(boolean b); 5 5 }
+10 -11
src/main/java/net/lerariemann/infinity/block/ModBlocks.java
··· 1 1 package net.lerariemann.infinity.block; 2 2 3 - import net.fabricmc.fabric.api.item.v1.FabricItemSettings; 4 3 import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; 5 - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 6 4 import net.lerariemann.infinity.InfinityMod; 7 5 import net.lerariemann.infinity.block.custom.*; 6 + import net.minecraft.block.AbstractBlock; 8 7 import net.minecraft.block.Block; 9 8 import net.minecraft.block.Blocks; 10 9 import net.minecraft.item.*; ··· 12 11 import net.minecraft.registry.Registry; 13 12 14 13 public class ModBlocks { 15 - public static final Block NEITHER_PORTAL = new NeitherPortalBlock(FabricBlockSettings.copy(Blocks.NETHER_PORTAL)); 16 - public static final Block BOOK_BOX = new BookBoxBlock(FabricBlockSettings.copy(Blocks.BOOKSHELF)); 17 - public static final Item BOOK_BOX_ITEM = new BlockItem(BOOK_BOX, new FabricItemSettings()); 18 - public static final Block ALTAR_COSMIC = new CosmicAltar(FabricBlockSettings.copy(Blocks.BEDROCK).nonOpaque()); 19 - public static final Block ALTAR_LIT = new TransfiniteAltar(FabricBlockSettings.copy(Blocks.BEDROCK).nonOpaque(). 14 + public static final Block NEITHER_PORTAL = new NeitherPortalBlock(AbstractBlock.Settings.copy(Blocks.NETHER_PORTAL)); 15 + public static final Block BOOK_BOX = new BookBoxBlock(AbstractBlock.Settings.copy(Blocks.BOOKSHELF)); 16 + public static final Item BOOK_BOX_ITEM = new BlockItem(BOOK_BOX, new Item.Settings()); 17 + public static final Block ALTAR_COSMIC = new CosmicAltar(AbstractBlock.Settings.copy(Blocks.BEDROCK).nonOpaque()); 18 + public static final Block ALTAR_LIT = new TransfiniteAltar(AbstractBlock.Settings.copy(Blocks.BEDROCK).nonOpaque(). 20 19 luminance(state -> state.get(TransfiniteAltar.FLOWER) ? 15 : 0)); 21 - public static final Block ALTAR = new TransfiniteAltarBase(FabricBlockSettings.copy(Blocks.STONE).nonOpaque(). 20 + public static final Block ALTAR = new TransfiniteAltarBase(AbstractBlock.Settings.copy(Blocks.STONE).nonOpaque(). 22 21 luminance(state -> state.get(TransfiniteAltarBase.FLOWER) ? 15 : 0)); 23 - public static final Item ALTAR_ITEM = new BlockItem(ALTAR, new FabricItemSettings()); 24 - public static final Block TIME_BOMB = new TimeBombBlock(FabricBlockSettings.copy(Blocks.BEDROCK).nonOpaque(). 22 + public static final Item ALTAR_ITEM = new BlockItem(ALTAR, new Item.Settings()); 23 + public static final Block TIME_BOMB = new TimeBombBlock(AbstractBlock.Settings.copy(Blocks.BEDROCK).nonOpaque(). 25 24 luminance(state -> 15)); 26 - public static final Item TIME_BOMB_ITEM = new BlockItem(TIME_BOMB, new FabricItemSettings()); 25 + public static final Item TIME_BOMB_ITEM = new BlockItem(TIME_BOMB, new Item.Settings()); 27 26 private static void registerBlock(String name, Block block) { 28 27 Registry.register(Registries.BLOCK, InfinityMod.getId(name), block); 29 28 }
+11 -11
src/main/java/net/lerariemann/infinity/block/custom/BookBoxBlock.java
··· 3 3 import net.minecraft.block.AbstractBlock; 4 4 import net.minecraft.block.Block; 5 5 import net.minecraft.block.BlockState; 6 + import net.minecraft.component.DataComponentTypes; 7 + import net.minecraft.component.type.WrittenBookContentComponent; 6 8 import net.minecraft.entity.player.PlayerEntity; 7 9 import net.minecraft.item.ItemStack; 8 10 import net.minecraft.item.Items; 9 - import net.minecraft.nbt.NbtCompound; 10 - import net.minecraft.nbt.NbtList; 11 - import net.minecraft.nbt.NbtString; 11 + import net.minecraft.text.RawFilteredPair; 12 + import net.minecraft.text.Text; 12 13 import net.minecraft.util.ActionResult; 13 - import net.minecraft.util.Hand; 14 14 import net.minecraft.util.hit.BlockHitResult; 15 15 import net.minecraft.util.math.BlockPos; 16 16 import net.minecraft.world.World; 17 17 18 + import java.util.ArrayList; 19 + import java.util.List; 18 20 import java.util.Random; 19 21 20 22 public class BookBoxBlock extends Block { ··· 37 39 } 38 40 39 41 @Override 40 - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { 42 + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { 41 43 if (!world.isClient) { 42 44 ItemStack itemStack1 = Items.WRITTEN_BOOK.getDefaultStack(); 43 - NbtCompound compound = itemStack1.getOrCreateNbt(); 44 - compound.putString("author", "§kLeraRiemann"); 45 - NbtList lst = new NbtList(); 46 - lst.add(NbtString.of(text(pos))); 47 - compound.put("pages", lst); 48 - compound.putString("title", title(pos)); 45 + List<RawFilteredPair<Text>> pages = new ArrayList<>(); 46 + pages.add(RawFilteredPair.of(Text.of(text(pos)))); 47 + WrittenBookContentComponent component = new WrittenBookContentComponent(RawFilteredPair.of(title(pos)), "§kLeraRiemann", 3, pages, false); 48 + itemStack1.set(DataComponentTypes.WRITTEN_BOOK_CONTENT, component); 49 49 player.getInventory().insertStack(itemStack1); 50 50 } 51 51 return ActionResult.SUCCESS;
+9 -2
src/main/java/net/lerariemann/infinity/block/custom/CosmicAltar.java
··· 1 1 package net.lerariemann.infinity.block.custom; 2 2 3 + import com.mojang.serialization.MapCodec; 3 4 import net.lerariemann.infinity.block.entity.CosmicAltarEntity; 4 5 import net.lerariemann.infinity.block.entity.ModBlockEntities; 5 6 import net.minecraft.block.BlockRenderType; ··· 13 14 import org.jetbrains.annotations.Nullable; 14 15 15 16 public class CosmicAltar extends BlockWithEntity { 17 + public static final MapCodec<CosmicAltar> CODEC = createCodec(CosmicAltar::new); 16 18 public CosmicAltar(Settings settings) { 17 19 super(settings); 18 20 } 21 + 22 + @Override 23 + protected MapCodec<? extends BlockWithEntity> getCodec() { 24 + return CODEC; 25 + } 26 + 19 27 @Override 20 28 public BlockRenderType getRenderType(BlockState state) { 21 29 return BlockRenderType.MODEL; ··· 27 35 } 28 36 @Override 29 37 public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { 30 - if (!world.isClient) return checkType(type, ModBlockEntities.ALTAR_COSMIC, CosmicAltarEntity::serverTick); 31 - return null; 38 + return validateTicker(type, ModBlockEntities.ALTAR_COSMIC, world.isClient ? null : CosmicAltarEntity::serverTick); 32 39 } 33 40 }
+23 -18
src/main/java/net/lerariemann/infinity/block/custom/NeitherPortalBlock.java
··· 6 6 import net.fabricmc.api.Environment; 7 7 import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; 8 8 import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; 9 - import net.lerariemann.infinity.InfinityMod; 10 9 import net.lerariemann.infinity.access.MinecraftServerAccess; 11 10 import net.lerariemann.infinity.block.ModBlocks; 12 11 import net.lerariemann.infinity.block.entity.NeitherPortalBlockEntity; ··· 17 16 import net.lerariemann.infinity.loading.DimensionGrabber; 18 17 import net.lerariemann.infinity.var.ModCommands; 19 18 import net.lerariemann.infinity.var.ModCriteria; 19 + import net.lerariemann.infinity.var.ModPayloads; 20 20 import net.lerariemann.infinity.var.ModStats; 21 21 import net.minecraft.block.BlockEntityProvider; 22 22 import net.minecraft.block.BlockState; ··· 30 30 import net.minecraft.item.ItemStack; 31 31 import net.minecraft.item.Items; 32 32 import net.minecraft.nbt.NbtCompound; 33 + import net.minecraft.nbt.NbtList; 33 34 import net.minecraft.network.PacketByteBuf; 34 35 import net.minecraft.particle.DustParticleEffect; 35 36 import net.minecraft.particle.ParticleEffect; ··· 68 69 } 69 70 70 71 public static boolean open(MinecraftServer s, World world, BlockPos pos, boolean countRepeats) { 71 - RandomProvider prov = ((MinecraftServerAccess)(s)).getDimensionProvider(); 72 + RandomProvider prov = ((MinecraftServerAccess)(s)).projectInfinity$getDimensionProvider(); 72 73 BlockEntity blockEntity = world.getBlockEntity(pos); 73 74 boolean bl = false; 74 75 if (blockEntity instanceof NeitherPortalBlockEntity) { ··· 130 131 131 132 @Override 132 133 public ActionResult onUse(BlockState state, World world, BlockPos pos, 133 - PlayerEntity player, Hand hand, BlockHitResult hit) { 134 + PlayerEntity player, BlockHitResult hit) { 134 135 if (!world.isClient) { 135 136 MinecraftServer s = world.getServer(); 136 137 BlockEntity blockEntity = world.getBlockEntity(pos); 137 138 if (s!=null && blockEntity instanceof NeitherPortalBlockEntity) { 138 139 if (((NeitherPortalBlockEntity)blockEntity).getOpen() && world_exists(s, ((NeitherPortalBlockEntity)blockEntity).getDimension())) 139 140 return ActionResult.SUCCESS; 140 - RandomProvider prov = ((MinecraftServerAccess)(s)).getDimensionProvider(); 141 + RandomProvider prov = ((MinecraftServerAccess)(s)).projectInfinity$getDimensionProvider(); 141 142 boolean bl = prov.portalKey.isBlank(); 142 143 boolean bl2 = false; 143 144 if (bl) { 144 145 bl2 = open(s, world, pos, false); 145 146 } 146 147 else { 147 - ItemStack itemStack = player.getStackInHand(hand); 148 - Item item = Registries.ITEM.get(new Identifier(prov.portalKey)); 148 + ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND); 149 + Item item = Registries.ITEM.get(Identifier.of(prov.portalKey)); 149 150 if (itemStack.isOf(item)) { 150 151 if (!player.getAbilities().creativeMode) { 151 152 itemStack.decrement(1); ··· 163 164 return ActionResult.SUCCESS; 164 165 } 165 166 166 - 167 167 public static boolean addDimension(MinecraftServer server, long i, boolean bl) { 168 168 RegistryKey<World> key = ModCommands.getKey(i, server); 169 - if ((server.getWorld(key) == null) && (!((MinecraftServerAccess)(server)).hasToAdd(key)) && !ModCommands.checkEnd(i, server)) { 169 + if ((server.getWorld(key) == null) && (!((MinecraftServerAccess)(server)).projectInfinity$hasToAdd(key)) && !ModCommands.checkEnd(i, server)) { 170 170 RandomDimension d = new RandomDimension(i, server); 171 171 if (bl) { 172 - ((MinecraftServerAccess) (server)).addWorld(key, (new DimensionGrabber(server.getRegistryManager())).grab_all(d)); 172 + ((MinecraftServerAccess) (server)).projectInfinity$addWorld(key, (new DimensionGrabber(server.getRegistryManager())).grab_all(d)); 173 173 server.getPlayerManager().getPlayerList().forEach(a -> 174 - ServerPlayNetworking.send(a, InfinityMod.WORLD_ADD, buildPacket(ModCommands.getIdentifier(i, server), d))); 174 + ServerPlayNetworking.send(a, buildPayload(ModCommands.getIdentifier(i, server), d))); 175 175 return true; 176 176 } 177 177 } 178 178 return false; 179 179 } 180 180 181 - static PacketByteBuf buildPacket(Identifier id, RandomDimension d) { 181 + static ModPayloads.WorldAddPayload buildPayload(Identifier id, RandomDimension d) { 182 182 PacketByteBuf buf = PacketByteBufs.create(); 183 183 buf.writeIdentifier(id); 184 - buf.writeNbt(d.type != null ? d.type.data : new NbtCompound()); 185 - buf.writeInt(d.random_biomes.size()); 184 + NbtCompound data = new NbtCompound(); 185 + NbtCompound dimdata = d.type != null ? d.type.data : new NbtCompound(); 186 + data.put("dimdata", dimdata); 187 + NbtList biomes = new NbtList(); 186 188 d.random_biomes.forEach(b -> { 187 - buf.writeIdentifier(InfinityMod.getId(b.name)); 188 - buf.writeNbt(b.data); 189 + NbtCompound biome = new NbtCompound(); 190 + biome.putString("id", b.name); 191 + biome.put("data", b.data); 192 + biomes.add(biome); 189 193 }); 190 - return buf; 194 + data.put("biomes", biomes); 195 + return new ModPayloads.WorldAddPayload(id, data); 191 196 } 192 197 193 198 @Environment(EnvType.CLIENT) ··· 239 244 if (recipes.containsKey(itemStack.getItem())) { 240 245 Vec3d v = entity.getVelocity(); 241 246 ItemEntity result = new ItemEntity(world, entity.getX(), entity.getY(), entity.getZ(), 242 - new ItemStack(Registries.ITEM.get(new Identifier(recipes.get(itemStack.getItem())))).copyWithCount(itemStack.getCount()), 247 + new ItemStack(Registries.ITEM.get(Identifier.of(recipes.get(itemStack.getItem())))).copyWithCount(itemStack.getCount()), 243 248 -v.x, -v.y, -v.z); 244 249 world.spawnEntity(result); 245 250 entity.remove(Entity.RemovalReason.CHANGED_DIMENSION); ··· 256 261 pos = pos.down(); 257 262 } 258 263 if (world.getBlockState(pos).allowsSpawning(world, pos, ModEntities.CHAOS_PAWN) && 259 - ((MinecraftServerAccess)world.getServer()).getDimensionProvider().rule("chaosMobsEnabled") && 264 + ((MinecraftServerAccess)world.getServer()).projectInfinity$getDimensionProvider().rule("chaosMobsEnabled") && 260 265 (entity = ModEntities.CHAOS_PAWN.spawn(world, pos.up(), SpawnReason.STRUCTURE)) != null) { 261 266 entity.resetPortalCooldown(); 262 267 BlockEntity blockEntity = world.getBlockEntity(pos.up());
+5 -5
src/main/java/net/lerariemann/infinity/block/custom/TimeBombBlock.java
··· 63 63 } 64 64 65 65 void activate(ServerWorld world, Path path) { 66 - ((Timebombable)world).timebomb(1); 66 + ((Timebombable)world).projectInfinity$timebomb(1); 67 67 try { 68 68 FileUtils.deleteDirectory(path.toFile()); 69 69 } catch (IOException ignored) { ··· 81 81 } 82 82 83 83 @Override 84 - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { 84 + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { 85 85 if (!world.isClient()) { 86 86 if (world.getRegistryKey().getValue().toString().contains("infinity")) { 87 87 ServerWorld w = ((ServerPlayerEntity)player).getServerWorld(); 88 - if (((Timebombable)w).isTimebobmed() == 0) { 88 + if (((Timebombable)w).projectInfinity$isTimebobmed() == 0) { 89 89 if (state.get(ACTIVE)) { 90 90 world.setBlockState(pos, Blocks.AIR.getDefaultState()); 91 91 world.getEntitiesByType(TypeFilter.instanceOf(AreaEffectCloudEntity.class), Box.of(pos.toCenterPos(), 1.0, 1.0, 1.0), Entity::isAlive). 92 92 forEach(e -> e.remove(Entity.RemovalReason.DISCARDED)); 93 93 return ActionResult.SUCCESS; 94 94 } //remove after regenerating a dimension 95 - if (player.getStackInHand(hand).isEmpty() && player.isSneaking()) { 95 + if (player.getStackInHand(Hand.MAIN_HAND).isEmpty() && player.isSneaking()) { 96 96 Path path = w.getServer().getSavePath(WorldSavePath.DATAPACKS).resolve(w.getRegistryKey().getValue().getPath()); 97 97 activate(w, path); 98 98 world.spawnEntity(genCloud(world, pos)); ··· 109 109 } //pick up 110 110 } 111 111 } 112 - else if (player.getStackInHand(hand).isEmpty()) { 112 + else if (player.getStackInHand(Hand.MAIN_HAND).isEmpty()) { 113 113 world.setBlockState(pos, Blocks.AIR.getDefaultState()); 114 114 player.getInventory().insertStack(ModBlocks.TIME_BOMB_ITEM.getDefaultStack()); 115 115 return ActionResult.SUCCESS;
+8 -2
src/main/java/net/lerariemann/infinity/block/custom/TransfiniteAltar.java
··· 1 1 package net.lerariemann.infinity.block.custom; 2 2 3 + import com.mojang.serialization.MapCodec; 3 4 import net.lerariemann.infinity.block.entity.ModBlockEntities; 4 5 import net.lerariemann.infinity.block.entity.TransfiniteAltarEntity; 5 6 import net.minecraft.block.*; ··· 20 21 import org.jetbrains.annotations.Nullable; 21 22 22 23 public class TransfiniteAltar extends BlockWithEntity { 24 + public static final MapCodec<TransfiniteAltar> CODEC = createCodec(TransfiniteAltar::new); 23 25 public static final BooleanProperty FLOWER = BooleanProperty.of("flower"); 24 26 public static final IntProperty COLOR = IntProperty.of("color", 0, 6); 25 27 public static final VoxelShape BASE_SHAPE = Block.createCuboidShape(1.5, 0, 1.5, 14.5, 14, 14.5); ··· 44 46 } 45 47 46 48 @Override 49 + protected MapCodec<? extends BlockWithEntity> getCodec() { 50 + return CODEC; 51 + } 52 + 53 + @Override 47 54 protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { 48 55 builder.add(COLOR); 49 56 builder.add(FLOWER); ··· 61 68 62 69 @Override 63 70 public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { 64 - if (!world.isClient) return checkType(type, ModBlockEntities.ALTAR, TransfiniteAltarEntity::serverTick); 65 - return null; 71 + return validateTicker(type, ModBlockEntities.ALTAR, world.isClient ? null : TransfiniteAltarEntity::serverTick); 66 72 } 67 73 68 74 public static void bumpAge(World world, BlockPos pos, BlockState state) {
+4 -4
src/main/java/net/lerariemann/infinity/block/custom/TransfiniteAltarBase.java
··· 67 67 } 68 68 69 69 @Override 70 - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { 71 - ItemStack itemStack = player.getStackInHand(hand); 70 + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { 71 + ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND); 72 72 if (!world.isClient) { 73 - String s = ((MinecraftServerAccess)(Objects.requireNonNull(world.getServer()))).getDimensionProvider().altarKey; 74 - boolean bl0 = s.isBlank() ? itemStack.isEmpty() : itemStack.isOf(Registries.ITEM.get(new Identifier(s))); 73 + String s = ((MinecraftServerAccess)(Objects.requireNonNull(world.getServer()))).projectInfinity$getDimensionProvider().altarKey; 74 + boolean bl0 = s.isBlank() ? itemStack.isEmpty() : itemStack.isOf(Registries.ITEM.get(Identifier.of(s))); 75 75 if (bl0) { 76 76 boolean bl = testSpace(world, pos); 77 77 if (!bl) {
+5 -5
src/main/java/net/lerariemann/infinity/block/entity/CosmicAltarEntity.java
··· 46 46 } 47 47 if(be.time == 1) { 48 48 ConfigGenerator.generateAll(world, pos.up(2), pos.up()); 49 - a.setDimensionProvider(); 49 + a.projectInfinity$setDimensionProvider(); 50 50 } 51 51 if(be.time == 2) { 52 52 for (int i : offsets) for (int j : offsets_y) for (int k : offsets) { ··· 69 69 } 70 70 71 71 @Override 72 - public void readNbt(NbtCompound nbt) { 73 - super.readNbt(nbt); 72 + public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { 73 + super.readNbt(nbt, registryLookup); 74 74 if (nbt.contains("time", NbtElement.INT_TYPE)) { 75 75 time = nbt.getInt("time"); 76 76 } ··· 85 85 } 86 86 87 87 @Override 88 - protected void writeNbt(NbtCompound nbt) { 89 - super.writeNbt(nbt); 88 + protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { 89 + super.writeNbt(nbt, registryLookup); 90 90 nbt.putInt("time", this.time); 91 91 NbtCompound mapnbt = new NbtCompound(); 92 92 for (String s : map.keySet()) {
+3 -4
src/main/java/net/lerariemann/infinity/block/entity/ModBlockEntities.java
··· 1 1 package net.lerariemann.infinity.block.entity; 2 2 3 - import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; 4 3 import net.lerariemann.infinity.InfinityMod; 5 4 import net.lerariemann.infinity.block.ModBlocks; 6 5 import net.minecraft.block.entity.BlockEntityType; ··· 15 14 public static void registerBlockEntities() { 16 15 NEITHER_PORTAL = Registry.register(Registries.BLOCK_ENTITY_TYPE, 17 16 InfinityMod.getId("neither_portal"), 18 - FabricBlockEntityTypeBuilder.create(NeitherPortalBlockEntity::new, 17 + BlockEntityType.Builder.create(NeitherPortalBlockEntity::new, 19 18 ModBlocks.NEITHER_PORTAL).build(null)); 20 19 ALTAR = Registry.register(Registries.BLOCK_ENTITY_TYPE, 21 20 InfinityMod.getId("altar_block_entity"), 22 - FabricBlockEntityTypeBuilder.create(TransfiniteAltarEntity::new, ModBlocks.ALTAR_LIT).build()); 21 + BlockEntityType.Builder.create(TransfiniteAltarEntity::new, ModBlocks.ALTAR_LIT).build()); 23 22 ALTAR_COSMIC = Registry.register(Registries.BLOCK_ENTITY_TYPE, 24 23 InfinityMod.getId("cosmic_block_entity"), 25 - FabricBlockEntityTypeBuilder.create(CosmicAltarEntity::new, ModBlocks.ALTAR_COSMIC).build()); 24 + BlockEntityType.Builder.create(CosmicAltarEntity::new, ModBlocks.ALTAR_COSMIC).build()); 26 25 } 27 26 }
+11 -10
src/main/java/net/lerariemann/infinity/block/entity/NeitherPortalBlockEntity.java
··· 1 1 package net.lerariemann.infinity.block.entity; 2 2 3 - import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; 3 + import net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity; 4 4 import net.minecraft.block.BlockState; 5 5 import net.minecraft.block.entity.BlockEntity; 6 6 import net.minecraft.nbt.NbtCompound; 7 7 import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; 8 + import net.minecraft.registry.RegistryWrapper; 8 9 import net.minecraft.screen.PropertyDelegate; 9 10 import net.minecraft.util.math.BlockPos; 10 11 import org.jetbrains.annotations.Nullable; 11 12 12 - public class NeitherPortalBlockEntity extends BlockEntity implements RenderAttachmentBlockEntity { 13 + public class NeitherPortalBlockEntity extends BlockEntity implements RenderDataBlockEntity { 13 14 private final PropertyDelegate propertyDelegate; 14 15 private long dimension; 15 16 private boolean isOpen; ··· 56 57 public void setOpen(boolean i) { 57 58 this.isOpen = i; 58 59 } 59 - public void writeNbt(NbtCompound tag) { 60 - super.writeNbt(tag); 60 + public void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { 61 + super.writeNbt(tag, registryLookup); 61 62 tag.putLong("Dimension", this.dimension); 62 63 tag.putBoolean("Open", this.isOpen); 63 64 } 64 65 65 - public void readNbt(NbtCompound tag) { 66 - super.readNbt(tag); 66 + public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { 67 + super.readNbt(tag, registryLookup); 67 68 this.dimension = tag.getLong("Dimension"); 68 69 this.isOpen = tag.getBoolean("Open"); 69 70 } ··· 75 76 } 76 77 77 78 @Override 78 - public NbtCompound toInitialChunkDataNbt() { 79 - return createNbt(); 79 + public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) { 80 + return createNbt(registryLookup); 80 81 } 81 82 82 83 @Override 83 - public Object getRenderAttachmentData() { 84 - return (int)dimension; 84 + public Object getRenderData() { 85 + return propertyDelegate.get(0); 85 86 } 86 87 }
+3 -3
src/main/java/net/lerariemann/infinity/block/entity/TransfiniteAltarEntity.java
··· 56 56 } 57 57 if(be.time == 10) { 58 58 ConfigGenerator.generateAll(world, pos.up(2), pos.up()); 59 - a.setDimensionProvider(); 59 + a.projectInfinity$setDimensionProvider(); 60 60 } 61 61 } 62 62 if(stage == 0 && be.time == 19) for (int i : offsets) for (int k : offsets) ··· 65 65 world.playSound(null, pos, SoundEvents.BLOCK_DISPENSER_DISPENSE, SoundCategory.BLOCKS, 1f, 1f); 66 66 for (int i : offsets) for (int k : offsets) { 67 67 if (i == 0 && k == 0) world.setBlockState(pos.add(i, -1, k), Blocks.STONE.getDefaultState()); 68 - else world.setBlockState(pos.add(i, -1, k), Registries.BLOCK.get(new Identifier( 69 - a.getDimensionProvider().randomName(r, "full_blocks"))).getDefaultState()); 68 + else world.setBlockState(pos.add(i, -1, k), Registries.BLOCK.get(Identifier.of( 69 + a.projectInfinity$getDimensionProvider().randomName(r, "full_blocks"))).getDefaultState()); 70 70 } 71 71 } 72 72 be.time+=1;
+2 -4
src/main/java/net/lerariemann/infinity/dimensions/RandomDimension.java
··· 1 1 package net.lerariemann.infinity.dimensions; 2 2 3 - 4 3 import net.lerariemann.infinity.InfinityMod; 5 4 import net.lerariemann.infinity.access.MinecraftServerAccess; 6 5 import net.lerariemann.infinity.options.RandomInfinityOptions; ··· 16 15 import java.nio.file.Files; 17 16 import java.nio.file.Paths; 18 17 import java.util.*; 19 - 20 18 21 19 public class RandomDimension { 22 20 public final long id; ··· 45 43 public RandomDimension(long i, MinecraftServer server) { 46 44 random = new Random(i); 47 45 this.server = server; 48 - PROVIDER = ((MinecraftServerAccess)(server)).getDimensionProvider(); 46 + PROVIDER = ((MinecraftServerAccess)(server)).projectInfinity$getDimensionProvider(); 49 47 id = i; 50 48 name = PROVIDER.easterizer.keyOf(i); 51 49 fullname = InfinityMod.MOD_ID + ":" + name; ··· 171 169 NbtCompound packMcmeta() { 172 170 NbtCompound res = new NbtCompound(); 173 171 NbtCompound pack = new NbtCompound(); 174 - pack.putInt("pack_format", 10); 172 + pack.putInt("pack_format", 34); 175 173 pack.putString("description", "Dimension #" + id); 176 174 res.put("pack", pack); 177 175 return res;
+2 -1
src/main/java/net/lerariemann/infinity/dimensions/RandomDimensionType.java
··· 41 41 data.putInt("monster_spawn_block_light_limit", random.nextInt(16)); 42 42 NbtCompound lightLevel = new NbtCompound(); 43 43 lightLevel.putString("type", "uniform"); 44 - lightLevel.put("value", RandomProvider.genBounds(0, random.nextInt(16))); 44 + lightLevel.putInt("min_inclusive", 0); 45 + lightLevel.putInt("max_inclusive", random.nextInt(16)); 45 46 data.put("monster_spawn_light_level", lightLevel); 46 47 data.putString("infiniburn", dim.PROVIDER.randomName(random, "tags")); 47 48 String s = dim.PROVIDER.randomName(random, "effects");
+23 -64
src/main/java/net/lerariemann/infinity/dimensions/RandomProvider.java
··· 10 10 import net.minecraft.util.Identifier; 11 11 import net.minecraft.world.biome.Biome; 12 12 13 - import java.io.File; 14 13 import java.io.IOException; 15 - import java.nio.charset.StandardCharsets; 16 - import java.nio.file.Files; 17 - import java.nio.file.Path; 18 14 import java.nio.file.Paths; 19 15 import java.util.*; 20 16 ··· 100 96 double size = trees.size(); 101 97 NbtCompound c = new NbtCompound(); 102 98 NbtList l = new NbtList(); 103 - c.put("default", notRandomTree(trees.get(0), "minecraft:grass_block")); 99 + c.put("default", notRandomTree(trees.getFirst(), "minecraft:grass_block")); 104 100 for (int i = 1; i < size; i++) { 105 101 NbtCompound c1 = new NbtCompound(); 106 102 c1.put("feature", notRandomTree(trees.get(i), "minecraft:grass_block")); ··· 119 115 } 120 116 121 117 void genCorePack() { 122 - extraRegistry.get("palettes").keys.forEach(e -> { 123 - if (!(Paths.get(savingPath + "/data/" + InfinityMod.MOD_ID + "/structures/" 124 - + ((NbtCompound)e).getString("name") + ".nbt")).toFile().exists()) { 125 - savePortalFromPalette((NbtCompound)e); 126 - } 127 - }); 128 118 saveTrees(); 129 119 if (!(Paths.get(savingPath + "/pack.mcmeta")).toFile().exists()) savePackMcmeta(); 130 120 } 131 121 132 - void savePortalFromPalette(NbtCompound rawdata) { 133 - String name = rawdata.getString("name"); 134 - NbtCompound datanbt = CommonIO.read(configPath + "util/portal/main.json"); 135 - NbtCompound moredata = CommonIO.readCarefully(configPath + 136 - "util/portal/palette_" + (rawdata.getBoolean("properties") ? "wood" : "stone") + ".json", 137 - rawdata.getString("plank"), 138 - rawdata.getString("log"), 139 - rawdata.getString("stair"), 140 - rawdata.getString("stair")); 141 - datanbt.put("palette", moredata.get("palette")); 142 - String path = savingPath + "/data/" + InfinityMod.MOD_ID + "/structures"; 143 - Path dir = Paths.get(path); 144 - Path file = Paths.get(path + "/" + name + ".nbt"); 145 - List<String> lines = new ArrayList<>(); 146 - try { 147 - Files.createDirectories(dir); 148 - Files.write(file, lines, StandardCharsets.UTF_8); 149 - NbtIo.write(datanbt, new File(file.toUri())); 150 - } catch (IOException e) { 151 - throw new RuntimeException(e); 152 - } 153 - CommonIO.write(CommonIO.readCarefully(configPath + "util/portal/pool.json", name), 154 - savingPath + "/data/" + InfinityMod.MOD_ID + "/worldgen/template_pool", name + ".json"); 155 - } 156 - 157 122 void savePackMcmeta() { 158 123 NbtCompound res = new NbtCompound(); 159 124 NbtCompound pack = new NbtCompound(); 160 - pack.putInt("pack_format", 10); 125 + pack.putInt("pack_format", 34); 161 126 pack.putString("description", "Common template pools for Infinite Dimensions"); 162 127 res.put("pack", pack); 163 128 CommonIO.write(res, savingPath, "pack.mcmeta"); ··· 336 301 return res; 337 302 } 338 303 339 - static NbtCompound genBounds(int lbound, int bound) { 340 - NbtCompound value = new NbtCompound(); 341 - value.putInt("min_inclusive", lbound); 342 - value.putInt("max_inclusive", bound); 343 - return value; 304 + static void addBounds(NbtCompound res, int lbound, int bound) { 305 + res.putInt("min_inclusive", lbound); 306 + res.putInt("max_inclusive", bound); 344 307 } 345 308 346 - static NbtCompound genBounds(Random random, int lbound, int bound) { 309 + static void addBounds(NbtCompound res, Random random, int lbound, int bound) { 347 310 int a = random.nextInt(lbound, bound); 348 311 int b = random.nextInt(lbound, bound); 349 - return genBounds(Math.min(a, b), Math.max(a, b)); 312 + addBounds(res, Math.min(a, b), Math.max(a, b)); 350 313 } 351 314 352 315 public static NbtElement intProvider(Random random, int bound, boolean acceptDistributions) { ··· 364 327 } 365 328 case 1, 2 -> { 366 329 res.putString("type", i==1 ? "uniform" : "biased_to_bottom"); 367 - res.put("value", genBounds(random, lbound, bound)); 330 + addBounds(res, random, lbound, bound); 368 331 return res; 369 332 } 370 333 case 4 -> { 371 334 res.putString("type", "clamped"); 372 - NbtCompound value = genBounds(random, lbound, bound); 373 - value.put("source", intProvider(random, lbound, bound, false)); 374 - res.put("value", value); 335 + addBounds(res, random, lbound, bound); 336 + res.put("source", intProvider(random, lbound, bound, false)); 375 337 return res; 376 338 } 377 339 case 3 -> { 378 340 res.putString("type", "clamped_normal"); 379 - NbtCompound value = genBounds(random, lbound, bound); 380 - value.putDouble("mean", lbound + random.nextDouble()*(bound-lbound)); 381 - value.putDouble("deviation", random.nextExponential()); 382 - res.put("value", value); 341 + addBounds(res, random, lbound, bound); 342 + res.putDouble("mean", lbound + random.nextDouble()*(bound-lbound)); 343 + res.putDouble("deviation", random.nextExponential()); 383 344 return res; 384 345 } 385 346 case 5 -> { ··· 453 414 String[] types = new String[]{"uniform", "clamped_normal", "trapezoid"}; 454 415 NbtCompound res = new NbtCompound(); 455 416 res.putString("type", types[i]); 456 - NbtCompound value = new NbtCompound(); 457 417 float a = random.nextFloat(lbound, bound); 458 418 float b = random.nextFloat(lbound, bound); 459 419 float min = Math.min(a, b); 460 420 float max = Math.max(a, b); 461 421 switch (i) { 462 422 case 0 -> { 463 - value.putFloat("max_exclusive", max); 464 - value.putFloat("min_inclusive", min); 423 + res.putFloat("max_exclusive", max); 424 + res.putFloat("min_inclusive", min); 465 425 } 466 426 case 1 -> { 467 - value.putFloat("max", max); 468 - value.putFloat("min", min); 469 - value.putFloat("mean", random.nextFloat(min, max)); 470 - value.putFloat("deviation", random.nextFloat(max - min)); 427 + res.putFloat("max", max); 428 + res.putFloat("min", min); 429 + res.putFloat("mean", random.nextFloat(min, max)); 430 + res.putFloat("deviation", random.nextFloat(max - min)); 471 431 } 472 432 case 2 -> { 473 - value.putFloat("max", max); 474 - value.putFloat("min", min); 475 - value.putFloat("plateau", random.nextFloat(max - min)); 433 + res.putFloat("max", max); 434 + res.putFloat("min", min); 435 + res.putFloat("plateau", random.nextFloat(max - min)); 476 436 } 477 437 } 478 - res.put("value", value); 479 438 return res; 480 439 } 481 440 ··· 484 443 WeighedStructure<String> biomes = registry.get("biomes"); 485 444 int i = 0; 486 445 while(i < biomes.keys.size()) { 487 - if (!reg.containsId(new Identifier(biomes.keys.get(i)))) { 446 + if (!reg.containsId(Identifier.of(biomes.keys.get(i)))) { 488 447 biomes.kick(i); 489 448 } 490 449 else i++;
+16 -17
src/main/java/net/lerariemann/infinity/entity/ModEntities.java
··· 2 2 3 3 import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; 4 4 import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; 5 - import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; 6 5 import net.lerariemann.infinity.InfinityMod; 7 6 import net.lerariemann.infinity.access.MinecraftServerAccess; 8 7 import net.lerariemann.infinity.entity.custom.*; ··· 38 37 e.setStackInHand(Hand.OFF_HAND, from.getStackInHand(Hand.OFF_HAND)); 39 38 } 40 39 41 - public static <T extends Entity> EntityType<T> register(String id, FabricEntityTypeBuilder<T> type) { 40 + public static <T extends Entity> EntityType<T> register(String id, EntityType.Builder<T> type) { 42 41 return Registry.register(Registries.ENTITY_TYPE, InfinityMod.getId(id), type.build()); 43 42 } 44 43 public static final EntityType<DimensionalSlime> DIMENSIONAL_SLIME = register("dimensional_slime", 45 - FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, DimensionalSlime::new) 46 - .dimensions(EntityDimensions.changing(2.04f, 2.04f)).trackRangeChunks(10)); 44 + EntityType.Builder.create(DimensionalSlime::new, SpawnGroup.MONSTER) 45 + .dimensions(0.52f, 0.52f).maxTrackingRange(10)); 47 46 public static final EntityType<DimensionalSkeleton> DIMENSIONAL_SKELETON = register("dimensional_skeleton", 48 - FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, DimensionalSkeleton::new) 49 - .dimensions(EntityDimensions.fixed(0.6f, 1.99f)).trackRangeChunks(8)); 47 + EntityType.Builder.create(DimensionalSkeleton::new, SpawnGroup.MONSTER) 48 + .dimensions(0.6f, 1.99f).maxTrackingRange(8)); 50 49 public static final EntityType<DimensionalCreeper> DIMENSIONAL_CREEPER = register("dimensional_creeper", 51 - FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, DimensionalCreeper::new) 52 - .dimensions(EntityDimensions.fixed(0.6f, 1.7f)).trackRangeChunks(8)); 50 + EntityType.Builder.create(DimensionalCreeper::new, SpawnGroup.MONSTER) 51 + .dimensions(0.6f, 1.7f).maxTrackingRange(8)); 53 52 public static final EntityType<ChaosPawn> CHAOS_PAWN = register("chaos_pawn", 54 - FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, ChaosPawn::new) 55 - .dimensions(EntityDimensions.fixed(0.6f, 1.8f)).trackRangeChunks(10)); 53 + EntityType.Builder.create(ChaosPawn::new, SpawnGroup.MONSTER) 54 + .dimensions(0.6f, 1.8f).maxTrackingRange(10)); 56 55 57 56 public static void registerEntities() { 58 57 FabricDefaultAttributeRegistry.register(DIMENSIONAL_SLIME, DimensionalSlime.createAttributes()); ··· 63 62 64 63 public static boolean canSpawnInDark(EntityType<? extends HostileEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) { 65 64 return HostileEntity.canSpawnInDark(type, world, spawnReason, pos, random) && 66 - ((MinecraftServerAccess)world.toServerWorld().getServer()).getDimensionProvider().rule("chaosMobsEnabled"); 65 + ((MinecraftServerAccess)world.toServerWorld().getServer()).projectInfinity$getDimensionProvider().rule("chaosMobsEnabled"); 67 66 } 68 67 69 68 public static void registerSpawnRestrictions() { 70 - SpawnRestriction.register(DIMENSIONAL_SLIME, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, DimensionalSlime::canSpawn); 71 - SpawnRestriction.register(DIMENSIONAL_SKELETON, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, ModEntities::canSpawnInDark); 72 - SpawnRestriction.register(DIMENSIONAL_CREEPER, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, ModEntities::canSpawnInDark); 73 - SpawnRestriction.register(CHAOS_PAWN, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, ChaosPawn::canSpawn); 74 - SpawnRestriction.register(EntityType.SNIFFER, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn); 75 - SpawnRestriction.register(EntityType.CAMEL, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn); 69 + SpawnRestriction.register(DIMENSIONAL_SLIME, SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, DimensionalSlime::canSpawn); 70 + SpawnRestriction.register(DIMENSIONAL_SKELETON, SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, ModEntities::canSpawnInDark); 71 + SpawnRestriction.register(DIMENSIONAL_CREEPER, SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, ModEntities::canSpawnInDark); 72 + SpawnRestriction.register(CHAOS_PAWN, SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, ChaosPawn::canSpawn); 73 + SpawnRestriction.register(EntityType.SNIFFER, SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn); 74 + SpawnRestriction.register(EntityType.CAMEL, SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::isValidNaturalSpawn); 76 75 } 77 76 78 77 public static void registerEntityRenderers() {
+4 -14
src/main/java/net/lerariemann/infinity/entity/client/ChaosPawnTint.java
··· 23 23 24 24 public void renderOneLayer(MatrixStack matrixStack, VertexConsumer vertexConsumer, int light, int overlay, ChaosPawn livingEntity, ModelPart part, String name) { 25 25 int color; 26 - float f = 0.0f, g = 0.0f, h = 0.0f; 27 - boolean bl = false; 28 26 color = livingEntity.getColors().getInt(name); 29 27 if (livingEntity.hasCustomName()) { 30 28 String s = livingEntity.getName().getString(); ··· 34 32 int p = n % o; 35 33 int q = (n + 1) % o; 36 34 float r = (livingEntity.age % 25) / 25.0f; 37 - float[] fs = SheepEntity.getRgbColor(DyeColor.byId(p)); 38 - float[] gs = SheepEntity.getRgbColor(DyeColor.byId(q)); 39 - f = fs[0] * (1.0f - r) + gs[0] * r; 40 - g = fs[1] * (1.0f - r) + gs[1] * r; 41 - h = fs[2] * (1.0f - r) + gs[2] * r; 42 - bl = true; 35 + int fs = SheepEntity.getRgbColor(DyeColor.byId(p)); 36 + int gs = SheepEntity.getRgbColor(DyeColor.byId(q)); 37 + color = (int)(fs * (1 - r) + gs * r); 43 38 } 44 39 if ("hue".equals(s)) { 45 40 int n = livingEntity.age + (name.equals("hat") ? 200 : 0) + livingEntity.getId(); ··· 48 43 color = Color.getHSBColor(hue, 1.0f, 1.0f).getRGB(); 49 44 } 50 45 } 51 - if (!bl) { 52 - f = (float)(color >> 16 & 0xFF) / 255.0f; 53 - g = (float)(color >> 8 & 0xFF) / 255.0f; 54 - h = (float)(color & 0xFF) / 255.0f; 55 - } 56 - part.render(matrixStack, vertexConsumer, light, overlay, f, g, h, 1.0f); 46 + part.render(matrixStack, vertexConsumer, light, overlay, color); 57 47 } 58 48 59 49 @Override
+2 -1
src/main/java/net/lerariemann/infinity/entity/client/DimensionalSkeletonRenderer.java
··· 1 1 package net.lerariemann.infinity.entity.client; 2 2 3 + import net.lerariemann.infinity.entity.custom.DimensionalSkeleton; 3 4 import net.minecraft.client.render.entity.EntityRendererFactory; 4 5 import net.minecraft.client.render.entity.SkeletonEntityRenderer; 5 6 import net.minecraft.client.render.entity.model.EntityModelLayers; 6 7 import net.minecraft.client.render.entity.model.SkeletonEntityModel; 7 8 8 - public class DimensionalSkeletonRenderer extends SkeletonEntityRenderer { 9 + public class DimensionalSkeletonRenderer extends SkeletonEntityRenderer<DimensionalSkeleton> { 9 10 public DimensionalSkeletonRenderer(EntityRendererFactory.Context context) { 10 11 super(context); 11 12 this.addFeature(new TintedLayerRenderer<>(this, new SkeletonEntityModel<>(context.getPart(EntityModelLayers.SKELETON))));
+2 -5
src/main/java/net/lerariemann/infinity/entity/client/TintedLayerRenderer.java
··· 11 11 import net.minecraft.client.render.entity.model.EntityModel; 12 12 import net.minecraft.client.util.math.MatrixStack; 13 13 import net.minecraft.entity.mob.MobEntity; 14 - import org.joml.Vector3f; 15 14 16 15 public class TintedLayerRenderer<T extends MobEntity, S extends EntityModel<T>> extends FeatureRenderer<T, S> { 17 16 private final S model; ··· 31 30 (this.getContextModel()).copyStateTo(this.model); 32 31 this.model.animateModel(livingEntity, f, g, h); 33 32 this.model.setAngles(livingEntity, f, g, j, k, l); 34 - Vector3f color = new Vector3f(1.0f, 1.0f, 1.0f); 35 - float alpha = 1.0f; 33 + int color = 16777215; 36 34 if (livingEntity instanceof TintableEntity) { 37 35 color = ((TintableEntity)livingEntity).getColor(); 38 - alpha = ((TintableEntity)livingEntity).getAlpha(); 39 36 } 40 - this.model.render(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0f), color.x, color.y, color.z, alpha); 37 + this.model.render(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0f), color); 41 38 } 42 39 }
+20 -16
src/main/java/net/lerariemann/infinity/entity/custom/ChaosPawn.java
··· 19 19 import net.minecraft.entity.mob.HostileEntity; 20 20 import net.minecraft.entity.player.PlayerEntity; 21 21 import net.minecraft.item.ItemStack; 22 + import net.minecraft.loot.LootTable; 22 23 import net.minecraft.nbt.NbtCompound; 23 24 import net.minecraft.registry.Registries; 25 + import net.minecraft.registry.RegistryKey; 26 + import net.minecraft.registry.RegistryKeys; 24 27 import net.minecraft.server.world.ServerWorld; 25 28 import net.minecraft.sound.SoundEvent; 26 29 import net.minecraft.sound.SoundEvents; ··· 88 91 } 89 92 90 93 @Override 91 - protected void initDataTracker() { 92 - super.initDataTracker(); 93 - this.dataTracker.startTracking(colors, new NbtCompound()); 94 - this.dataTracker.startTracking(special_case, -1); 94 + protected void initDataTracker(DataTracker.Builder builder) { 95 + super.initDataTracker(builder); 96 + builder.add(colors, new NbtCompound()); 97 + builder.add(special_case, -1); 95 98 } 96 99 @Override 97 100 protected void initGoals() { ··· 127 130 } 128 131 129 132 @Override 130 - public Identifier getLootTableId() { 131 - return switch (this.dataTracker.get(special_case)) { 132 - case 0 -> new Identifier("infinity:entities/chaos_pawn_black"); 133 - case 1 -> new Identifier("infinity:entities/chaos_pawn_white"); 134 - default -> new Identifier(""); 133 + public RegistryKey<LootTable> getLootTableId() { 134 + Identifier i = switch (this.dataTracker.get(special_case)) { 135 + case 0 -> Identifier.of("infinity:entities/chaos_pawn_black"); 136 + case 1 -> Identifier.of("infinity:entities/chaos_pawn_white"); 137 + default -> Identifier.of(""); 135 138 }; 139 + return RegistryKey.of(RegistryKeys.LOOT_TABLE, i); 136 140 } 137 141 138 142 public void setAllColors(int color) { ··· 183 187 184 188 @Override 185 189 @Nullable 186 - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt) { 190 + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData) { 187 191 Random r = new Random(); 188 192 setAllColors(r, world.getBlockState(this.getBlockPos().down(2))); 189 193 double i = 15*r.nextExponential(); 190 - this.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).setBaseValue(i); 194 + Objects.requireNonNull(this.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH)).setBaseValue(i); 191 195 this.setHealth((float)i); 192 196 int a; 193 197 if ((a = (int)(0.1*i)) > 0) { 194 - this.equipLootStack(EquipmentSlot.HEAD, Registries.ITEM.get(new Identifier( 195 - ((MinecraftServerAccess)Objects.requireNonNull(world.getServer())).getDimensionProvider().randomName(r, "items"))) 198 + this.equipLootStack(EquipmentSlot.HEAD, Registries.ITEM.get(Identifier.of( 199 + ((MinecraftServerAccess)Objects.requireNonNull(world.getServer())).projectInfinity$getDimensionProvider().randomName(r, "items"))) 196 200 .getDefaultStack().copyWithCount(a)); 197 - ((MobEntityAccess)this).setPersistent(false); 201 + ((MobEntityAccess)this).projectInfinity$setPersistent(false); 198 202 } 199 - return super.initialize(world, difficulty, spawnReason, entityData, entityNbt); 203 + return super.initialize(world, difficulty, spawnReason, entityData); 200 204 } 201 205 202 206 @Override ··· 207 211 208 212 public static boolean canSpawn(EntityType<ChaosPawn> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, net.minecraft.util.math.random.Random random) { 209 213 return world.getDifficulty() != Difficulty.PEACEFUL && 210 - ((MinecraftServerAccess)world.toServerWorld().getServer()).getDimensionProvider().rule("chaosMobsEnabled"); 214 + ((MinecraftServerAccess)world.toServerWorld().getServer()).projectInfinity$getDimensionProvider().rule("chaosMobsEnabled"); 211 215 } 212 216 }
+11 -11
src/main/java/net/lerariemann/infinity/entity/custom/DimensionalCreeper.java
··· 51 51 } 52 52 @Override 53 53 @Nullable 54 - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt) { 54 + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData) { 55 55 MinecraftServer s = world.toServerWorld().getServer(); 56 56 reg = s.getRegistryManager().get(RegistryKeys.BIOME); 57 - String biomename = ((MinecraftServerAccess)(s)).getDimensionProvider().registry.get("biomes").getElement(world.getRandom().nextDouble()); 58 - Biome b = reg.get(new Identifier(biomename)); 57 + String biomename = ((MinecraftServerAccess)(s)).projectInfinity$getDimensionProvider().registry.get("biomes").getElement(world.getRandom().nextDouble()); 58 + Biome b = reg.get(Identifier.of(biomename)); 59 59 this.setColor(b != null ? b.getFoliageColor() : 7842607); 60 60 this.setRange(8 + random.nextFloat()*24); 61 61 this.setBiome(biomename); 62 - return super.initialize(world, difficulty, spawnReason, entityData, entityNbt); 62 + return super.initialize(world, difficulty, spawnReason, entityData); 63 63 } 64 64 65 65 @Override 66 - protected void initDataTracker() { 67 - super.initDataTracker(); 68 - this.dataTracker.startTracking(color, 7842607); 69 - this.dataTracker.startTracking(range, 16.0f); 70 - this.dataTracker.startTracking(biome, "minecraft:plains"); 66 + protected void initDataTracker(DataTracker.Builder builder) { 67 + super.initDataTracker(builder); 68 + builder.add(color, 7842607); 69 + builder.add(range, 16.0f); 70 + builder.add(biome, "minecraft:plains"); 71 71 } 72 72 public void setBiome(String s) { 73 73 this.dataTracker.set(biome, s); 74 74 } 75 75 public Biome getBiome() { 76 - return reg.get(new Identifier(getBiomeId())); 76 + return reg.get(Identifier.of(getBiomeId())); 77 77 } 78 78 public String getBiomeId() { 79 79 return this.dataTracker.get(biome); ··· 175 175 serverWorld.getChunkManager().getNoiseConfig().getMultiNoiseSampler()); 176 176 chunk.setNeedsSaving(true); 177 177 } 178 - serverWorld.getChunkManager().threadedAnvilChunkStorage.sendChunkBiomePackets(list); 178 + serverWorld.getChunkManager().chunkLoadingManager.sendChunkBiomePackets(list); 179 179 } 180 180 } 181 181 this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), f, World.ExplosionSourceType.NONE);
+21 -26
src/main/java/net/lerariemann/infinity/entity/custom/DimensionalSkeleton.java
··· 1 1 package net.lerariemann.infinity.entity.custom; 2 2 3 3 import net.lerariemann.infinity.entity.ModEntities; 4 + import net.minecraft.component.DataComponentTypes; 5 + import net.minecraft.component.type.PotionContentsComponent; 4 6 import net.minecraft.entity.EntityData; 5 7 import net.minecraft.entity.EntityType; 6 8 import net.minecraft.entity.SpawnReason; ··· 9 11 import net.minecraft.entity.data.TrackedDataHandlerRegistry; 10 12 import net.minecraft.entity.effect.StatusEffect; 11 13 import net.minecraft.entity.effect.StatusEffectCategory; 14 + import net.minecraft.entity.effect.StatusEffectInstance; 12 15 import net.minecraft.entity.mob.SkeletonEntity; 13 16 import net.minecraft.entity.player.PlayerEntity; 14 17 import net.minecraft.item.ItemStack; 15 18 import net.minecraft.item.ItemUsage; 16 19 import net.minecraft.item.Items; 17 20 import net.minecraft.nbt.NbtCompound; 18 - import net.minecraft.nbt.NbtList; 19 21 import net.minecraft.particle.ParticleTypes; 20 - import net.minecraft.potion.PotionUtil; 21 - import net.minecraft.potion.Potions; 22 22 import net.minecraft.registry.Registries; 23 23 import net.minecraft.registry.Registry; 24 24 import net.minecraft.server.world.ServerWorld; ··· 63 63 64 64 @Override 65 65 @Nullable 66 - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt) { 66 + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData) { 67 67 Random r = new Random(); 68 68 List<Identifier> a = new ArrayList<>(); 69 69 reg.getIds().forEach(i -> { ··· 73 73 this.setEffect(e); 74 74 this.setColorRaw(Objects.requireNonNull(reg.get(e)).getColor()); 75 75 this.setDuration(r.nextInt(200)); 76 - return super.initialize(world, difficulty, spawnReason, entityData, entityNbt); 76 + return super.initialize(world, difficulty, spawnReason, entityData); 77 77 } 78 78 79 79 @Override 80 - protected void initDataTracker() { 81 - super.initDataTracker(); 82 - this.dataTracker.startTracking(effect, "luck"); 83 - this.dataTracker.startTracking(duration, 200); 84 - this.dataTracker.startTracking(color, 0); 80 + protected void initDataTracker(DataTracker.Builder builder) { 81 + super.initDataTracker(builder); 82 + builder.add(effect, "luck"); 83 + builder.add(duration, 200); 84 + builder.add(color, 0); 85 85 } 86 86 87 87 public boolean isFriendly() { ··· 112 112 ModEntities.copy(this, newSkeleton); 113 113 newSkeleton.setDuration(this.getDuration()); 114 114 String i = effect_lookup.get(this.getEffectRaw()); 115 - StatusEffect e = reg.get(new Identifier(i)); 115 + StatusEffect e = reg.get(Identifier.of(i)); 116 116 newSkeleton.setEffectRaw(i); 117 117 if (e!= null) newSkeleton.setColorRaw(e.getColor()); 118 118 this.getWorld().spawnEntity(newSkeleton); ··· 121 121 } 122 122 } 123 123 if (itemStack.isOf(Items.GLASS_BOTTLE)) { 124 - ItemStack itemStack2 = setPotion(Items.LINGERING_POTION.getDefaultStack(), this.getEffectRawId(), this.getDuration() * 60); 124 + ItemStack itemStack2 = setPotion(Items.LINGERING_POTION.getDefaultStack(), this.getColor(), this.getEffectRaw(), this.getDuration() * 60); 125 125 ItemStack itemStack3 = ItemUsage.exchangeStack(itemStack, player, itemStack2, false); 126 126 player.setStackInHand(hand, itemStack3); 127 127 this.playSound(SoundEvents.ENTITY_COW_MILK, 1.0f, 1.0f); ··· 136 136 return super.interactMob(player, hand); 137 137 } 138 138 139 - 140 139 public void setEffectRaw(String c) { 141 140 this.dataTracker.set(effect, c); 142 141 } ··· 146 145 public String getEffectRaw() { 147 146 return this.dataTracker.get(effect); 148 147 } 149 - public int getEffectRawId() { 150 - return reg.getRawId(getEffect()); 151 - } 152 148 public void setEffect(Identifier i) { 153 149 setEffectRaw(i.toString()); 154 150 } 155 151 public StatusEffect getEffect() { 156 - return reg.get(new Identifier(getEffectRaw())); 152 + return reg.get(Identifier.of(getEffectRaw())); 157 153 } 158 154 public void setDuration(int i) { 159 155 this.dataTracker.set(duration, i); ··· 176 172 this.setColorRaw(nbt.getInt("color")); 177 173 } 178 174 179 - public static ItemStack setPotion(ItemStack stack, int effect, int duration) { 180 - NbtList effects = new NbtList(); 181 - NbtCompound compound = new NbtCompound(); 182 - compound.putInt("Id", effect); 183 - compound.putInt("Duration", duration); 184 - effects.add(compound); 185 - PotionUtil.setPotion(stack, Potions.WATER); 186 - stack.getOrCreateNbt().put("CustomPotionEffects", effects); 175 + public static ItemStack setPotion(ItemStack stack, int color, String effect, int duration) { 176 + NbtCompound poteffect = new NbtCompound(); 177 + poteffect.putString("id", effect); 178 + poteffect.putInt("duration", duration); 179 + List<StatusEffectInstance> customEffects = new ArrayList<>(); 180 + customEffects.add(StatusEffectInstance.fromNbt(poteffect)); 181 + stack.set(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Optional.empty(), Optional.of(color), customEffects)); 187 182 return stack; 188 183 } 189 184 190 185 @Override 191 186 public ItemStack getProjectileType(ItemStack stack) { 192 - return setPotion(Items.TIPPED_ARROW.getDefaultStack(), this.getEffectRawId(), this.getDuration()); 187 + return setPotion(Items.TIPPED_ARROW.getDefaultStack(), this.getColor(), this.getEffectRaw(), this.getDuration()); 193 188 } 194 189 195 190 @Override
+27 -31
src/main/java/net/lerariemann/infinity/entity/custom/DimensionalSlime.java
··· 16 16 import net.minecraft.entity.data.TrackedDataHandlerRegistry; 17 17 import net.minecraft.entity.mob.HostileEntity; 18 18 import net.minecraft.entity.mob.SlimeEntity; 19 + import net.minecraft.loot.LootTable; 19 20 import net.minecraft.nbt.NbtCompound; 20 21 import net.minecraft.particle.DustParticleEffect; 21 22 import net.minecraft.particle.ParticleEffect; 22 23 import net.minecraft.registry.Registries; 24 + import net.minecraft.registry.RegistryKey; 23 25 import net.minecraft.sound.SoundEvent; 24 26 import net.minecraft.text.Text; 25 27 import net.minecraft.util.Identifier; 26 28 import net.minecraft.util.math.BlockPos; 27 29 import net.minecraft.world.*; 28 30 import org.jetbrains.annotations.Nullable; 29 - import org.joml.Vector3f; 30 31 31 32 import java.util.Objects; 32 33 import java.util.Random; 33 34 34 35 public class DimensionalSlime extends SlimeEntity implements TintableEntity { 35 36 public static final TrackedData<BlockState> core = DataTracker.registerData(DimensionalSlime.class, TrackedDataHandlerRegistry.BLOCK_STATE); 36 - public static final TrackedData<Vector3f> color = DataTracker.registerData(DimensionalSlime.class, TrackedDataHandlerRegistry.VECTOR3F); 37 + public static final TrackedData<Integer> color = DataTracker.registerData(DimensionalSlime.class, TrackedDataHandlerRegistry.INTEGER); 37 38 38 39 public DimensionalSlime(EntityType<? extends DimensionalSlime> entityType, World world) { 39 40 super(entityType, world); ··· 55 56 } 56 57 57 58 @Override 58 - protected void initDataTracker() { 59 - super.initDataTracker(); 60 - this.dataTracker.startTracking(core, Blocks.STONE.getDefaultState()); 61 - this.dataTracker.startTracking(color, new Vector3f(0.0f, 0.0f, 0.0f)); 59 + protected void initDataTracker(DataTracker.Builder builder) { 60 + super.initDataTracker(builder); 61 + builder.add(core, Blocks.STONE.getDefaultState()); 62 + builder.add(color, 0); 62 63 } 63 64 64 65 public static DefaultAttributeContainer.Builder createAttributes() { ··· 67 68 68 69 @Override 69 70 @Nullable 70 - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt) { 71 - RandomProvider p = ((MinecraftServerAccess)(Objects.requireNonNull(world.getServer()))).getDimensionProvider(); 71 + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData) { 72 + RandomProvider p = ((MinecraftServerAccess)(Objects.requireNonNull(world.getServer()))).projectInfinity$getDimensionProvider(); 72 73 Random r = new Random(); 73 - this.dataTracker.set(core, Registries.BLOCK.get(new Identifier(p.randomName(r, "all_blocks"))).getDefaultState()); 74 - Vector3f c = new Vector3f(r.nextFloat(), r.nextFloat(), r.nextFloat()); 75 - this.dataTracker.set(color, c); 76 - return super.initialize(world, difficulty, spawnReason, entityData, entityNbt); 74 + this.dataTracker.set(core, Registries.BLOCK.get(Identifier.of(p.randomName(r, "all_blocks"))).getDefaultState()); 75 + this.dataTracker.set(color, r.nextInt(16777216)); 76 + return super.initialize(world, difficulty, spawnReason, entityData); 77 77 } 78 78 79 79 @Override ··· 81 81 return world.doesNotIntersectEntities(this); 82 82 } 83 83 84 - public void setColor(Vector3f c) { 84 + public void setColor(int c) { 85 85 this.dataTracker.set(color, c); 86 86 } 87 87 public void setCore(BlockState c) { 88 88 this.dataTracker.set(core, c); 89 89 } 90 90 @Override 91 - public Vector3f getColor() { 92 - Vector3f v = getColorNamed(); 93 - if (v!=null) return v; 91 + public int getColor() { 92 + int v = getColorNamed(); 93 + if (v!=-1) return v; 94 94 return this.dataTracker.get(color); 95 95 } 96 - @Override 97 - public float getAlpha() {return 1.0f;} 98 96 99 97 public BlockState getCore() { 100 98 return this.dataTracker.get(core); ··· 102 100 103 101 @Override 104 102 protected ParticleEffect getParticles() { 105 - return new DustParticleEffect(this.getColor(), 1.0f); 103 + return new DustParticleEffect(colorFromInt(this.getColor()), 1.0f); 106 104 } 107 105 @Override 108 106 protected SoundEvent getHurtSound(DamageSource source) { 109 - return this.getCore().getBlock().getSoundGroup(this.getCore()).getHitSound(); 107 + return this.getCore().getSoundGroup().getHitSound(); 110 108 } 111 109 @Override 112 110 protected SoundEvent getDeathSound() { 113 - return this.getCore().getBlock().getSoundGroup(this.getCore()).getBreakSound(); 111 + return this.getCore().getSoundGroup().getBreakSound(); 114 112 } 115 113 @Override 116 114 protected SoundEvent getSquishSound() { 117 - return this.getCore().getBlock().getSoundGroup(this.getCore()).getStepSound(); 115 + return this.getCore().getSoundGroup().getStepSound(); 118 116 } 119 117 @Override 120 118 protected SoundEvent getJumpSound() { 121 - return this.getCore().getBlock().getSoundGroup(this.getCore()).getFallSound(); 119 + return this.getCore().getSoundGroup().getFallSound(); 122 120 } 123 121 @Override 124 - public Identifier getLootTableId() { 125 - return this.getCore().getBlock().getLootTableId(); 122 + public RegistryKey<LootTable> getLootTableId() { 123 + return this.getCore().getBlock().getLootTableKey(); 126 124 } 127 125 128 126 @Override 129 127 public void writeCustomDataToNbt(NbtCompound nbt) { 130 128 super.writeCustomDataToNbt(nbt); 131 - nbt.putFloat("red", this.dataTracker.get(color).x); 132 - nbt.putFloat("green", this.dataTracker.get(color).y); 133 - nbt.putFloat("blue", this.dataTracker.get(color).z); 129 + nbt.putInt("color", this.dataTracker.get(color)); 134 130 nbt.putString("core", Registries.BLOCK.getId(this.getCore().getBlock()).toString()); 135 131 } 136 132 137 133 @Override 138 134 public void readCustomDataFromNbt(NbtCompound nbt) { 139 135 super.readCustomDataFromNbt(nbt); 140 - this.setColor(new Vector3f(nbt.getFloat("red"), nbt.getFloat("green"), nbt.getFloat("blue"))); 141 - Block b = Registries.BLOCK.get(new Identifier(nbt.getString("core"))); 136 + this.setColor(nbt.getInt("color")); 137 + Block b = Registries.BLOCK.get(Identifier.of(nbt.getString("core"))); 142 138 this.setCore(b.getDefaultState()); 143 139 } 144 140 145 141 public static boolean canSpawn(EntityType<DimensionalSlime> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, net.minecraft.util.math.random.Random random) { 146 - if (world.getDifficulty() != Difficulty.PEACEFUL && ((MinecraftServerAccess)world.toServerWorld().getServer()).getDimensionProvider().rule("chaosMobsEnabled")) { 142 + if (world.getDifficulty() != Difficulty.PEACEFUL && ((MinecraftServerAccess)world.toServerWorld().getServer()).projectInfinity$getDimensionProvider().rule("chaosMobsEnabled")) { 147 143 if (!(world instanceof StructureWorldAccess)) { 148 144 return false; 149 145 }
+12 -17
src/main/java/net/lerariemann/infinity/entity/custom/TintableEntity.java
··· 19 19 float h = (float)(i & 0xFF) / 255.0f; 20 20 return new Vector3f(f, g, h); 21 21 } 22 - default Vector3f getColorNamed() { 22 + default int getColorNamed() { 23 23 if (hasCustomName()) { 24 24 String s = getName().getString(); 25 25 if ("jeb_".equals(s)) { ··· 28 28 int p = n % o; 29 29 int q = (n + 1) % o; 30 30 float r = (getAge() % 25) / 25.0f; 31 - float[] fs = SheepEntity.getRgbColor(DyeColor.byId(p)); 32 - float[] gs = SheepEntity.getRgbColor(DyeColor.byId(q)); 33 - float f = fs[0] * (1.0f - r) + gs[0] * r; 34 - float g = fs[1] * (1.0f - r) + gs[1] * r; 35 - float h = fs[2] * (1.0f - r) + gs[2] * r; 36 - return new Vector3f(f, g, h); 31 + int fs = SheepEntity.getRgbColor(DyeColor.byId(p)); 32 + int gs = SheepEntity.getRgbColor(DyeColor.byId(q)); 33 + float f = fs * (1.0f - r) + gs * r; 34 + return (int)f; 37 35 } 38 36 if ("hue".equals(s)) { 39 37 int n = getAge() + getId(); 40 38 float hue = n / 400.f; 41 39 hue = hue - (int) hue; 42 - return colorFromInt(Color.getHSBColor(hue, 1.0f, 1.0f).getRGB()); 40 + return Color.getHSBColor(hue, 1.0f, 1.0f).getRGB(); 43 41 } 44 42 } 45 - return null; 43 + return -1; 46 44 } 47 - 48 - default Vector3f getColor() { 49 - Vector3f v = getColorNamed(); 50 - if (v!=null) return v; 51 - return colorFromInt(this.getColorRaw()); 45 + default int getColor() { 46 + int v = getColorNamed(); 47 + if (v!=-1) return v; 48 + return this.getColorRaw(); 52 49 } 50 + 53 51 default int getColorRaw() { 54 52 return 0; 55 - } 56 - default float getAlpha() { 57 - return 1.0f; 58 53 } 59 54 }
+2 -2
src/main/java/net/lerariemann/infinity/features/RandomDungeonFeature.java
··· 7 7 import net.minecraft.block.BlockState; 8 8 import net.minecraft.block.Blocks; 9 9 import net.minecraft.block.entity.BlockEntity; 10 - import net.minecraft.block.entity.LootableContainerBlockEntity; 11 10 import net.minecraft.block.entity.MobSpawnerBlockEntity; 12 11 import net.minecraft.entity.EntityType; 12 + import net.minecraft.inventory.LootableInventory; 13 13 import net.minecraft.loot.LootTables; 14 14 import net.minecraft.registry.tag.BlockTags; 15 15 import net.minecraft.structure.StructurePiece; ··· 100 100 } 101 101 if (x != 1) continue; 102 102 this.setBlockStateIf(structureWorldAccess, blockPos3, StructurePiece.orientateChest(structureWorldAccess, blockPos3, Blocks.CHEST.getDefaultState()), predicate); 103 - LootableContainerBlockEntity.setLootTable(structureWorldAccess, random, blockPos3, LootTables.SIMPLE_DUNGEON_CHEST); 103 + LootableInventory.setLootTable(structureWorldAccess, random, blockPos3, LootTables.SIMPLE_DUNGEON_CHEST); 104 104 continue block6; 105 105 } 106 106 }
+11 -7
src/main/java/net/lerariemann/infinity/loading/JsonGrabber.java
··· 5 5 import com.mojang.serialization.Codec; 6 6 import com.mojang.serialization.DataResult; 7 7 import com.mojang.serialization.JsonOps; 8 - import com.mojang.serialization.Lifecycle; 9 8 import net.lerariemann.infinity.InfinityMod; 10 9 import net.lerariemann.infinity.util.CommonIO; 11 10 import net.minecraft.nbt.NbtCompound; 12 11 import net.minecraft.registry.*; 12 + import net.minecraft.registry.entry.RegistryEntryInfo; 13 13 import net.minecraft.util.Identifier; 14 14 import org.apache.commons.io.FileUtils; 15 + import org.apache.logging.log4j.LogManager; 15 16 16 17 import java.io.File; 17 18 import java.io.IOException; ··· 61 62 void grab(RegistryKey<E> key, JsonElement jsonElement, boolean bl) { 62 63 RegistryOps<JsonElement> registryOps = RegistryOps.of(JsonOps.INSTANCE, registryInfoGetter); 63 64 DataResult<E> dataResult = decoder.parse(registryOps, jsonElement); 64 - E object = dataResult.getOrThrow(false, (error) -> { 65 - }); 66 - if (bl || !registry.contains(key)) registry.add(key, object, Lifecycle.stable()); 65 + if(dataResult.result().isPresent()) { 66 + E object = dataResult.result().get(); 67 + if (bl || !registry.contains(key)) registry.add(key, object, RegistryEntryInfo.DEFAULT); 68 + } 69 + else { 70 + LogManager.getLogger().info(jsonElement); 71 + } 67 72 } 68 73 69 74 void grab(String path, RegistryKey<E> registryKey, boolean bl) { ··· 91 96 JsonElement jsonElement = JsonParser.parseString(content); 92 97 RegistryOps<JsonElement> registryOps = RegistryOps.of(JsonOps.INSTANCE, registryInfoGetter); 93 98 DataResult<E> dataResult = decoder.parse(registryOps, jsonElement); 94 - E object = dataResult.getOrThrow(false, (error) -> { 95 - }); 96 - if (register) registry.add(key, object, Lifecycle.stable()); 99 + E object = dataResult.getOrThrow((error) -> null); 100 + if (register) registry.add(key, object, RegistryEntryInfo.DEFAULT); 97 101 return object; 98 102 } 99 103 }
-52
src/main/java/net/lerariemann/infinity/mixin/EntityMixin.java
··· 1 - package net.lerariemann.infinity.mixin; 2 - 3 - import net.lerariemann.infinity.access.Timebombable; 4 - import net.lerariemann.infinity.block.ModBlocks; 5 - import net.lerariemann.infinity.block.entity.NeitherPortalBlockEntity; 6 - import net.lerariemann.infinity.var.ModCommands; 7 - import net.minecraft.entity.Entity; 8 - import net.minecraft.registry.RegistryKey; 9 - import net.minecraft.server.world.ServerWorld; 10 - import net.minecraft.util.math.BlockPos; 11 - import net.minecraft.world.World; 12 - import org.spongepowered.asm.mixin.Mixin; 13 - import org.spongepowered.asm.mixin.Shadow; 14 - import org.spongepowered.asm.mixin.injection.*; 15 - 16 - @Mixin(Entity.class) 17 - public class EntityMixin { 18 - @Shadow 19 - protected BlockPos lastNetherPortalPosition; 20 - @Shadow 21 - private World world; 22 - 23 - @ModifyArg(method = "tickPortal()V", at = @At(value = "INVOKE", 24 - target = "Lnet/minecraft/server/MinecraftServer;getWorld(Lnet/minecraft/registry/RegistryKey;)Lnet/minecraft/server/world/ServerWorld;"), index = 0) 25 - private RegistryKey<World> injected(RegistryKey<World> key) { 26 - return this.world.getRegistryKey() == World.OVERWORLD ? World.NETHER : World.OVERWORLD; 27 - } 28 - 29 - @ModifyArg(method = "tickPortal()V", at = @At(value = "INVOKE", 30 - target = "Lnet/minecraft/entity/Entity;moveToWorld(Lnet/minecraft/server/world/ServerWorld;)Lnet/minecraft/entity/Entity;"), index = 0) 31 - private ServerWorld injected(ServerWorld serverWorld2) { 32 - ServerWorld serverWorld = (ServerWorld)this.world; 33 - if (serverWorld.getBlockState(this.lastNetherPortalPosition).isOf(ModBlocks.NEITHER_PORTAL)) { 34 - NeitherPortalBlockEntity e = ((NeitherPortalBlockEntity)serverWorld.getBlockEntity(this.lastNetherPortalPosition)); 35 - if (e == null) return serverWorld; 36 - long d = e.getDimension(); 37 - serverWorld2 = serverWorld.getServer().getWorld(ModCommands.getKey(d, serverWorld.getServer())); 38 - return (serverWorld2 != null && e.getOpen() && ((Timebombable)serverWorld2).isTimebobmed() == 0) ? serverWorld2 : serverWorld; 39 - } 40 - return (serverWorld2 != null) ? serverWorld2 : serverWorld; 41 - } 42 - 43 - @Redirect(method = "getTeleportTarget(Lnet/minecraft/server/world/ServerWorld;)Lnet/minecraft/world/TeleportTarget;", 44 - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getRegistryKey()Lnet/minecraft/registry/RegistryKey;"), 45 - slice = @Slice(from = @At( 46 - value = "INVOKE", target = "Lnet/minecraft/util/math/BlockPos;getZ()Lnet/minecraft/util/math/Vec3i;" 47 - ), to = @At("TAIL"))) 48 - RegistryKey<World> smuggle(World w) { 49 - if (w == this.world) return World.NETHER; 50 - return w.getRegistryKey(); 51 - } 52 - }
+20 -11
src/main/java/net/lerariemann/infinity/mixin/MinecraftServerMixin.java
··· 5 5 import net.lerariemann.infinity.InfinityMod; 6 6 import net.lerariemann.infinity.dimensions.RandomProvider; 7 7 import net.lerariemann.infinity.access.MinecraftServerAccess; 8 + import net.minecraft.network.QueryableServer; 8 9 import net.minecraft.registry.DynamicRegistryManager; 9 10 import net.minecraft.registry.RegistryKey; 10 11 import net.minecraft.server.MinecraftServer; 11 12 import net.minecraft.server.ServerTask; 12 13 import net.minecraft.server.WorldGenerationProgressListener; 13 14 import net.minecraft.server.WorldGenerationProgressListenerFactory; 15 + import net.minecraft.server.command.CommandOutput; 16 + import net.minecraft.server.world.ChunkErrorHandler; 14 17 import net.minecraft.server.world.ServerWorld; 15 18 import net.minecraft.util.WorldSavePath; 16 19 import net.minecraft.util.math.random.RandomSequencesState; 20 + import net.minecraft.util.thread.ReentrantThreadExecutor; 17 21 import net.minecraft.world.SaveProperties; 18 22 import net.minecraft.world.World; 19 23 import net.minecraft.world.biome.source.BiomeAccess; ··· 21 25 import net.minecraft.world.dimension.DimensionOptions; 22 26 import net.minecraft.world.level.ServerWorldProperties; 23 27 import net.minecraft.world.level.storage.LevelStorage; 24 - import net.minecraft.world.spawner.Spawner; 28 + import net.minecraft.world.spawner.SpecialSpawner; 25 29 import org.spongepowered.asm.mixin.Final; 26 30 import org.spongepowered.asm.mixin.Mixin; 27 31 import org.spongepowered.asm.mixin.Shadow; ··· 38 42 import java.util.concurrent.Executor; 39 43 40 44 @Mixin(MinecraftServer.class) 41 - public abstract class MinecraftServerMixin implements MinecraftServerAccess { 45 + public abstract class MinecraftServerMixin extends ReentrantThreadExecutor<ServerTask> implements QueryableServer, ChunkErrorHandler, CommandOutput, AutoCloseable, MinecraftServerAccess { 42 46 @Final @Shadow 43 47 private Map<RegistryKey<World>, ServerWorld> worlds; 44 48 @Final @Shadow ··· 49 53 protected SaveProperties saveProperties; 50 54 @Final @Shadow 51 55 private WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory; 56 + 57 + public MinecraftServerMixin(String string) { 58 + super(string); 59 + } 60 + 52 61 @Shadow 53 62 public ServerWorld getWorld(RegistryKey<World> key) { 54 63 return null; ··· 75 84 private void injected(CallbackInfo info) { 76 85 worldsToAdd = new HashMap<>(); 77 86 needsInvocation = true; 78 - setDimensionProvider(); 87 + projectInfinity$setDimensionProvider(); 79 88 } 80 89 @Override 81 - public boolean needsInvocation() {return needsInvocation;} 90 + public boolean projectInfinity$needsInvocation() {return needsInvocation;} 82 91 @Override 83 - public void onInvocation() {needsInvocation = false;} 92 + public void projectInfinity$onInvocation() {needsInvocation = false;} 84 93 @Override 85 - public RandomProvider getDimensionProvider() { 94 + public RandomProvider projectInfinity$getDimensionProvider() { 86 95 return dimensionProvider; 87 96 } 88 97 89 98 @Override 90 - public void setDimensionProvider() { 99 + public void projectInfinity$setDimensionProvider() { 91 100 RandomProvider p = new RandomProvider("config/" + InfinityMod.MOD_ID + "/", 92 101 getSavePath(WorldSavePath.DATAPACKS).toString() + "/" + InfinityMod.MOD_ID); 93 102 p.kickGhostsOut(getRegistryManager()); ··· 95 104 } 96 105 97 106 @Override 98 - public void addWorld(RegistryKey<World> key, DimensionOptions options) { 107 + public void projectInfinity$addWorld(RegistryKey<World> key, DimensionOptions options) { 99 108 ServerWorldProperties serverWorldProperties = saveProperties.getMainWorldProperties(); 100 109 ServerWorld world = new ServerWorld(((MinecraftServer) (Object) this), workerExecutor, session, serverWorldProperties, 101 110 key, options, worldGenerationProgressListenerFactory.create(11), saveProperties.isDebugWorld(), 102 111 BiomeAccess.hashSeed(saveProperties.getGeneratorOptions().getSeed()), ImmutableList.of(), false, getWorld(World.OVERWORLD).getRandomSequences()); 103 112 getWorld(World.OVERWORLD).getWorldBorder().addListener(new WorldBorderListener.WorldBorderSyncer(world.getWorldBorder())); 104 113 worldsToAdd.put(key, world); 105 - ((MinecraftServer) (Object) this).send(createTask(() -> { 114 + send(createTask(() -> { 106 115 worlds.put(key, world); 107 116 worldsToAdd.clear(); 108 117 })); ··· 110 119 } 111 120 112 121 @Override 113 - public boolean hasToAdd(RegistryKey<World> key) { 122 + public boolean projectInfinity$hasToAdd(RegistryKey<World> key) { 114 123 return (worldsToAdd.containsKey(key)); 115 124 } 116 125 117 126 @Redirect(method="createWorlds", at=@At(value="NEW", target="(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/level/storage/LevelStorage$Session;Lnet/minecraft/world/level/ServerWorldProperties;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/world/dimension/DimensionOptions;Lnet/minecraft/server/WorldGenerationProgressListener;ZJLjava/util/List;ZLnet/minecraft/util/math/random/RandomSequencesState;)Lnet/minecraft/server/world/ServerWorld;")) 118 - public ServerWorld create(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, RandomSequencesState randomSequencesState) { 127 + public ServerWorld create(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<SpecialSpawner> spawners, boolean shouldTickTime, RandomSequencesState randomSequencesState) { 119 128 ServerWorldProperties prop = (worldKey.getValue().toString().contains("infinity")) ? saveProperties.getMainWorldProperties() : properties; 120 129 return new ServerWorld(server, workerExecutor, session, prop, worldKey, dimensionOptions, worldGenerationProgressListener, debugWorld, seed, spawners, shouldTickTime, randomSequencesState); 121 130 }
+1 -1
src/main/java/net/lerariemann/infinity/mixin/MobEntityMixin.java
··· 10 10 @Shadow 11 11 private boolean persistent; 12 12 13 - public void setPersistent(boolean bl) { 13 + public void projectInfinity$setPersistent(boolean bl) { 14 14 this.persistent = bl; 15 15 } 16 16 }
+58 -13
src/main/java/net/lerariemann/infinity/mixin/NetherPortalBlockMixin.java
··· 1 1 package net.lerariemann.infinity.mixin; 2 2 3 + import com.llamalad7.mixinextras.injector.ModifyExpressionValue; 4 + import com.llamalad7.mixinextras.sugar.Local; 5 + import com.llamalad7.mixinextras.sugar.ref.LocalRef; 6 + import net.lerariemann.infinity.InfinityMod; 3 7 import net.lerariemann.infinity.access.MinecraftServerAccess; 8 + import net.lerariemann.infinity.access.Timebombable; 9 + import net.lerariemann.infinity.block.ModBlocks; 4 10 import net.lerariemann.infinity.block.custom.NeitherPortalBlock; 11 + import net.lerariemann.infinity.block.entity.NeitherPortalBlockEntity; 5 12 import net.lerariemann.infinity.dimensions.RandomProvider; 6 13 import net.lerariemann.infinity.var.ModCommands; 7 14 import net.lerariemann.infinity.var.ModCriteria; ··· 9 16 import net.minecraft.block.Block; 10 17 import net.minecraft.block.BlockState; 11 18 import net.minecraft.block.NetherPortalBlock; 19 + import net.minecraft.component.DataComponentTypes; 20 + import net.minecraft.component.type.WritableBookContentComponent; 21 + import net.minecraft.component.type.WrittenBookContentComponent; 12 22 import net.minecraft.entity.Entity; 13 23 import net.minecraft.entity.ItemEntity; 14 24 import net.minecraft.entity.player.PlayerEntity; 15 25 import net.minecraft.item.ItemStack; 16 - import net.minecraft.item.Items; 17 - import net.minecraft.nbt.NbtCompound; 18 26 import net.minecraft.registry.RegistryKey; 19 27 import net.minecraft.registry.RegistryKeys; 20 28 import net.minecraft.server.MinecraftServer; 21 29 import net.minecraft.server.network.ServerPlayerEntity; 22 - import net.minecraft.util.Identifier; 30 + import net.minecraft.server.world.ServerWorld; 23 31 import net.minecraft.util.math.BlockPos; 24 32 import net.minecraft.world.World; 33 + import org.jetbrains.annotations.Nullable; 25 34 import org.spongepowered.asm.mixin.Mixin; 26 35 import org.spongepowered.asm.mixin.injection.At; 27 36 import org.spongepowered.asm.mixin.injection.Inject; 28 37 import org.spongepowered.asm.mixin.injection.Redirect; 29 38 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 30 39 40 + import java.util.Objects; 41 + 31 42 @Mixin(NetherPortalBlock.class) 32 43 public class NetherPortalBlockMixin { 33 - 34 44 @Inject(at = @At("HEAD"), method = "onEntityCollision(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;)V") 35 45 private void injected(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo info) { 36 46 if (!world.isClient() && entity instanceof ItemEntity) { 37 47 ItemStack itemStack = ((ItemEntity)entity).getStack(); 38 - if (itemStack.getItem() == Items.WRITTEN_BOOK || itemStack.getItem() == Items.WRITABLE_BOOK) { 39 - NbtCompound compound = itemStack.getNbt(); 48 + WritableBookContentComponent comp1 = itemStack.getComponents().get(DataComponentTypes.WRITABLE_BOOK_CONTENT); 49 + WrittenBookContentComponent comp2 = itemStack.getComponents().get(DataComponentTypes.WRITTEN_BOOK_CONTENT); 50 + if (comp1 != null || comp2 != null) { 51 + String content = ""; 52 + if (comp1 != null) { 53 + content = comp1.pages().getFirst().raw(); 54 + } 55 + if (comp2 != null) { 56 + content = comp2.pages().getFirst().raw().getString(); 57 + } 58 + if (Objects.equals(content, "")) { 59 + content = "empty"; 60 + } 40 61 MinecraftServer server = world.getServer(); 41 - if (compound != null && server != null) { 42 - long i = ModCommands.getDimensionSeed(compound, server, itemStack.getItem()); 43 - boolean b = server.getWorld(RegistryKey.of(RegistryKeys.WORLD, new Identifier("infinity:generated_" + i))) != null; 62 + if (server != null) { 63 + long i = ModCommands.getDimensionSeed(content, server); 64 + boolean b = server.getWorld(RegistryKey.of(RegistryKeys.WORLD, InfinityMod.getId("generated_" + i))) != null; 44 65 NeitherPortalBlock.modifyPortal(world, pos, state, i, b); 45 - MinecraftServer s = world.getServer(); 46 - RandomProvider prov = ((MinecraftServerAccess)(s)).getDimensionProvider(); 66 + RandomProvider prov = ((MinecraftServerAccess)(server)).projectInfinity$getDimensionProvider(); 47 67 boolean bl = prov.portalKey.isBlank(); 48 68 if (bl) { 49 - NeitherPortalBlock.open(s, world, pos, false); 69 + NeitherPortalBlock.open(server, world, pos, false); 50 70 PlayerEntity player = world.getClosestPlayer(pos.getX(), pos.getY(), pos.getZ(), 5, false); 51 71 if (player != null) { 52 72 player.increaseStat(ModStats.DIMS_OPENED_STAT, 1); ··· 60 80 } 61 81 } 62 82 63 - @Redirect(method="getStateForNeighborUpdate(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;Lnet/minecraft/block/BlockState;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z")) 83 + @ModifyExpressionValue(method = "createTeleportTarget", at = @At(value = "INVOKE", 84 + target = "Lnet/minecraft/server/MinecraftServer;getWorld(Lnet/minecraft/registry/RegistryKey;)Lnet/minecraft/server/world/ServerWorld;")) 85 + private @Nullable ServerWorld injected(@Nullable ServerWorld original, 86 + @Local(argsOnly = true) ServerWorld world, @Local(argsOnly = true) BlockPos pos) { 87 + if (!world.getBlockState(pos).isOf(ModBlocks.NEITHER_PORTAL)) { 88 + if (!world.getRegistryKey().getValue().getNamespace().contains("infinity")) { 89 + return original; //when teleportation should not be redirected 90 + } 91 + return world.getServer().getWorld(World.OVERWORLD); //when we return from another dimension 92 + } 93 + 94 + NeitherPortalBlockEntity e = ((NeitherPortalBlockEntity)world.getBlockEntity(pos)); 95 + if (e==null) return world; 96 + long d = e.getDimension(); 97 + 98 + RegistryKey<World> key2 = ModCommands.getKey(d, world.getServer()); 99 + ServerWorld serverWorld2 = world.getServer().getWorld(key2); 100 + 101 + if (serverWorld2 != null && e.getOpen() && ((Timebombable)serverWorld2).projectInfinity$isTimebobmed() == 0) { 102 + return serverWorld2; 103 + } 104 + return world; 105 + } 106 + 107 + @Redirect(method="getStateForNeighborUpdate(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;Lnet/minecraft/block/BlockState;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;", 108 + at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z")) 64 109 private boolean injected(BlockState neighborState, Block block) { 65 110 return (neighborState.getBlock() instanceof NetherPortalBlock); 66 111 }
-21
src/main/java/net/lerariemann/infinity/mixin/PlayerEntityMixin.java
··· 1 - package net.lerariemann.infinity.mixin; 2 - 3 - import net.lerariemann.infinity.access.Timebombable; 4 - import net.minecraft.entity.player.PlayerEntity; 5 - import net.minecraft.server.world.ServerWorld; 6 - import net.minecraft.util.math.BlockPos; 7 - import net.minecraft.util.math.Vec3d; 8 - import org.spongepowered.asm.mixin.Mixin; 9 - import org.spongepowered.asm.mixin.injection.At; 10 - import org.spongepowered.asm.mixin.injection.Inject; 11 - import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 12 - 13 - import java.util.Optional; 14 - 15 - @Mixin(PlayerEntity.class) 16 - public class PlayerEntityMixin { 17 - @Inject(method="findRespawnPosition", at = @At("HEAD"), cancellable = true) 18 - private static void injected(ServerWorld world, BlockPos pos, float angle, boolean forced, boolean alive, CallbackInfoReturnable<Optional<Vec3d>> cir) { 19 - if (((Timebombable)world).isTimebobmed() > 0) cir.setReturnValue(Optional.empty()); 20 - } 21 - }
-5
src/main/java/net/lerariemann/infinity/mixin/PointOfInterestTypesMixin.java
··· 2 2 3 3 import com.google.common.collect.ImmutableSet; 4 4 import net.lerariemann.infinity.block.ModBlocks; 5 - import net.minecraft.block.Block; 6 5 import net.minecraft.block.BlockState; 7 6 import net.minecraft.block.Blocks; 8 7 import net.minecraft.registry.Registry; ··· 16 15 17 16 import java.util.HashSet; 18 17 import java.util.Set; 19 - import java.util.stream.Stream; 20 18 21 19 @Mixin(PointOfInterestTypes.class) 22 20 public class PointOfInterestTypesMixin { 23 - private static Set<BlockState> getAllStatesOf(Block... blocks) { 24 - return (Set<BlockState>) Stream.<Block>of(blocks).flatMap(block -> block.getStateManager().getStates().stream()).collect(ImmutableSet.toImmutableSet()); 25 - } 26 21 27 22 @Shadow private static PointOfInterestType register(Registry<PointOfInterestType> registry, RegistryKey<PointOfInterestType> key, Set<BlockState> states, int ticketCount, int searchDistance) { 28 23 return null;
+5 -8
src/main/java/net/lerariemann/infinity/mixin/PortalForcerMixin.java
··· 2 2 3 3 import net.lerariemann.infinity.var.ModPoi; 4 4 import net.minecraft.registry.entry.RegistryEntry; 5 - import net.minecraft.world.PortalForcer; 5 + import net.minecraft.world.dimension.PortalForcer; 6 6 import net.minecraft.world.poi.PointOfInterestType; 7 7 import org.spongepowered.asm.mixin.Mixin; 8 8 import org.spongepowered.asm.mixin.injection.At; ··· 12 12 13 13 @Mixin(PortalForcer.class) 14 14 public class PortalForcerMixin { 15 - @ModifyArg(method = "getPortalRect(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/world/border/WorldBorder;)Ljava/util/Optional;", 16 - at = @At(value = "INVOKE", 17 - target = "Lnet/minecraft/world/poi/PointOfInterestStorage;getInSquare(Ljava/util/function/Predicate;Lnet/minecraft/util/math/BlockPos;ILnet/minecraft/world/poi/PointOfInterestStorage$OccupationStatus;)Ljava/util/stream/Stream;"), 18 - index = 0) 19 - Predicate<RegistryEntry<PointOfInterestType>> injected(Predicate<RegistryEntry<PointOfInterestType>> typePredicate) 20 - { 21 - return typePredicate.or(poiType -> (poiType.matchesKey(ModPoi.NEITHER_PORTAL_KEY))); 15 + @ModifyArg(method = "getPortalPos", at = @At(value = "INVOKE", 16 + target = "Lnet/minecraft/world/poi/PointOfInterestStorage;getInSquare(Ljava/util/function/Predicate;Lnet/minecraft/util/math/BlockPos;ILnet/minecraft/world/poi/PointOfInterestStorage$OccupationStatus;)Ljava/util/stream/Stream;")) 17 + Predicate<RegistryEntry<PointOfInterestType>> injected(Predicate<RegistryEntry<PointOfInterestType>> typePredicate) { 18 + return typePredicate.or(poiType -> poiType.matchesKey(ModPoi.NEITHER_PORTAL_KEY)); 22 19 } 23 20 }
+30 -28
src/main/java/net/lerariemann/infinity/mixin/ServerPlayerEntityMixin.java
··· 1 1 package net.lerariemann.infinity.mixin; 2 2 3 + import com.llamalad7.mixinextras.sugar.Local; 3 4 import com.mojang.authlib.GameProfile; 4 - import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; 5 5 import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; 6 6 import net.lerariemann.infinity.InfinityMod; 7 7 import net.lerariemann.infinity.access.Timebombable; 8 8 import net.lerariemann.infinity.block.custom.NeitherPortalBlock; 9 9 import net.lerariemann.infinity.access.MinecraftServerAccess; 10 10 import net.lerariemann.infinity.access.ServerPlayerEntityAccess; 11 - import net.lerariemann.infinity.options.PacketTransiever; 12 11 import net.lerariemann.infinity.var.ModCommands; 13 12 import net.lerariemann.infinity.var.ModCriteria; 13 + import net.lerariemann.infinity.var.ModPayloads; 14 14 import net.lerariemann.infinity.var.ModStats; 15 15 import net.minecraft.block.Blocks; 16 16 import net.minecraft.entity.Entity; ··· 24 24 import net.minecraft.registry.RegistryKeys; 25 25 import net.minecraft.registry.entry.RegistryEntry; 26 26 import net.minecraft.server.MinecraftServer; 27 - import net.minecraft.server.PlayerManager; 28 27 import net.minecraft.server.network.ServerPlayNetworkHandler; 29 28 import net.minecraft.server.network.ServerPlayerEntity; 30 29 import net.minecraft.server.world.ServerWorld; 31 30 import net.minecraft.util.math.BlockPos; 31 + import net.minecraft.util.math.Vec3d; 32 32 import net.minecraft.world.GameMode; 33 33 import net.minecraft.world.TeleportTarget; 34 34 import net.minecraft.world.World; 35 - import net.minecraft.world.WorldProperties; 36 35 import net.minecraft.world.dimension.DimensionType; 36 + import org.jetbrains.annotations.Nullable; 37 37 import org.spongepowered.asm.mixin.Mixin; 38 38 import org.spongepowered.asm.mixin.Shadow; 39 39 import org.spongepowered.asm.mixin.Unique; ··· 41 41 import org.spongepowered.asm.mixin.injection.Inject; 42 42 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 43 43 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 44 - import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 45 44 46 45 import java.util.HashSet; 46 + import java.util.Optional; 47 47 import java.util.Set; 48 48 49 49 @Mixin(ServerPlayerEntity.class) ··· 61 61 @Shadow public abstract boolean damage(DamageSource source, float amount); 62 62 @Shadow public boolean notInAnyWorld; 63 63 @Shadow public ServerPlayNetworkHandler networkHandler; 64 + 65 + @Shadow public abstract @Nullable Entity teleportTo(TeleportTarget teleportTarget); 66 + 64 67 @Unique private long ticksUntilWarp; 65 68 @Unique private long idForWarp; 66 69 67 70 68 - @Inject(method = "moveToWorld(Lnet/minecraft/server/world/ServerWorld;)Lnet/minecraft/entity/Entity;", 69 - at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;setServerWorld(Lnet/minecraft/server/world/ServerWorld;)V"), 70 - locals = LocalCapture.CAPTURE_FAILHARD) 71 - private void injected2(ServerWorld destination, CallbackInfoReturnable<Entity> ci, ServerWorld serverWorld, RegistryKey<World> registryKey, 72 - WorldProperties worldProperties, PlayerManager playerManager, TeleportTarget teleportTarget) { 73 - if (((MinecraftServerAccess)(serverWorld.getServer())).getDimensionProvider().rule("returnPortalsEnabled") && 71 + @Inject(method="findRespawnPosition", at = @At("HEAD"), cancellable = true) 72 + private static void injected(ServerWorld world, BlockPos pos, float angle, boolean forced, boolean alive, CallbackInfoReturnable<Optional<Vec3d>> cir) { 73 + if (((Timebombable)world).projectInfinity$isTimebobmed() > 0) cir.setReturnValue(Optional.empty()); 74 + } 75 + 76 + @Inject(method = "teleportTo", 77 + at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;setServerWorld(Lnet/minecraft/server/world/ServerWorld;)V") 78 + ) 79 + private void injected2(TeleportTarget teleportTarget, CallbackInfoReturnable<Entity> cir, @Local(ordinal = 0) ServerWorld serverWorld, @Local RegistryKey<World> registryKey) { 80 + if (((MinecraftServerAccess)(serverWorld.getServer())).projectInfinity$getDimensionProvider().rule("returnPortalsEnabled") && 74 81 (registryKey.getValue().getNamespace().equals(InfinityMod.MOD_ID))) { 75 - BlockPos pos = BlockPos.ofFloored(teleportTarget.position); 82 + BlockPos pos = BlockPos.ofFloored(teleportTarget.pos()); 83 + ServerWorld destination = teleportTarget.world(); 76 84 boolean bl = false; 77 85 for (BlockPos pos2: new BlockPos[] {pos, pos.add(1, 0, 0), pos.add(0, 0, 1), 78 86 pos.add(-1, 0, 0), pos.add(0, 0, -1)}) if (destination.getBlockState(pos2).isOf(Blocks.NETHER_PORTAL)) { ··· 94 102 } 95 103 } 96 104 97 - @Inject(method = "moveToWorld(Lnet/minecraft/server/world/ServerWorld;)Lnet/minecraft/entity/Entity;", 105 + @Inject(method = "teleportTo", 98 106 at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getPlayerManager()Lnet/minecraft/server/PlayerManager;")) 99 - private void injected3(ServerWorld destination, CallbackInfoReturnable<Entity> cir) { 100 - ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), InfinityMod.SHADER_RELOAD, 101 - PacketTransiever.buildPacket(destination)); 102 - ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), InfinityMod.STARS_RELOAD, PacketByteBufs.create()); 107 + private void injected3(TeleportTarget teleportTarget, CallbackInfoReturnable<Entity> cir) { 108 + ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), ModPayloads.setShaderFromWorld(teleportTarget.world())); 109 + ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), ModPayloads.StarsRePayLoad.INSTANCE); 103 110 } 104 111 105 112 @Inject(method = "tick", at = @At("TAIL")) ··· 113 120 BlockPos blockPos2 = w.getWorldBorder().clamp(self.getX() * d, self.getY(), self.getZ() * d); 114 121 this.teleport(w, blockPos2.getX(), blockPos2.getY(), blockPos2.getZ(), new HashSet<>(), self.getYaw(), self.getPitch()); 115 122 } 116 - int i = ((Timebombable)(getServerWorld())).isTimebobmed(); 123 + int i = ((Timebombable)(getServerWorld())).projectInfinity$isTimebobmed(); 117 124 if (i > 200) { 118 125 if (i%4 == 0) { 119 126 Registry<DamageType> r = getServerWorld().getServer().getRegistryManager().get(RegistryKeys.DAMAGE_TYPE); 120 127 RegistryEntry<DamageType> entry = r.getEntry(r.get(InfinityMod.getId("world_ceased"))); 121 128 damage(new DamageSource(entry), i > 400 ? 2.0f : 1.0f); 122 129 } 123 - if (i > 3500) ModCriteria.HE_WHO_REMAINS.trigger((ServerPlayerEntity)(Object)this); 130 + if (i > 3500) { 131 + ModCriteria.WHO_REMAINS.trigger((ServerPlayerEntity)(Object)this); 132 + } 124 133 if (i > 3540) { 125 134 this.detach(); 126 135 this.getServerWorld().removePlayer((ServerPlayerEntity)(Object)this, Entity.RemovalReason.CHANGED_DIMENSION); ··· 134 143 135 144 @Inject(method = "changeGameMode", at = @At("RETURN")) 136 145 private void injected4(GameMode gameMode, CallbackInfoReturnable<Boolean> cir) { 137 - if (cir.getReturnValue()) ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), InfinityMod.SHADER_RELOAD, PacketTransiever.buildPacket(this.getServerWorld())); 146 + if (cir.getReturnValue()) ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), ModPayloads.setShaderFromWorld(this.getServerWorld())); 138 147 } 139 148 140 - @Inject(method= "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At(value="INVOKE", target ="Lnet/minecraft/server/PlayerManager;sendCommandTree(Lnet/minecraft/server/network/ServerPlayerEntity;)V")) 141 - private void injected5(ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { 142 - ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), InfinityMod.SHADER_RELOAD, PacketTransiever.buildPacket(targetWorld)); 143 - ServerPlayNetworking.send(((ServerPlayerEntity)(Object)this), InfinityMod.STARS_RELOAD, PacketByteBufs.create()); 144 - } 145 - 146 - 147 149 @Override 148 - public void setWarpTimer(long ticks, long dim) { 150 + public void projectInfinity$setWarpTimer(long ticks, long dim) { 149 151 this.ticksUntilWarp = ticks; 150 152 this.idForWarp = dim; 151 153 }
+6 -9
src/main/java/net/lerariemann/infinity/mixin/SlimeEntityMixin.java
··· 1 1 package net.lerariemann.infinity.mixin; 2 2 3 - import com.llamalad7.mixinextras.sugar.Local; 4 3 import net.lerariemann.infinity.entity.custom.DimensionalSlime; 5 - import net.minecraft.entity.Entity; 6 4 import net.minecraft.entity.mob.SlimeEntity; 7 5 import org.spongepowered.asm.mixin.Mixin; 8 6 import org.spongepowered.asm.mixin.injection.At; 9 - import org.spongepowered.asm.mixin.injection.Inject; 10 - import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 7 + import org.spongepowered.asm.mixin.injection.Redirect; 11 8 12 9 import static net.lerariemann.infinity.entity.custom.DimensionalSlime.color; 13 10 14 11 @Mixin(SlimeEntity.class) 15 12 public class SlimeEntityMixin { 16 - @Inject(method = "remove(Lnet/minecraft/entity/Entity$RemovalReason;)V", at = @At(value = "INVOKE", 13 + @Redirect(method = "remove(Lnet/minecraft/entity/Entity$RemovalReason;)V", at = @At(value = "INVOKE", 17 14 target = "Lnet/minecraft/entity/mob/SlimeEntity;setAiDisabled(Z)V")) 18 - private void injected(Entity.RemovalReason reason, CallbackInfo ci, @Local SlimeEntity slimeEntity) { 15 + private void injected(SlimeEntity instance, boolean b) { 16 + instance.setAiDisabled(b); 19 17 SlimeEntity e = ((SlimeEntity)(Object)(this)); 20 - if (((SlimeEntity)(Object)(this)) instanceof DimensionalSlime) { 21 - DimensionalSlime slime_mom = (DimensionalSlime)e; 22 - DimensionalSlime slime_son = (DimensionalSlime)slimeEntity; 18 + if (e instanceof DimensionalSlime slime_mom) { 19 + DimensionalSlime slime_son = (DimensionalSlime)instance; 23 20 slime_son.setCore(slime_mom.getCore()); 24 21 slime_son.setColor(slime_mom.getDataTracker().get(color)); 25 22 }
-22
src/main/java/net/lerariemann/infinity/mixin/mavity/BoatEntityMixin.java
··· 1 - package net.lerariemann.infinity.mixin.mavity; 2 - 3 - import net.lerariemann.infinity.access.MavityInterface; 4 - import net.minecraft.entity.Entity; 5 - import net.minecraft.entity.EntityType; 6 - import net.minecraft.entity.vehicle.BoatEntity; 7 - import net.minecraft.world.World; 8 - import org.spongepowered.asm.mixin.Mixin; 9 - import org.spongepowered.asm.mixin.injection.At; 10 - import org.spongepowered.asm.mixin.injection.ModifyVariable; 11 - 12 - @Mixin(BoatEntity.class) 13 - public abstract class BoatEntityMixin extends Entity implements MavityInterface { 14 - public BoatEntityMixin(EntityType<?> type, World world) { 15 - super(type, world); 16 - } 17 - 18 - @ModifyVariable(method="updateVelocity", at=@At("STORE"), ordinal=1) 19 - double inj(double constant) { 20 - return constant * (this.hasNoGravity() ? 0.0 : getMavity()); 21 - } 22 - }
-35
src/main/java/net/lerariemann/infinity/mixin/mavity/LivingEntityMixin.java
··· 1 - package net.lerariemann.infinity.mixin.mavity; 2 - 3 - import net.lerariemann.infinity.access.MavityInterface; 4 - import net.minecraft.entity.Attackable; 5 - import net.minecraft.entity.Entity; 6 - import net.minecraft.entity.EntityType; 7 - import net.minecraft.entity.LivingEntity; 8 - import net.minecraft.world.World; 9 - import org.spongepowered.asm.mixin.Mixin; 10 - import org.spongepowered.asm.mixin.injection.At; 11 - import org.spongepowered.asm.mixin.injection.Constant; 12 - import org.spongepowered.asm.mixin.injection.ModifyArg; 13 - import org.spongepowered.asm.mixin.injection.ModifyConstant; 14 - 15 - @Mixin(LivingEntity.class) 16 - public abstract class LivingEntityMixin extends Entity implements Attackable, MavityInterface { 17 - public LivingEntityMixin(EntityType<?> type, World world) { 18 - super(type, world); 19 - } 20 - 21 - @ModifyArg(method = "computeFallDamage", at = @At(value="INVOKE", target="Lnet/minecraft/util/math/MathHelper;ceil(F)I")) 22 - float injected(float value) { 23 - return (float)getMavity() * value; 24 - } 25 - 26 - @ModifyConstant(method = "travel", constant = @Constant(doubleValue = 0.08)) 27 - double inj2(double value) { 28 - return value*getMavity(); 29 - } 30 - 31 - @ModifyConstant(method = "travel", constant = @Constant(doubleValue = 0.01)) 32 - double inj3(double value) { 33 - return value*getMavity(); 34 - } 35 - }
-22
src/main/java/net/lerariemann/infinity/mixin/mavity/PersistentProjectileEntityMixin.java
··· 1 - package net.lerariemann.infinity.mixin.mavity; 2 - 3 - import net.lerariemann.infinity.access.MavityInterface; 4 - import net.minecraft.entity.EntityType; 5 - import net.minecraft.entity.projectile.PersistentProjectileEntity; 6 - import net.minecraft.entity.projectile.ProjectileEntity; 7 - import net.minecraft.world.World; 8 - import org.spongepowered.asm.mixin.Mixin; 9 - import org.spongepowered.asm.mixin.injection.At; 10 - import org.spongepowered.asm.mixin.injection.ModifyArg; 11 - 12 - @Mixin(PersistentProjectileEntity.class) 13 - public abstract class PersistentProjectileEntityMixin extends ProjectileEntity implements MavityInterface { 14 - public PersistentProjectileEntityMixin(EntityType<? extends ProjectileEntity> entityType, World world) { 15 - super(entityType, world); 16 - } 17 - 18 - @ModifyArg(method = "tick", at = @At(value="INVOKE", target="Lnet/minecraft/entity/projectile/PersistentProjectileEntity;setVelocity(DDD)V"), index = 1) 19 - double injected(double x) { 20 - return x - 0.05 * (getMavity() - 1); 21 - } 22 - }
-22
src/main/java/net/lerariemann/infinity/mixin/mavity/SeveralEntitiesMixin.java
··· 1 - package net.lerariemann.infinity.mixin.mavity; 2 - 3 - import net.lerariemann.infinity.access.MavityInterface; 4 - import net.minecraft.entity.*; 5 - import net.minecraft.entity.projectile.LlamaSpitEntity; 6 - import net.minecraft.entity.vehicle.AbstractMinecartEntity; 7 - import net.minecraft.world.World; 8 - import org.spongepowered.asm.mixin.Mixin; 9 - import org.spongepowered.asm.mixin.injection.At; 10 - import org.spongepowered.asm.mixin.injection.ModifyArg; 11 - 12 - @Mixin({FallingBlockEntity.class, TntEntity.class, ItemEntity.class, ExperienceOrbEntity.class, AbstractMinecartEntity.class, LlamaSpitEntity.class}) 13 - public abstract class SeveralEntitiesMixin extends Entity implements MavityInterface { 14 - public SeveralEntitiesMixin(EntityType<?> type, World world) { 15 - super(type, world); 16 - } 17 - 18 - @ModifyArg(method = "tick", at = @At(value="INVOKE", target="Lnet/minecraft/util/math/Vec3d;add(DDD)Lnet/minecraft/util/math/Vec3d;"), index = 1) 19 - double injected(double x) { 20 - return getMavity() * x; 21 - } 22 - }
-25
src/main/java/net/lerariemann/infinity/mixin/mavity/ThrownEntityMixin.java
··· 1 - package net.lerariemann.infinity.mixin.mavity; 2 - 3 - import net.lerariemann.infinity.access.MavityInterface; 4 - import net.minecraft.entity.EntityType; 5 - import net.minecraft.entity.projectile.ProjectileEntity; 6 - import net.minecraft.entity.projectile.thrown.ThrownEntity; 7 - import net.minecraft.world.World; 8 - import org.spongepowered.asm.mixin.Mixin; 9 - import org.spongepowered.asm.mixin.Shadow; 10 - import org.spongepowered.asm.mixin.injection.At; 11 - import org.spongepowered.asm.mixin.injection.Redirect; 12 - 13 - @Mixin(ThrownEntity.class) 14 - public abstract class ThrownEntityMixin extends ProjectileEntity implements MavityInterface { 15 - @Shadow protected abstract float getGravity(); 16 - 17 - public ThrownEntityMixin(EntityType<? extends ProjectileEntity> entityType, World world) { 18 - super(entityType, world); 19 - } 20 - 21 - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/thrown/ThrownEntity;getGravity()F")) 22 - protected float getGravity(ThrownEntity instance) { 23 - return (float)getMavity() * getGravity(); 24 - } 25 - }
+1 -2
src/main/java/net/lerariemann/infinity/mixin/mobs/passive/SheepEntityMixin.java
··· 3 3 import net.minecraft.entity.EntityData; 4 4 import net.minecraft.entity.SpawnReason; 5 5 import net.minecraft.entity.passive.SheepEntity; 6 - import net.minecraft.nbt.NbtCompound; 7 6 import net.minecraft.util.DyeColor; 8 7 import net.minecraft.world.LocalDifficulty; 9 8 import net.minecraft.world.ServerWorldAccess; ··· 18 17 @Shadow public abstract void setColor(DyeColor color); 19 18 20 19 @Inject(method = "initialize", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;setColor(Lnet/minecraft/util/DyeColor;)V", shift = At.Shift.AFTER)) 21 - private void injected(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, NbtCompound entityNbt, CallbackInfoReturnable<EntityData> cir) { 20 + private void injected(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CallbackInfoReturnable<EntityData> cir) { 22 21 if (world.toServerWorld().getRegistryKey().getValue().toString().contains("infinity:classic")) { 23 22 setColor(DyeColor.WHITE); 24 23 }
+4 -4
src/main/java/net/lerariemann/infinity/mixin/options/ClientWorldMixin.java
··· 32 32 @Inject(method = "<init>", at = @At("TAIL")) 33 33 private void injected(ClientPlayNetworkHandler networkHandler, ClientWorld.Properties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> dimensionTypeEntry, int loadDistance, int simulationDistance, Supplier<Profiler> profiler, WorldRenderer worldRenderer, boolean debugWorld, long seed, CallbackInfo ci) { 34 34 DimensionType t = getDimension(); 35 - infinityoptions = ((InfinityOptionsAccess)MinecraftClient.getInstance()).getInfinityOptions(); 36 - ((InfinityOptionsAccess)(Object)t).setInfinityOptions(infinityoptions); 35 + infinityoptions = ((InfinityOptionsAccess)MinecraftClient.getInstance()).projectInfinity$getInfinityOptions(); 36 + ((InfinityOptionsAccess)(Object)t).projectInfinity$setInfinityOptions(infinityoptions); 37 37 } 38 38 39 39 @Override 40 - public InfinityOptions getInfinityOptions() { 40 + public InfinityOptions projectInfinity$getInfinityOptions() { 41 41 return infinityoptions; 42 42 } 43 43 @Override 44 - public void setInfinityOptions(InfinityOptions options) { 44 + public void projectInfinity$setInfinityOptions(InfinityOptions options) { 45 45 infinityoptions = options; 46 46 } 47 47 }
+3 -3
src/main/java/net/lerariemann/infinity/mixin/options/DimensionTypeMixin.java
··· 16 16 @ModifyArg(method = "getSkyAngle", at = @At(value="INVOKE", target="Lnet/minecraft/util/math/MathHelper;fractionalPart(D)D"), index = 0) 17 17 private double injected(double value) { 18 18 try { 19 - double timescale = getInfinityOptions().getTimeScale(); 19 + double timescale = projectInfinity$getInfinityOptions().getTimeScale(); 20 20 return timescale*(value + 0.25) - 0.25; 21 21 } catch (Exception e) { 22 22 return value; 23 23 } 24 24 } 25 - public InfinityOptions getInfinityOptions() { 25 + public InfinityOptions projectInfinity$getInfinityOptions() { 26 26 return infinityoptions; 27 27 } 28 28 @Override 29 - public void setInfinityOptions(InfinityOptions options) { 29 + public void projectInfinity$setInfinityOptions(InfinityOptions options) { 30 30 infinityoptions = options; 31 31 } 32 32 }
+4 -3
src/main/java/net/lerariemann/infinity/mixin/options/GameRendererMixin.java
··· 15 15 16 16 @Mixin(GameRenderer.class) 17 17 public class GameRendererMixin implements GameRendererAccess { 18 - @Shadow void loadPostProcessor(Identifier id) { 18 + @Shadow 19 + private void loadPostProcessor(Identifier id) { 19 20 } 20 21 21 22 @Override 22 - public void loadPP(Identifier id) { 23 + public void projectInfinity$loadPP(Identifier id) { 23 24 loadPostProcessor(id); 24 25 } 25 26 26 27 @Inject(method = "onCameraEntitySet", at = @At("TAIL"), cancellable = true) 27 28 private void preserveShaderThirdPerson(CallbackInfo ci) { 28 - InfinityOptions options = ((InfinityOptionsAccess)MinecraftClient.getInstance()).getInfinityOptions(); 29 + InfinityOptions options = ((InfinityOptionsAccess)MinecraftClient.getInstance()).projectInfinity$getInfinityOptions(); 29 30 if (options.getShader().isEmpty()) { 30 31 ci.cancel(); 31 32 }
+2 -2
src/main/java/net/lerariemann/infinity/mixin/options/MinecraftClientMixin.java
··· 21 21 } 22 22 23 23 @Unique 24 - public InfinityOptions getInfinityOptions() { 24 + public InfinityOptions projectInfinity$getInfinityOptions() { 25 25 return infinityoptions; 26 26 } 27 27 28 28 @Unique 29 - public void setInfinityOptions(InfinityOptions options) { 29 + public void projectInfinity$setInfinityOptions(InfinityOptions options) { 30 30 infinityoptions = options; 31 31 } 32 32 }
+9 -10
src/main/java/net/lerariemann/infinity/mixin/options/PlayerManagerMixin.java
··· 1 1 package net.lerariemann.infinity.mixin.options; 2 2 3 3 import com.llamalad7.mixinextras.sugar.Local; 4 - import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; 5 4 import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; 6 - import net.lerariemann.infinity.InfinityMod; 7 5 import net.lerariemann.infinity.access.MinecraftServerAccess; 8 6 import net.lerariemann.infinity.block.ModBlocks; 9 7 import net.lerariemann.infinity.block.entity.ModBlockEntities; 10 - import net.lerariemann.infinity.options.PacketTransiever; 8 + import net.lerariemann.infinity.var.ModPayloads; 11 9 import net.minecraft.block.BlockState; 12 10 import net.minecraft.network.ClientConnection; 13 11 import net.minecraft.server.PlayerManager; 12 + import net.minecraft.server.network.ConnectedClientData; 14 13 import net.minecraft.server.network.ServerPlayerEntity; 15 14 import net.minecraft.server.world.ServerWorld; 16 15 import net.minecraft.util.math.BlockPos; ··· 23 22 public class PlayerManagerMixin { 24 23 @Inject(method = "onPlayerConnect", at = @At(value="INVOKE", 25 24 target = "Lnet/minecraft/server/PlayerManager;sendCommandTree(Lnet/minecraft/server/network/ServerPlayerEntity;)V")) 26 - private void injected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci, @Local(ordinal=0) ServerWorld serverWorld2) { 27 - ServerPlayNetworking.send(player, InfinityMod.SHADER_RELOAD, PacketTransiever.buildPacket(serverWorld2)); 28 - ServerPlayNetworking.send(player, InfinityMod.STARS_RELOAD, PacketByteBufs.create()); 25 + private void injected(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci, @Local(ordinal=0) ServerWorld serverWorld2) { 26 + ServerPlayNetworking.send(player, ModPayloads.setShaderFromWorld(serverWorld2)); 27 + ServerPlayNetworking.send(player, ModPayloads.StarsRePayLoad.INSTANCE); 29 28 MinecraftServerAccess acc = ((MinecraftServerAccess)(serverWorld2.getServer())); 30 - if (acc.needsInvocation()) { 29 + if (acc.projectInfinity$needsInvocation()) { 31 30 int y = serverWorld2.getTopY() - 10; 32 31 BlockPos pos = new BlockPos(player.getBlockX(), y, player.getBlockY()); 33 32 BlockState st = serverWorld2.getBlockState(pos); 34 33 serverWorld2.setBlockState(pos, ModBlocks.ALTAR_COSMIC.getDefaultState()); 35 34 serverWorld2.getBlockEntity(pos, ModBlockEntities.ALTAR_COSMIC).ifPresent(e -> e.addNull(st)); 36 - acc.onInvocation(); 35 + acc.projectInfinity$onInvocation(); 37 36 } 38 37 } 39 38 40 39 @Inject(method="sendWorldInfo", at = @At("TAIL")) 41 40 private void injected2(ServerPlayerEntity player, ServerWorld world, CallbackInfo ci) { 42 - ServerPlayNetworking.send(player, InfinityMod.SHADER_RELOAD, PacketTransiever.buildPacket(world)); 43 - ServerPlayNetworking.send(player, InfinityMod.STARS_RELOAD, PacketByteBufs.create()); 41 + ServerPlayNetworking.send(player, ModPayloads.setShaderFromWorld(world)); 42 + ServerPlayNetworking.send(player, ModPayloads.StarsRePayLoad.INSTANCE); 44 43 } 45 44 }
+7 -7
src/main/java/net/lerariemann/infinity/mixin/options/ServerWorldMixin.java
··· 19 19 import net.minecraft.world.dimension.DimensionType; 20 20 import net.minecraft.world.level.ServerWorldProperties; 21 21 import net.minecraft.world.level.storage.LevelStorage; 22 - import net.minecraft.world.spawner.Spawner; 22 + import net.minecraft.world.spawner.SpecialSpawner; 23 23 import org.spongepowered.asm.mixin.Mixin; 24 24 import org.spongepowered.asm.mixin.Unique; 25 25 import org.spongepowered.asm.mixin.injection.At; ··· 44 44 } 45 45 46 46 @Inject(method = "<init>", at = @At("TAIL")) 47 - private void injected(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, RandomSequencesState randomSequencesState, CallbackInfo ci) { 47 + private void injected(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<SpecialSpawner> spawners, boolean shouldTickTime, RandomSequencesState randomSequencesState, CallbackInfo ci) { 48 48 infinityoptions = InfinityOptions.generate(server, worldKey); 49 49 DimensionType t = getDimension(); 50 - ((InfinityOptionsAccess)(Object)t).setInfinityOptions(infinityoptions); 50 + ((InfinityOptionsAccess)(Object)t).projectInfinity$setInfinityOptions(infinityoptions); 51 51 timebombed = 0; 52 52 } 53 53 ··· 62 62 } 63 63 64 64 @Override 65 - public void timebomb(int i) { 65 + public void projectInfinity$timebomb(int i) { 66 66 if(getRegistryKey().getValue().toString().contains("infinity")) timebombed = i; 67 67 } 68 68 69 69 @Override 70 - public int isTimebobmed() { 70 + public int projectInfinity$isTimebobmed() { 71 71 return timebombed; 72 72 } 73 73 74 74 @Override 75 - public InfinityOptions getInfinityOptions() { 75 + public InfinityOptions projectInfinity$getInfinityOptions() { 76 76 return infinityoptions; 77 77 } 78 78 @Override 79 - public void setInfinityOptions(InfinityOptions options) { 79 + public void projectInfinity$setInfinityOptions(InfinityOptions options) { 80 80 infinityoptions = options; 81 81 } 82 82 }
+61 -57
src/main/java/net/lerariemann/infinity/mixin/options/WorldRendererMixin.java
··· 4 4 import com.mojang.blaze3d.systems.RenderSystem; 5 5 import net.fabricmc.api.EnvType; 6 6 import net.fabricmc.api.Environment; 7 + import net.lerariemann.infinity.InfinityMod; 7 8 import net.lerariemann.infinity.access.InfinityOptionsAccess; 8 9 import net.lerariemann.infinity.access.WorldRendererAccess; 9 10 import net.lerariemann.infinity.options.InfinityOptions; 11 + import net.minecraft.block.enums.CameraSubmersionType; 10 12 import net.minecraft.client.MinecraftClient; 11 13 import net.minecraft.client.gl.VertexBuffer; 12 14 import net.minecraft.client.render.*; ··· 54 56 } 55 57 } 56 58 @Override 57 - public void setNeedsStars(boolean b) { 59 + public void projectInfinity$setNeedsStars(boolean b) { 58 60 needsStars = b; 59 61 } 60 62 61 - @Inject(method = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FLnet/minecraft/client/render/Camera;ZLjava/lang/Runnable;)V", 63 + @Inject(method = "renderSky(Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;FLnet/minecraft/client/render/Camera;ZLjava/lang/Runnable;)V", 62 64 at=@At("HEAD"), cancellable=true) 63 - private void injected4(MatrixStack matrices, Matrix4f projectionMatrix, float tickDelta, Camera camera, boolean thickFog, Runnable fogCallback, CallbackInfo ci) { 65 + private void injected4(Matrix4f matrix4f, Matrix4f projectionMatrix, float tickDelta, Camera camera, boolean thickFog, Runnable fogCallback, CallbackInfo ci) { 64 66 if (!options().isEmpty()) { 65 - renderEntireSky(matrices, projectionMatrix, tickDelta, camera, thickFog, fogCallback); 67 + renderEntireSky(matrix4f, projectionMatrix, tickDelta, camera, thickFog, fogCallback); 66 68 ci.cancel(); 67 69 } 68 70 } 69 - @ModifyConstant(method = "renderStars(Lnet/minecraft/client/render/BufferBuilder;)Lnet/minecraft/client/render/BufferBuilder$BuiltBuffer;", constant = @Constant(intValue = 1500)) 71 + @ModifyConstant(method = "buildStarsBuffer(Lnet/minecraft/client/render/Tessellator;)Lnet/minecraft/client/render/BuiltBuffer;", constant = @Constant(intValue = 1500)) 70 72 private int injected(int constant) { 71 73 return options().getNumStars(); 72 74 } 73 - @ModifyConstant(method = "renderStars(Lnet/minecraft/client/render/BufferBuilder;)Lnet/minecraft/client/render/BufferBuilder$BuiltBuffer;", constant = @Constant(floatValue = 0.15f)) 75 + @ModifyConstant(method = "buildStarsBuffer(Lnet/minecraft/client/render/Tessellator;)Lnet/minecraft/client/render/BuiltBuffer;", constant = @Constant(floatValue = 0.15f)) 74 76 private float injected2(float constant) { 75 77 return options().getStarSizeBase(); 76 78 } 77 - @ModifyConstant(method = "renderStars(Lnet/minecraft/client/render/BufferBuilder;)Lnet/minecraft/client/render/BufferBuilder$BuiltBuffer;", constant = @Constant(floatValue = 0.1f)) 79 + @ModifyConstant(method = "buildStarsBuffer(Lnet/minecraft/client/render/Tessellator;)Lnet/minecraft/client/render/BuiltBuffer;", constant = @Constant(floatValue = 0.1f)) 78 80 private float injected3(float constant) { 79 81 return options().getStarSizeModifier(); 80 82 } 81 83 82 84 @Unique 83 - private void renderEntireSky(MatrixStack matrices, Matrix4f projectionMatrix, float tickDelta, Camera camera, boolean thickFog, Runnable fogCallback) { 85 + private void renderEntireSky(Matrix4f matrix4f, Matrix4f projectionMatrix, float tickDelta, Camera camera, boolean thickFog, Runnable fogCallback) { 84 86 fogCallback.run(); 85 87 if (thickFog) { 86 88 return; ··· 89 91 if (cameraSubmersionType == CameraSubmersionType.POWDER_SNOW || cameraSubmersionType == CameraSubmersionType.LAVA || hasBlindnessOrDarkness(camera)) { 90 92 return; 91 93 } 94 + MatrixStack matrices = new MatrixStack(); 95 + matrices.multiplyPositionMatrix(matrix4f); 92 96 if (client.world!=null && client.world.getDimensionEffects().getSkyType() == DimensionEffects.SkyType.END) { 93 - this.renderCustomSky(matrices, new Identifier("textures/environment/end_sky.png"), 16.0f, 40, 255, tickDelta, false); 97 + this.renderCustomSky(matrices, Identifier.of("textures/environment/end_sky.png"), 16.0f, 40, 255, tickDelta, false); 94 98 return; 95 99 } 96 100 if (options().endSkyLike()) { ··· 101 105 return; 102 106 } 103 107 104 - BackgroundRenderer.setFogBlack(); 105 - BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer(); 108 + BackgroundRenderer.applyFogColor(); 109 + Tessellator tessellator = Tessellator.getInstance(); 106 110 RenderSystem.depthMask(false); 107 111 handleSkyBackground(matrices, projectionMatrix, tickDelta); 108 - handleFog(matrices, bufferBuilder, tickDelta); 112 + handleFog(matrices, tessellator, tickDelta); 109 113 matrices.push(); 110 114 111 115 float rain_alpha = 1.0f - this.world.getRainGradient(tickDelta); ··· 114 118 rotate_with_velocity(matrices, tickDelta, 1); 115 119 Matrix4f matrix4f2 = matrices.peek().getPositionMatrix(); //creates the rotating layer for stellar bodies 116 120 117 - renderSun(bufferBuilder, matrix4f2, options().getSolarTexture(), options().getSolarSize(), 100.0f, options().getSolarTint()); 121 + renderSun(tessellator, matrix4f2, options().getSolarTexture(), options().getSolarSize(), 100.0f, options().getSolarTint()); 118 122 for (int i = 0; i < options().getNumMoons(); i++) { 119 - renderSingleMoon(matrices, bufferBuilder, tickDelta, options().getLunarSize(i), options().getLunarTiltY(i), options().getLunarTiltZ(i), 123 + renderSingleMoon(matrices, tessellator, tickDelta, options().getLunarSize(i), options().getLunarTiltY(i), options().getLunarTiltZ(i), 120 124 options().getLunarVelocity(i), options().getLunarOffset(i), options().getLunarTint(i), options().getLunarTexture(i)); 121 125 } 122 126 testRerenderStars(); ··· 156 160 } 157 161 boolean color = !options().endSkyLike(); 158 162 if (skyType.contains("textures")) { 159 - renderCustomSky(matrices, new Identifier(skyType), tickDelta, color); 163 + renderCustomSky(matrices, Identifier.of(skyType), tickDelta, color); 160 164 } 161 165 else if (skyType.equals("LSD_rainbow")) { 162 166 renderLSDSky(matrices, tickDelta, color); ··· 179 183 } 180 184 181 185 @Unique 182 - private void renderSun(BufferBuilder bufferBuilder, Matrix4f matrix4f2, Identifier texture, float k, float y, Vector3f tint) { 186 + private void renderSun(Tessellator tessellator, Matrix4f matrix4f2, Identifier texture, float k, float y, Vector3f tint) { 183 187 RenderSystem.setShader(GameRenderer::getPositionTexProgram); 184 188 RenderSystem.setShaderTexture(0, texture); 185 189 RenderSystem.setShaderColor(tint.x, tint.y, tint.z, 1.0f); 186 - bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); 187 - bufferBuilder.vertex(matrix4f2, -k, y, -k).texture(0.0f, 0.0f).next(); 188 - bufferBuilder.vertex(matrix4f2, k, y, -k).texture(1.0f, 0.0f).next(); 189 - bufferBuilder.vertex(matrix4f2, k, y, k).texture(1.0f, 1.0f).next(); 190 - bufferBuilder.vertex(matrix4f2, -k, y, k).texture(0.0f, 1.0f).next(); 190 + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); 191 + bufferBuilder.vertex(matrix4f2, -k, y, -k).texture(0.0f, 0.0f); 192 + bufferBuilder.vertex(matrix4f2, k, y, -k).texture(1.0f, 0.0f); 193 + bufferBuilder.vertex(matrix4f2, k, y, k).texture(1.0f, 1.0f); 194 + bufferBuilder.vertex(matrix4f2, -k, y, k).texture(0.0f, 1.0f); 191 195 BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); 192 196 } 193 197 194 198 @Unique 195 - private void renderSingleMoon(MatrixStack matrices, BufferBuilder bufferBuilder, float tickDelta, float size, float tilt_y, float tilt_z, float velocity, float offset, Vector3f tint, Identifier texture) { 199 + private void renderSingleMoon(MatrixStack matrices, Tessellator tessellator, float tickDelta, float size, float tilt_y, float tilt_z, float velocity, float offset, Vector3f tint, Identifier texture) { 196 200 float lunarv = (velocity != 1.0f) ? velocity - 1 : 0; 197 201 matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(tilt_y)); 198 202 matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(tilt_z)); 199 203 rotate_with_velocity(matrices, tickDelta, lunarv, offset); 200 - renderMoon(bufferBuilder, matrices.peek().getPositionMatrix(), texture, size, -100.0f, tint); 204 + renderMoon(tessellator, matrices.peek().getPositionMatrix(), texture, size, -100.0f, tint); 201 205 rotate_with_velocity(matrices, tickDelta, -1 * lunarv, offset); 202 206 matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-tilt_z)); 203 207 matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-tilt_y)); 204 208 } 205 - 206 209 @Unique 207 - private void renderMoon(BufferBuilder bufferBuilder, Matrix4f matrix4f2, Identifier texture, float k, float y, Vector3f tint, float t, float q, float p, float o) { 208 - RenderSystem.setShader(GameRenderer::getPositionTexProgram); 209 - RenderSystem.setShaderTexture(0, texture); 210 - RenderSystem.setShaderColor(tint.x, tint.y, tint.z, 1.0f); 211 - bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); 212 - bufferBuilder.vertex(matrix4f2, -k, y, k).texture(p, q).next(); 213 - bufferBuilder.vertex(matrix4f2, k, y, k).texture(t, q).next(); 214 - bufferBuilder.vertex(matrix4f2, k, y, -k).texture(t, o).next(); 215 - bufferBuilder.vertex(matrix4f2, -k, y, -k).texture(p, o).next(); 216 - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); 217 - } 218 - @Unique 219 - private void renderMoon(BufferBuilder bufferBuilder, Matrix4f matrix4f2, Identifier texture, float k, float y, Vector3f tint) { 210 + private void renderMoon(Tessellator tessellator, Matrix4f matrix4f2, Identifier texture, float k, float y, Vector3f tint) { 220 211 float t, q, p, o; 221 212 if (!options().isMoonCustom()) { 222 213 int r = this.world.getMoonPhase(); ··· 231 222 t = q = 1.0f; 232 223 p = o = 0.0f; 233 224 } 234 - renderMoon(bufferBuilder, matrix4f2, texture, k, y, tint, t, q, p, o); 225 + renderMoon(tessellator, matrix4f2, texture, k, y, tint, t, q, p, o); 226 + } 227 + @Unique 228 + private void renderMoon(Tessellator tessellator, Matrix4f matrix4f2, Identifier texture, float k, float y, Vector3f tint, float t, float q, float p, float o) { 229 + RenderSystem.setShader(GameRenderer::getPositionTexProgram); 230 + RenderSystem.setShaderTexture(0, texture); 231 + RenderSystem.setShaderColor(tint.x, tint.y, tint.z, 1.0f); 232 + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); 233 + bufferBuilder.vertex(matrix4f2, -k, y, k).texture(p, q); 234 + bufferBuilder.vertex(matrix4f2, k, y, k).texture(t, q); 235 + bufferBuilder.vertex(matrix4f2, k, y, -k).texture(t, o); 236 + bufferBuilder.vertex(matrix4f2, -k, y, -k).texture(p, o); 237 + BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); 235 238 } 236 239 237 240 @Unique 238 241 private void renderStars(Matrix4f matrix4f2, float tickDelta, Matrix4f projectionMatrix, Runnable fogCallback, float i) { 239 - float u = world.method_23787(tickDelta) * i; 242 + float u = world.getStarBrightness(tickDelta) * i; 240 243 Vector3f color = options().getStellarColor(); 241 244 if (u > 0.0f) { 242 245 RenderSystem.setShaderColor(u*color.x, u*color.y, u*color.z, u); ··· 250 253 251 254 @Unique 252 255 private InfinityOptions options() { 253 - InfinityOptions options = ((InfinityOptionsAccess)client).getInfinityOptions(); 256 + InfinityOptions options = ((InfinityOptionsAccess)client).projectInfinity$getInfinityOptions(); 254 257 if (options == null) options = InfinityOptions.empty(); 255 258 return options; 256 259 } ··· 262 265 renderSingleColorSky(matrices, projectionMatrix, f * (float)(color >> 16 & 0xFF) / 255.0f, f * (float)(color >> 8 & 0xFF) / 255.0f, f * (float)(color & 0xFF) / 255.0f, 1.0f); 263 266 } 264 267 @Unique 265 - private static final Identifier[] LSD_SKY = new Identifier[]{new Identifier("infinity:textures/lsd.png"), 266 - new Identifier("infinity:textures/lsd60.png"), 267 - new Identifier("infinity:textures/lsd120.png"), 268 - new Identifier("infinity:textures/lsd180.png"), 269 - new Identifier("infinity:textures/lsd240.png"), 270 - new Identifier("infinity:textures/lsd300.png")}; 268 + private static final Identifier[] LSD_SKY = new Identifier[]{InfinityMod.getId("textures/lsd.png"), 269 + InfinityMod.getId("textures/lsd60.png"), 270 + InfinityMod.getId("textures/lsd120.png"), 271 + InfinityMod.getId("textures/lsd180.png"), 272 + InfinityMod.getId("textures/lsd240.png"), 273 + InfinityMod.getId("textures/lsd300.png")}; 271 274 272 275 @Unique 273 276 private void renderLSDSky(MatrixStack matrices, float tickDelta, boolean color) { ··· 299 302 } 300 303 RenderSystem.setShaderTexture(0, texture); 301 304 Tessellator tessellator = Tessellator.getInstance(); 302 - BufferBuilder bufferBuilder = tessellator.getBuffer(); 305 + 303 306 for (int i = 0; i < 6; ++i) { 304 307 matrices.push(); 305 308 if (i == 1) { ··· 317 320 if (i == 5) { 318 321 matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-90.0f)); 319 322 } 323 + 320 324 Matrix4f matrix4f = matrices.peek().getPositionMatrix(); 321 - bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); 322 - bufferBuilder.vertex(matrix4f, -100.0f, -100.0f, -100.0f).texture(0.0f, 0.0f).color(r, g, b, alpha).next(); 323 - bufferBuilder.vertex(matrix4f, -100.0f, -100.0f, 100.0f).texture(0.0f, copies).color(r, g, b, alpha).next(); 324 - bufferBuilder.vertex(matrix4f, 100.0f, -100.0f, 100.0f).texture(copies, copies).color(r, g, b, alpha).next(); 325 - bufferBuilder.vertex(matrix4f, 100.0f, -100.0f, -100.0f).texture(copies, 0.0f).color(r, g, b, alpha).next(); 326 - tessellator.draw(); 325 + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); 326 + bufferBuilder.vertex(matrix4f, -100.0f, -100.0f, -100.0f).texture(0.0f, 0.0f).color(r, g, b, alpha); 327 + bufferBuilder.vertex(matrix4f, -100.0f, -100.0f, 100.0f).texture(0.0f, copies).color(r, g, b, alpha); 328 + bufferBuilder.vertex(matrix4f, 100.0f, -100.0f, 100.0f).texture(copies, copies).color(r, g, b, alpha); 329 + bufferBuilder.vertex(matrix4f, 100.0f, -100.0f, -100.0f).texture(copies, 0.0f).color(r, g, b, alpha); 330 + BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); 327 331 matrices.pop(); 328 332 } 329 333 RenderSystem.depthMask(true); ··· 331 335 } 332 336 333 337 @Unique 334 - private void handleFog(MatrixStack matrices, BufferBuilder bufferBuilder, float tickDelta) { 338 + private void handleFog(MatrixStack matrices, Tessellator tessellator, float tickDelta) { 335 339 RenderSystem.enableBlend(); 336 340 float[] fs = this.world.getDimensionEffects().getFogColorOverride(this.world.getSkyAngle(tickDelta), tickDelta); 337 341 if (fs != null) { ··· 346 350 float k = fs[1]; 347 351 float l = fs[2]; 348 352 Matrix4f matrix4f = matrices.peek().getPositionMatrix(); 349 - bufferBuilder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); 350 - bufferBuilder.vertex(matrix4f, 0.0f, 100.0f, 0.0f).color(j, k, l, fs[3]).next(); 353 + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); 354 + bufferBuilder.vertex(matrix4f, 0.0f, 100.0f, 0.0f).color(j, k, l, fs[3]); 351 355 for (int n = 0; n <= 16; ++n) { 352 356 float o = (float)n * ((float)Math.PI * 2) / 16.0f; 353 357 float p = MathHelper.sin(o); 354 358 float q = MathHelper.cos(o); 355 - bufferBuilder.vertex(matrix4f, p * 120.0f, q * 120.0f, -q * 40.0f * fs[3]).color(fs[0], fs[1], fs[2], 0.0f).next(); 359 + bufferBuilder.vertex(matrix4f, p * 120.0f, q * 120.0f, -q * 40.0f * fs[3]).color(fs[0], fs[1], fs[2], 0.0f); 356 360 } 357 361 BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); 358 362 matrices.pop();
+2 -2
src/main/java/net/lerariemann/infinity/options/InfinityOptions.java
··· 58 58 } 59 59 60 60 public Identifier getSolarTexture() { 61 - return new Identifier(data.contains("solar_texture") ? data.getString("solar_texture") : "textures/environment/sun.png"); 61 + return Identifier.of(data.contains("solar_texture") ? data.getString("solar_texture") : "textures/environment/sun.png"); 62 62 } 63 63 64 64 public Vector3f getStellarColor() { ··· 140 140 } 141 141 142 142 public Identifier getLunarTexture(int i) { 143 - return new Identifier(lunarTest("lunar_texture", i) ? 143 + return Identifier.of(lunarTest("lunar_texture", i) ? 144 144 ((NbtCompound)(data.getList("moons", NbtElement.COMPOUND_TYPE).get(i))).getString("lunar_texture") : "textures/environment/moon_phases.png"); 145 145 } 146 146
-38
src/main/java/net/lerariemann/infinity/options/PacketTransiever.java
··· 1 - package net.lerariemann.infinity.options; 2 - 3 - import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; 4 - import net.fabricmc.fabric.api.networking.v1.PacketSender; 5 - import net.lerariemann.infinity.access.InfinityOptionsAccess; 6 - import net.lerariemann.infinity.access.WorldRendererAccess; 7 - import net.lerariemann.infinity.util.CommonIO; 8 - import net.minecraft.client.MinecraftClient; 9 - import net.minecraft.client.network.ClientPlayNetworkHandler; 10 - import net.minecraft.nbt.NbtCompound; 11 - import net.minecraft.network.PacketByteBuf; 12 - import net.minecraft.server.world.ServerWorld; 13 - 14 - public class PacketTransiever { 15 - public static PacketByteBuf buildPacket(ServerWorld destination) { 16 - PacketByteBuf buf = PacketByteBufs.create(); 17 - buf.writeNbt(((InfinityOptionsAccess)(destination)).getInfinityOptions().data()); 18 - return buf; 19 - } 20 - 21 - public static void receive(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { 22 - InfinityOptions options = new InfinityOptions(buf.readNbt()); 23 - ((InfinityOptionsAccess)client).setInfinityOptions(options); 24 - NbtCompound shader = options.getShader(); 25 - boolean bl = shader.isEmpty(); 26 - if (bl) client.execute(() -> ShaderLoader.reloadShaders(client, false)); 27 - else { 28 - client.execute(() -> { 29 - CommonIO.write(shader, ShaderLoader.shaderDir(client), ShaderLoader.FILENAME); 30 - ShaderLoader.reloadShaders(client, true); 31 - }); 32 - } 33 - } 34 - 35 - public static void receiveStars(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { 36 - ((WorldRendererAccess)(client.worldRenderer)).setNeedsStars(true); 37 - } 38 - }
+4 -4
src/main/java/net/lerariemann/infinity/options/ShaderLoader.java
··· 15 15 16 16 @Environment(EnvType.CLIENT) 17 17 public class ShaderLoader { 18 - static String FILENAME = "current.json"; 19 - static Path shaderDir(MinecraftClient client) { 18 + public static String FILENAME = "current.json"; 19 + public static Path shaderDir(MinecraftClient client) { 20 20 return client.getResourcePackDir().resolve("infinity/assets/infinity/shaders"); 21 21 } 22 22 ··· 27 27 throw new RuntimeException(e); 28 28 } 29 29 if(bl && shaderDir(client).resolve(FILENAME).toFile().exists()) { 30 - ((GameRendererAccess)(client.gameRenderer)).loadPP(InfinityMod.getId("shaders/" + FILENAME)); 30 + ((GameRendererAccess)(client.gameRenderer)).projectInfinity$loadPP(InfinityMod.getId("shaders/" + FILENAME)); 31 31 return; 32 32 } 33 33 client.gameRenderer.disablePostProcessor(); ··· 45 45 private static NbtCompound packMcmeta() { 46 46 NbtCompound res = new NbtCompound(); 47 47 NbtCompound pack = new NbtCompound(); 48 - pack.putInt("pack_format", 15); 48 + pack.putInt("pack_format", 34); 49 49 pack.putString("description", "Shader container"); 50 50 res.put("pack", pack); 51 51 return res;
-2
src/main/java/net/lerariemann/infinity/structure/ModStructureType.java
··· 7 7 import net.minecraft.world.gen.structure.StructureType; 8 8 9 9 public class ModStructureType { 10 - public static StructureType<RandomPortalStructure> PORTAL; 11 10 public static StructurePieceType PYRAMID_PIECE; 12 11 public static StructureType<PyramidStructure> PYRAMID; 13 12 ··· 21 20 22 21 public static void registerStructures() { 23 22 InfinityMod.LOGGER.debug("Registering processors for " + InfinityMod.MOD_ID); 24 - PORTAL = Registry.register(Registries.STRUCTURE_TYPE, InfinityMod.getId("portal"), () -> RandomPortalStructure.CODEC); 25 23 PYRAMID = Registry.register(Registries.STRUCTURE_TYPE, InfinityMod.getId("pyramid"), () -> PyramidStructure.CODEC); 26 24 PYRAMID_PIECE = register(PyramidGenerator::new, "infinity:pypiece"); 27 25 }
+2 -1
src/main/java/net/lerariemann/infinity/structure/PyramidStructure.java
··· 1 1 package net.lerariemann.infinity.structure; 2 2 3 3 import com.mojang.serialization.Codec; 4 + import com.mojang.serialization.MapCodec; 4 5 import com.mojang.serialization.codecs.RecordCodecBuilder; 5 6 import net.minecraft.structure.StructurePiecesCollector; 6 7 import net.minecraft.world.Heightmap; ··· 11 12 import java.util.Optional; 12 13 13 14 public class PyramidStructure extends Structure { 14 - public static final Codec<PyramidStructure> CODEC = RecordCodecBuilder.create(instance -> instance.group( 15 + public static final MapCodec<PyramidStructure> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( 15 16 PyramidStructure.configCodecBuilder(instance), 16 17 (Codec.INT.fieldOf("top_y")).forGetter(a -> a.top_y), 17 18 (Codec.INT.fieldOf("bottom_y")).forGetter(a -> a.top_y),
-107
src/main/java/net/lerariemann/infinity/structure/RandomPortalStructure.java
··· 1 - package net.lerariemann.infinity.structure; 2 - 3 - import com.mojang.brigadier.exceptions.CommandSyntaxException; 4 - import com.mojang.serialization.Codec; 5 - import com.mojang.serialization.DataResult; 6 - import com.mojang.serialization.codecs.RecordCodecBuilder; 7 - import net.minecraft.entity.Entity; 8 - import net.minecraft.entity.ItemEntity; 9 - import net.minecraft.item.ItemStack; 10 - import net.minecraft.item.Items; 11 - import net.minecraft.nbt.StringNbtReader; 12 - import net.minecraft.registry.entry.RegistryEntry; 13 - import net.minecraft.structure.StructurePiecesList; 14 - import net.minecraft.structure.pool.StructurePool; 15 - import net.minecraft.structure.pool.StructurePoolBasedGenerator; 16 - import net.minecraft.util.Identifier; 17 - import net.minecraft.util.TypeFilter; 18 - import net.minecraft.util.dynamic.Codecs; 19 - import net.minecraft.util.math.*; 20 - import net.minecraft.util.math.random.Random; 21 - import net.minecraft.world.Heightmap; 22 - import net.minecraft.world.StructureWorldAccess; 23 - import net.minecraft.world.gen.HeightContext; 24 - import net.minecraft.world.gen.StructureAccessor; 25 - import net.minecraft.world.gen.chunk.ChunkGenerator; 26 - import net.minecraft.world.gen.heightprovider.HeightProvider; 27 - import net.minecraft.world.gen.structure.Structure; 28 - import net.minecraft.world.gen.structure.StructureType; 29 - 30 - import java.util.Optional; 31 - 32 - public class RandomPortalStructure extends Structure { 33 - public static final Codec<RandomPortalStructure> CODEC = Codecs.validate( 34 - RecordCodecBuilder.mapCodec(instance -> instance.group(RandomPortalStructure.configCodecBuilder(instance), 35 - (StructurePool.REGISTRY_CODEC.fieldOf("start_pool")).forGetter(structure -> structure.startPool), 36 - Identifier.CODEC.optionalFieldOf("start_jigsaw_name").forGetter(structure -> structure.startJigsawName), 37 - (Codec.intRange(0, 7).fieldOf("size")).forGetter(structure -> structure.size), 38 - (HeightProvider.CODEC.fieldOf("start_height")).forGetter(structure -> structure.startHeight), 39 - (Codec.BOOL.fieldOf("use_expansion_hack")).forGetter(structure -> structure.useExpansionHack), 40 - Heightmap.Type.CODEC.optionalFieldOf("project_start_to_heightmap").forGetter(structure -> structure.projectStartToHeightmap), 41 - (Codec.intRange(1, 128).fieldOf("max_distance_from_center")).forGetter(structure -> structure.maxDistanceFromCenter)).apply( 42 - instance, RandomPortalStructure::new)), RandomPortalStructure::validate).codec(); 43 - private final RegistryEntry<StructurePool> startPool; 44 - private final Optional<Identifier> startJigsawName; 45 - private final int size; 46 - private final HeightProvider startHeight; 47 - private final boolean useExpansionHack; 48 - private final Optional<Heightmap.Type> projectStartToHeightmap; 49 - private final int maxDistanceFromCenter; 50 - 51 - private static DataResult<RandomPortalStructure> validate(RandomPortalStructure structure) { 52 - int i; 53 - switch (structure.getTerrainAdaptation()) { 54 - default -> throw new IncompatibleClassChangeError(); 55 - case NONE -> i = 0; 56 - case BURY, BEARD_THIN, BEARD_BOX -> i = 12; 57 - } 58 - if (structure.maxDistanceFromCenter + i > 128) { 59 - return DataResult.error(() -> "Structure size including terrain adaptation must not exceed 128"); 60 - } 61 - return DataResult.success(structure); 62 - } 63 - 64 - public RandomPortalStructure(Structure.Config config, RegistryEntry<StructurePool> startPool, Optional<Identifier> startJigsawName, int size, HeightProvider startHeight, boolean useExpansionHack, Optional<Heightmap.Type> projectStartToHeightmap, int maxDistanceFromCenter) { 65 - super(config); 66 - this.startPool = startPool; 67 - this.startJigsawName = startJigsawName; 68 - this.size = size; 69 - this.startHeight = startHeight; 70 - this.useExpansionHack = useExpansionHack; 71 - this.projectStartToHeightmap = projectStartToHeightmap; 72 - this.maxDistanceFromCenter = maxDistanceFromCenter; 73 - } 74 - 75 - @Override 76 - public Optional<Structure.StructurePosition> getStructurePosition(Structure.Context context) { 77 - ChunkPos chunkPos = context.chunkPos(); 78 - int i = this.startHeight.get(context.random(), new HeightContext(context.chunkGenerator(), context.world())); 79 - BlockPos blockPos = new BlockPos(chunkPos.getStartX(), i, chunkPos.getStartZ()); 80 - Optional<Structure.StructurePosition> s = StructurePoolBasedGenerator.generate(context, this.startPool, this.startJigsawName, this.size, blockPos, this.useExpansionHack, this.projectStartToHeightmap, this.maxDistanceFromCenter); 81 - return s; 82 - } 83 - 84 - @Override 85 - public StructureType<?> getType() { 86 - return ModStructureType.PORTAL; 87 - } 88 - 89 - @Override 90 - public void postPlace(StructureWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox box, ChunkPos chunkPos, StructurePiecesList pieces) { 91 - Box b = Box.from(pieces.getBoundingBox()); 92 - BlockPos pos = BlockPos.ofFloored(b.getCenter().x, b.getCenter().y, b.getCenter().z); 93 - try { 94 - if (!world.isClient() && world.toServerWorld().getEntitiesByType(TypeFilter.instanceOf(ItemEntity.class), b, RandomPortalStructure::isBook).isEmpty()) { 95 - ItemStack stack = ItemStack.fromNbt(StringNbtReader.parse( 96 - "{id:\"minecraft:written_book\", Count:1b, tag:{author:\"LeraRiemann\",filtered_title:\"" + pos + "\",pages:['{\"text\":\"" + pos + "\"}'],title:\"" + pos + "\"}}")); 97 - Entity e = new ItemEntity(world.toServerWorld(), b.getCenter().x, b.getCenter().y + 1.0, b.getCenter().z, stack, 0.0, 0.0, 0.0); 98 - world.spawnEntityAndPassengers(e); 99 - } 100 - } catch (CommandSyntaxException e) { 101 - throw new RuntimeException(e); 102 - } 103 - } 104 - public static boolean isBook(ItemEntity entity) { 105 - return entity.getStack().getItem() == Items.WRITTEN_BOOK || entity.getStack().getItem() == Items.WRITABLE_BOOK; 106 - } 107 - }
+9 -9
src/main/java/net/lerariemann/infinity/util/ConfigGenerator.java
··· 4 4 import net.minecraft.block.Block; 5 5 import net.minecraft.block.BlockState; 6 6 import net.minecraft.block.FallingBlock; 7 - import net.minecraft.block.enums.WallMountLocation; 7 + import net.minecraft.block.enums.BlockFace; 8 8 import net.minecraft.entity.EntityType; 9 9 import net.minecraft.entity.SpawnGroup; 10 10 import net.minecraft.fluid.Fluid; ··· 35 35 NbtCompound res = new NbtCompound(); 36 36 NbtList elements = new NbtList(); 37 37 int cse = 0; 38 - if (w.keys.get(0) instanceof String) cse = 1; 39 - if (w.keys.get(0) instanceof NbtCompound) cse = 2; 40 - if (w.keys.get(0) instanceof NbtList) cse = 3; 38 + if (w.keys.getFirst() instanceof String) cse = 1; 39 + if (w.keys.getFirst() instanceof NbtCompound) cse = 2; 40 + if (w.keys.getFirst() instanceof NbtList) cse = 3; 41 41 int finalCse = cse; 42 42 List<Integer> range = new ArrayList<>(IntStream.rangeClosed(0, w.keys.size() - 1).boxed().toList()); 43 43 range.sort(new Comparator<Integer>() { 44 44 public String extract(int i) { 45 45 return switch (finalCse) { 46 - default -> w.keys.get(i).toString(); 47 46 case 2 -> ((NbtCompound)(w.keys.get(i))).getString("Name"); 48 - case 3 -> ((NbtList)(w.keys.get(i))).get(0).toString(); 47 + case 3 -> ((NbtList)(w.keys.get(i))).getFirst().toString(); 48 + default -> w.keys.get(i).toString(); 49 49 }; 50 50 } 51 51 @Override ··· 103 103 res.putBoolean("float", isFloat(bs, w, inAir)); 104 104 NbtCompound properties = new NbtCompound(); 105 105 if (bs.contains(Properties.PERSISTENT)) properties.putString("persistent", "true"); 106 - if (bs.contains(Properties.WALL_MOUNT_LOCATION)) { 106 + if (bs.contains(Properties.BLOCK_FACE)) { 107 107 properties.putString("face", "floor"); 108 - bs = bs.with(Properties.WALL_MOUNT_LOCATION, WallMountLocation.FLOOR); 108 + bs = bs.with(Properties.BLOCK_FACE, BlockFace.FLOOR); 109 109 } 110 110 res.putBoolean("top", isTop(bs, w, onStone)); 111 111 if (!properties.isEmpty()) res.put("Properties", properties); ··· 205 205 Arrays.stream(colors).forEach(color -> { 206 206 int i = block.lastIndexOf("magenta"); 207 207 String blockColored = block.substring(0, i) + color + block.substring(i+7); 208 - if (Registries.BLOCK.containsId(new Identifier(blockColored))) { 208 + if (Registries.BLOCK.containsId(Identifier.of(blockColored))) { 209 209 successCounter.addAndGet(1); 210 210 NbtCompound c = new NbtCompound(); 211 211 c.putString("Name", blockColored);
+1 -4
src/main/java/net/lerariemann/infinity/util/ConfigManager.java
··· 6 6 import net.minecraft.nbt.NbtCompound; 7 7 import net.minecraft.nbt.NbtElement; 8 8 import net.minecraft.nbt.NbtList; 9 - import org.apache.logging.log4j.LogManager; 10 9 11 10 import java.io.File; 12 11 import java.io.IOException; ··· 66 65 Files.createDirectories(path); 67 66 } 68 67 69 - Files.walk(modContainer.getRootPaths().get(0).resolve("config")).forEach(p -> { 68 + Files.walk(modContainer.getRootPaths().getFirst().resolve("config")).forEach(p -> { 70 69 boolean bl = registerConfig(p); 71 70 if (bl && p.toString().contains("evicted_files.json")) bl2.set(true); 72 71 }); ··· 76 75 if (bl2.get()) evictOldFiles(); 77 76 } 78 77 public static void evictOldFiles() { 79 - LogManager.getLogger().info("1"); 80 78 NbtCompound c = CommonIO.read("config/infinity/util/evicted_files.json"); 81 79 NbtList l = c.getList("content", NbtElement.STRING_TYPE); 82 80 try { 83 81 for (NbtElement e : l) { 84 82 Path path1 = Paths.get("config/infinity/" + e.asString()); 85 - LogManager.getLogger().info("path1"); 86 83 if (path1.toFile().exists()) { 87 84 Path path2 = Paths.get("config/infinity/evicted/" + e.asString()); 88 85 Files.createDirectories(path2);
-43
src/main/java/net/lerariemann/infinity/util/RandomLootDrops.java
··· 1 - package net.lerariemann.infinity.util; 2 - 3 - import com.google.gson.JsonElement; 4 - import net.lerariemann.infinity.InfinityMod; 5 - import net.minecraft.loot.LootDataType; 6 - import net.minecraft.server.MinecraftServer; 7 - import net.minecraft.util.Identifier; 8 - import net.minecraft.util.WorldSavePath; 9 - 10 - import java.io.IOException; 11 - import java.nio.charset.StandardCharsets; 12 - import java.nio.file.Files; 13 - import java.nio.file.Paths; 14 - import java.util.Collections; 15 - import java.util.List; 16 - import java.util.Random; 17 - import java.util.stream.IntStream; 18 - 19 - public class RandomLootDrops { 20 - public static void genAll(int seed, MinecraftServer s) { 21 - List<Identifier> a = s.getLootManager().getIds(LootDataType.LOOT_TABLES).stream().toList(); 22 - List<Integer> l = new java.util.ArrayList<>(IntStream.rangeClosed(0, a.size() - 1).boxed().toList()); 23 - Collections.shuffle(l, new Random(seed)); 24 - for (int i = 0; i < a.size(); i++) { 25 - try { 26 - gen(s, a.get(i), a.get(l.get(i))); 27 - } catch (IOException e) { 28 - throw new RuntimeException(e); 29 - } 30 - } 31 - } 32 - 33 - static void gen(MinecraftServer s, Identifier dataFrom, Identifier nameFrom) throws IOException { 34 - JsonElement e = LootDataType.LOOT_TABLES.getGson().toJsonTree(s.getLootManager().getLootTable(dataFrom)); 35 - int i = nameFrom.getPath().lastIndexOf("/"); 36 - String before = i < 0 ? "" : "/" + nameFrom.getPath().substring(0, i); 37 - String after = i < 0 ? nameFrom.getPath() : nameFrom.getPath().substring(i+1); 38 - String directory = s.getSavePath(WorldSavePath.DATAPACKS).toString() + "/" + InfinityMod.MOD_ID + 39 - "/data/" + nameFrom.getNamespace() + "/loot_tables" + before; 40 - Files.createDirectories(Paths.get(directory)); 41 - Files.write(Paths.get(directory + "/" + after + ".json"), Collections.singletonList(e.toString()), StandardCharsets.UTF_8); 42 - } 43 - }
+4 -31
src/main/java/net/lerariemann/infinity/var/ModCommands.java
··· 11 11 import net.lerariemann.infinity.block.custom.NeitherPortalBlock; 12 12 import net.lerariemann.infinity.dimensions.RandomProvider; 13 13 import net.lerariemann.infinity.util.ConfigGenerator; 14 - import net.lerariemann.infinity.util.RandomLootDrops; 15 - import net.minecraft.command.CommandException; 16 14 import net.minecraft.command.argument.BlockPosArgumentType; 17 15 import net.minecraft.item.Item; 18 16 import net.minecraft.item.Items; ··· 25 23 import net.minecraft.server.command.ServerCommandSource; 26 24 import net.minecraft.server.network.ServerPlayerEntity; 27 25 import net.minecraft.server.world.ServerWorld; 28 - import net.minecraft.text.Text; 29 26 import net.minecraft.util.Identifier; 30 27 import net.minecraft.util.math.BlockPos; 31 28 import net.minecraft.world.World; ··· 37 34 public class ModCommands { 38 35 static void warpId(CommandContext<ServerCommandSource> context, long value) { 39 36 MinecraftServer s = context.getSource().getServer(); 40 - boolean bl = ((MinecraftServerAccess)(s)).getDimensionProvider().rule("runtimeGenerationEnabled"); 37 + boolean bl = ((MinecraftServerAccess)(s)).projectInfinity$getDimensionProvider().rule("runtimeGenerationEnabled"); 41 38 boolean bl2 = NeitherPortalBlock.addDimension(s, value, bl); 42 - if (!bl) throw new CommandException(Text.translatable("commands.warp.runtime_disabled")); 43 39 final ServerPlayerEntity self = context.getSource().getPlayer(); 44 - if (self == null) throw new CommandException(Text.translatable("commands.warp.not_a_player")); 45 40 if (bl2) self.increaseStat(ModStats.DIMS_OPENED_STAT, 1); 46 41 self.increaseStat(ModStats.PORTALS_OPENED_STAT, 1); 47 - ((ServerPlayerEntityAccess)(self)).setWarpTimer(20, value); 42 + ((ServerPlayerEntityAccess)(self)).projectInfinity$setWarpTimer(20, value); 48 43 } 49 44 50 45 public static boolean checkEnd(long d, MinecraftServer s) { ··· 52 47 } 53 48 54 49 public static Identifier getIdentifier(long d, MinecraftServer s) { 55 - String s1 = ((MinecraftServerAccess)s).getDimensionProvider().easterizer.keyOf(d); 50 + String s1 = ((MinecraftServerAccess)s).projectInfinity$getDimensionProvider().easterizer.keyOf(d); 56 51 return InfinityMod.getId(s1); 57 52 } 58 53 ··· 61 56 } 62 57 63 58 public static long getDimensionSeed(String text, MinecraftServer s) { 64 - return getDimensionSeed(text, ((MinecraftServerAccess)(s)).getDimensionProvider()); 65 - } 66 - public static long getDimensionSeed(NbtCompound compound, MinecraftServer s, Item item) { 67 - NbtList pages = compound.getList("pages", NbtElement.STRING_TYPE); 68 - if (pages.isEmpty()) { 69 - return getDimensionSeed("empty", ((MinecraftServerAccess)(s)).getDimensionProvider()); 70 - } 71 - else if (item == Items.WRITTEN_BOOK) { 72 - String pagesString = pages.get(0).asString(); 73 - String parsedString = pagesString.substring(pagesString.indexOf(':')+2, pagesString.length()-2); 74 - return getDimensionSeed(parsedString, ((MinecraftServerAccess)(s)).getDimensionProvider()); 75 - } 76 - else { 77 - String pagesString = pages.get(0).asString(); 78 - return getDimensionSeed(pagesString, ((MinecraftServerAccess)(s)).getDimensionProvider()); 79 - } 59 + return getDimensionSeed(text, ((MinecraftServerAccess)(s)).projectInfinity$getDimensionProvider()); 80 60 } 81 61 82 62 public static long getDimensionSeed(String text, RandomProvider prov) { ··· 109 89 ConfigGenerator.generateAll(w, bp1, bp2); 110 90 return 1; 111 91 }))))); 112 - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("generate_loot") 113 - .requires(source -> source.hasPermissionLevel(2)) 114 - .then(argument("seed", IntegerArgumentType.integer()).executes(context -> { 115 - final int seed = IntegerArgumentType.getInteger(context, "seed"); 116 - RandomLootDrops.genAll(seed, context.getSource().getServer()); 117 - return 1; 118 - })))); //experimental command, will likely get separated into its own mod 119 92 } 120 93 }
+34 -82
src/main/java/net/lerariemann/infinity/var/ModCriteria.java
··· 1 1 package net.lerariemann.infinity.var; 2 2 3 - import com.google.gson.JsonObject; 4 - import com.google.gson.JsonPrimitive; 3 + import com.mojang.serialization.Codec; 4 + import com.mojang.serialization.codecs.RecordCodecBuilder; 5 5 import net.lerariemann.infinity.InfinityMod; 6 6 import net.minecraft.advancement.criterion.AbstractCriterion; 7 - import net.minecraft.advancement.criterion.AbstractCriterionConditions; 8 - import net.minecraft.advancement.criterion.Criteria; 9 - import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; 10 - import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer; 7 + import net.minecraft.predicate.entity.EntityPredicate; 11 8 import net.minecraft.predicate.entity.LootContextPredicate; 9 + import net.minecraft.registry.Registries; 10 + import net.minecraft.registry.Registry; 12 11 import net.minecraft.server.network.ServerPlayerEntity; 13 - import net.minecraft.util.Identifier; 12 + 13 + import java.util.Optional; 14 14 15 15 public class ModCriteria { 16 16 public static class DimensionOpenedCriterion extends AbstractCriterion<ScoredConditions> { 17 - static final Identifier ID = InfinityMod.getId("dims_open"); 18 - 19 - public DimensionOpenedCriterion() { 20 - super(); 21 - } 22 - 23 - public Identifier getId() { 24 - return ID; 25 - } 26 - 27 17 @Override 28 - public ScoredConditions conditionsFromJson(JsonObject jsonObject, LootContextPredicate lootContextPredicate, AdvancementEntityPredicateDeserializer advancementEntityPredicateDeserializer) { 29 - int score = jsonObject.getAsJsonPrimitive("amount").getAsInt(); 30 - return new ScoredConditions(lootContextPredicate, score, getId()); 18 + public Codec<ScoredConditions> getConditionsCodec() { 19 + return ScoredConditions.CODEC; 31 20 } 32 21 33 22 public void trigger(ServerPlayerEntity player) { ··· 36 25 } 37 26 38 27 public static class DimensionClosedCriterion extends AbstractCriterion<ScoredConditions> { 39 - static final Identifier ID = InfinityMod.getId("dims_closed"); 40 - 41 - public DimensionClosedCriterion() { 42 - super(); 43 - } 44 - 45 - public Identifier getId() { 46 - return ID; 47 - } 48 - 49 28 @Override 50 - public ScoredConditions conditionsFromJson(JsonObject jsonObject, LootContextPredicate lootContextPredicate, AdvancementEntityPredicateDeserializer advancementEntityPredicateDeserializer) { 51 - int score = jsonObject.getAsJsonPrimitive("amount").getAsInt(); 52 - return new ScoredConditions(lootContextPredicate, score, getId()); 29 + public Codec<ScoredConditions> getConditionsCodec() { 30 + return ScoredConditions.CODEC; 53 31 } 54 32 55 33 public void trigger(ServerPlayerEntity player) { ··· 57 35 } 58 36 } 59 37 60 - 61 38 public static class WhoRemainsCriterion extends AbstractCriterion<EmptyConditions> { 62 - static final Identifier ID = InfinityMod.getId("who_remains"); 63 - 64 - public WhoRemainsCriterion() { 65 - super(); 66 - } 67 - 68 - public Identifier getId() { 69 - return ID; 70 - } 71 - 72 - @Override 73 - public EmptyConditions conditionsFromJson(JsonObject jsonObject, LootContextPredicate lootContextPredicate, AdvancementEntityPredicateDeserializer advancementEntityPredicateDeserializer) { 74 - return new EmptyConditions(lootContextPredicate, ID); 75 - } 76 - 77 39 public void trigger(ServerPlayerEntity player) { 78 40 this.trigger(player, (conditions) -> true); 79 41 } 80 - } 81 42 82 - public static class EmptyConditions extends AbstractCriterionConditions { 83 - 84 - public EmptyConditions(LootContextPredicate player, Identifier ID) { 85 - super(ID, player); 43 + @Override 44 + public Codec<EmptyConditions> getConditionsCodec() { 45 + return EmptyConditions.CODEC; 86 46 } 47 + } 87 48 88 - public static EmptyConditions create(Identifier ID) { 89 - return new EmptyConditions(LootContextPredicate.EMPTY, ID); 90 - } 91 - 92 - public JsonObject toJson(AdvancementEntityPredicateSerializer predicateSerializer) { 93 - return super.toJson(predicateSerializer); 94 - } 49 + public record EmptyConditions(Optional<LootContextPredicate> player) implements AbstractCriterion.Conditions { 50 + public static final Codec<EmptyConditions> CODEC = RecordCodecBuilder.create( 51 + instance -> instance.group( 52 + EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(EmptyConditions::player) 53 + ) 54 + .apply(instance, EmptyConditions::new) 55 + ); 95 56 } 96 57 97 - public static class ScoredConditions extends AbstractCriterionConditions { 98 - private final int score; 99 - 100 - public ScoredConditions(LootContextPredicate player, int score, Identifier ID) { 101 - super(ID, player); 102 - this.score = score; 103 - } 58 + public record ScoredConditions(Optional<LootContextPredicate> player, int score) implements AbstractCriterion.Conditions { 59 + public static final Codec<ScoredConditions> CODEC = RecordCodecBuilder.create( 60 + instance -> instance.group( 61 + EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(ScoredConditions::player), 62 + Codec.INT.fieldOf("amount").forGetter(ScoredConditions::score) 63 + ) 64 + .apply(instance, ScoredConditions::new) 65 + ); 104 66 105 67 public boolean test(int stat) { 106 68 return stat >= this.score; 107 69 } 108 - 109 - public static ScoredConditions create(int i, Identifier ID) { 110 - return new ScoredConditions(LootContextPredicate.EMPTY, i, ID); 111 - } 112 - 113 - public JsonObject toJson(AdvancementEntityPredicateSerializer predicateSerializer) { 114 - JsonObject jsonObject = super.toJson(predicateSerializer); 115 - jsonObject.add("amount", new JsonPrimitive(this.score)); 116 - return jsonObject; 117 - } 118 70 } 119 71 120 72 public static DimensionOpenedCriterion DIMS_OPENED; 121 73 public static DimensionClosedCriterion DIMS_CLOSED; 122 - public static WhoRemainsCriterion HE_WHO_REMAINS; 74 + public static WhoRemainsCriterion WHO_REMAINS; 123 75 124 76 public static void registerCriteria() { 125 - DIMS_OPENED = Criteria.register(new DimensionOpenedCriterion()); 126 - DIMS_CLOSED = Criteria.register(new DimensionClosedCriterion()); 127 - HE_WHO_REMAINS = Criteria.register(new WhoRemainsCriterion()); 77 + DIMS_OPENED = Registry.register(Registries.CRITERION, InfinityMod.getId("dims_open"), new DimensionOpenedCriterion()); 78 + DIMS_CLOSED = Registry.register(Registries.CRITERION, InfinityMod.getId("dims_closed"), new DimensionClosedCriterion()); 79 + WHO_REMAINS = Registry.register(Registries.CRITERION, InfinityMod.getId("who_remains"), new WhoRemainsCriterion()); 128 80 } 129 81 }
+7 -5
src/main/java/net/lerariemann/infinity/var/ModDensityFunctionTypes.java
··· 11 11 import net.minecraft.util.math.random.CheckedRandom; 12 12 import net.minecraft.world.gen.densityfunction.DensityFunction; 13 13 14 + import java.util.Arrays; 15 + 14 16 public class ModDensityFunctionTypes { 15 17 interface Nonbinary extends DensityFunction { 16 18 DensityFunction input(); ··· 85 87 } 86 88 87 89 record Coordinate(double scale, int axis) implements DensityFunction.Base { 88 - public static final CodecHolder<Coordinate> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 90 + public static final CodecHolder<Coordinate> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 89 91 Codec.DOUBLE.fieldOf("scale").orElse(1.0).forGetter(a -> a.scale), 90 92 Codec.INT.fieldOf("axis").forGetter(a -> a.axis)).apply( 91 93 instance, Coordinate::new))); ··· 130 132 } 131 133 132 134 record Menger(double scale, int max_y) implements DensityFunction.Base { 133 - public static final CodecHolder<Menger> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 135 + public static final CodecHolder<Menger> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 134 136 Codec.DOUBLE.fieldOf("scale").orElse(1.0).forGetter(a -> a.scale), 135 137 Codec.INT.fieldOf("max_y").orElse(0).forGetter(a -> a.max_y)).apply( 136 138 instance, Menger::new))); ··· 171 173 } 172 174 173 175 record Skygrid(double scale, int size, int separation) implements DensityFunction.Base { 174 - public static final CodecHolder<Skygrid> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 176 + public static final CodecHolder<Skygrid> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 175 177 Codec.DOUBLE.fieldOf("scale").orElse(1.0).forGetter(a -> a.scale), 176 178 Codec.INT.fieldOf("size").orElse(1).forGetter(a -> a.size), 177 179 Codec.INT.fieldOf("separation").orElse(3).forGetter(a -> a.separation)).apply( ··· 266 268 267 269 static double[] gen(int octaves){ 268 270 double[] a = new double[octaves]; 269 - for (int i = 0; i < octaves; i++) a[i] = 1; 271 + Arrays.fill(a, 1); 270 272 return a; 271 273 } 272 274 273 275 public record Classic(int sealevel) implements DensityFunction.Base { 274 - public static final CodecHolder<Classic> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 276 + public static final CodecHolder<Classic> CODEC_HOLDER = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 275 277 Codec.INT.fieldOf("sealevel").orElse(64).forGetter(a -> a.sealevel)).apply( 276 278 instance, Classic::new))); 277 279
+3 -3
src/main/java/net/lerariemann/infinity/var/ModMaterialConditions.java
··· 14 14 public class ModMaterialConditions { 15 15 record LinearCondition(double k_x, double k_y, double k_z, double min, double max, int separation) implements MaterialRules.MaterialCondition 16 16 { 17 - static final CodecHolder<LinearCondition> CODEC = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 17 + static final CodecHolder<LinearCondition> CODEC = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 18 18 (Codec.DOUBLE.fieldOf("k_x").orElse(1.0).forGetter(a -> a.k_x)), 19 19 (Codec.DOUBLE.fieldOf("k_y").orElse(0.0).forGetter(a -> a.k_y)), 20 20 (Codec.DOUBLE.fieldOf("k_z").orElse(1.0).forGetter(a -> a.k_z)), ··· 53 53 54 54 record CheckerboardCondition(int size) implements MaterialRules.MaterialCondition 55 55 { 56 - static final CodecHolder<CheckerboardCondition> CODEC = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 56 + static final CodecHolder<CheckerboardCondition> CODEC = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 57 57 (Codec.INT.fieldOf("size").orElse(1).forGetter(a -> a.size)) 58 58 ).apply(instance, CheckerboardCondition::new))); 59 59 ··· 86 86 87 87 public record TextCondition(int font_size, int char_spacing, int line_spacing, int max_width, String text, Pair<Integer, Pair<List<List<Integer>>, List<List<Character>>>> data) implements MaterialRules.MaterialCondition 88 88 { 89 - static final CodecHolder<TextCondition> CODEC = CodecHolder.of(RecordCodecBuilder.create(instance -> instance.group( 89 + static final CodecHolder<TextCondition> CODEC = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group( 90 90 (Codec.INT.fieldOf("font_size").orElse(1).forGetter(a -> a.font_size)), 91 91 (Codec.INT.fieldOf("char_spacing").orElse(1).forGetter(a -> a.char_spacing)), 92 92 (Codec.INT.fieldOf("line_spacing").orElse(1).forGetter(a -> a.line_spacing)),
+1 -1
src/main/java/net/lerariemann/infinity/var/ModMaterialRules.java
··· 26 26 long seed = MathHelper.hashCode(i, j, k); 27 27 double d = (seed & 0xFFFL) / (double)0xFFFL; 28 28 d = d - Math.floor(d); 29 - BlockState st = Registries.BLOCK.get(new Identifier(RandomProvider.blockElementToName(w.getElement(d)))).getDefaultState(); 29 + BlockState st = Registries.BLOCK.get(Identifier.of(RandomProvider.blockElementToName(w.getElement(d)))).getDefaultState(); 30 30 if(st.contains(Properties.PERSISTENT)) st = st.with(Properties.PERSISTENT, Boolean.TRUE); 31 31 return st; 32 32 }
+104
src/main/java/net/lerariemann/infinity/var/ModPayloads.java
··· 1 + package net.lerariemann.infinity.var; 2 + 3 + import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; 4 + import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; 5 + import net.lerariemann.infinity.InfinityMod; 6 + import net.lerariemann.infinity.access.InfinityOptionsAccess; 7 + import net.lerariemann.infinity.access.WorldRendererAccess; 8 + import net.lerariemann.infinity.loading.DimensionGrabber; 9 + import net.lerariemann.infinity.options.InfinityOptions; 10 + import net.lerariemann.infinity.options.ShaderLoader; 11 + import net.lerariemann.infinity.util.CommonIO; 12 + import net.minecraft.client.MinecraftClient; 13 + import net.minecraft.nbt.NbtCompound; 14 + import net.minecraft.nbt.NbtElement; 15 + import net.minecraft.nbt.NbtList; 16 + import net.minecraft.network.RegistryByteBuf; 17 + import net.minecraft.network.codec.PacketCodec; 18 + import net.minecraft.network.codec.PacketCodecs; 19 + import net.minecraft.network.packet.CustomPayload; 20 + import net.minecraft.server.world.ServerWorld; 21 + import net.minecraft.util.Identifier; 22 + 23 + import java.util.ArrayList; 24 + import java.util.List; 25 + 26 + public class ModPayloads { 27 + public record WorldAddPayload(Identifier world_id, NbtCompound optiondata) implements CustomPayload { 28 + public static final CustomPayload.Id<WorldAddPayload> ID = new CustomPayload.Id<>(InfinityMod.getId("reload_worlds")); 29 + public static final PacketCodec<RegistryByteBuf, WorldAddPayload> CODEC = PacketCodec.tuple( 30 + Identifier.PACKET_CODEC, WorldAddPayload::world_id, 31 + PacketCodecs.NBT_COMPOUND, WorldAddPayload::optiondata, 32 + WorldAddPayload::new); 33 + @Override 34 + public CustomPayload.Id<? extends CustomPayload> getId() { 35 + return ID; 36 + } 37 + } 38 + public static void addWorld(WorldAddPayload payload, ClientPlayNetworking.Context context) { 39 + Identifier id = payload.world_id; 40 + NbtCompound optiondata = payload.optiondata; 41 + NbtCompound dimdata = optiondata.getCompound("dimdata"); 42 + NbtList biomeslist = optiondata.getList("biomes", NbtElement.COMPOUND_TYPE); 43 + List<Identifier> biomeids = new ArrayList<>(); 44 + List<NbtCompound> biomes = new ArrayList<>(); 45 + for (NbtElement e: biomeslist) if (e instanceof NbtCompound biome) { 46 + biomeids.add(InfinityMod.getId(biome.getString("id"))); 47 + biomes.add(biome.getCompound("data")); 48 + } 49 + context.client().execute(() -> (new DimensionGrabber(context.client().getNetworkHandler().getRegistryManager())).grab_for_client(id, dimdata, biomeids, biomes)); 50 + } 51 + 52 + public record ShaderRePayload(NbtCompound shader_data) implements CustomPayload { 53 + public static final CustomPayload.Id<ShaderRePayload> ID = new CustomPayload.Id<>(InfinityMod.getId("reload_shader")); 54 + public static final PacketCodec<RegistryByteBuf, ShaderRePayload> CODEC = PacketCodec.tuple( 55 + PacketCodecs.NBT_COMPOUND, ShaderRePayload::shader_data, 56 + ShaderRePayload::new); 57 + @Override 58 + public CustomPayload.Id<? extends CustomPayload> getId() { 59 + return ID; 60 + } 61 + } 62 + public static void receiveShader(ShaderRePayload payload, ClientPlayNetworking.Context context) { 63 + InfinityOptions options = new InfinityOptions(payload.shader_data); 64 + MinecraftClient client = context.client(); 65 + ((InfinityOptionsAccess)client).projectInfinity$setInfinityOptions(options); 66 + NbtCompound shader = options.getShader(); 67 + boolean bl = shader.isEmpty(); 68 + if (bl) client.execute(() -> ShaderLoader.reloadShaders(client, false)); 69 + else { 70 + client.execute(() -> { 71 + CommonIO.write(shader, ShaderLoader.shaderDir(client), ShaderLoader.FILENAME); 72 + ShaderLoader.reloadShaders(client, true); 73 + }); 74 + } 75 + } 76 + 77 + public record StarsRePayLoad() implements CustomPayload { 78 + public static final StarsRePayLoad INSTANCE = new StarsRePayLoad(); 79 + public static final CustomPayload.Id<StarsRePayLoad> ID = new CustomPayload.Id<>(InfinityMod.getId("reload_stars")); 80 + public static final PacketCodec<RegistryByteBuf, StarsRePayLoad> CODEC = PacketCodec.unit(INSTANCE); 81 + @Override 82 + public CustomPayload.Id<? extends CustomPayload> getId() { 83 + return ID; 84 + } 85 + } 86 + public static void receiveStars(StarsRePayLoad payload, ClientPlayNetworking.Context context) { 87 + ((WorldRendererAccess)(context.client().worldRenderer)).projectInfinity$setNeedsStars(true); 88 + } 89 + 90 + public static ShaderRePayload setShaderFromWorld(ServerWorld destination) { 91 + return new ShaderRePayload(((InfinityOptionsAccess)(destination)).projectInfinity$getInfinityOptions().data()); 92 + } 93 + 94 + public static void registerPayloadsServer() { 95 + PayloadTypeRegistry.playS2C().register(WorldAddPayload.ID, WorldAddPayload.CODEC); 96 + PayloadTypeRegistry.playS2C().register(ShaderRePayload.ID, ShaderRePayload.CODEC); 97 + PayloadTypeRegistry.playS2C().register(StarsRePayLoad.ID, StarsRePayLoad.CODEC); 98 + } 99 + public static void registerPayloadsClient() { 100 + ClientPlayNetworking.registerGlobalReceiver(ModPayloads.WorldAddPayload.ID, ModPayloads::addWorld); 101 + ClientPlayNetworking.registerGlobalReceiver(ModPayloads.ShaderRePayload.ID, ModPayloads::receiveShader); 102 + ClientPlayNetworking.registerGlobalReceiver(ModPayloads.StarsRePayLoad.ID, ModPayloads::receiveStars); 103 + } 104 + }
+4 -4
src/main/java/net/lerariemann/infinity/var/ModPlacementModifiers.java
··· 1 1 package net.lerariemann.infinity.var; 2 2 3 - import com.mojang.serialization.Codec; 3 + import com.mojang.serialization.MapCodec; 4 4 import net.lerariemann.infinity.InfinityMod; 5 5 import net.minecraft.registry.Registries; 6 6 import net.minecraft.registry.Registry; ··· 14 14 15 15 public class ModPlacementModifiers { 16 16 public static class CenterProximityPlacementModifier extends AbstractConditionalPlacementModifier { 17 - public static final Codec<CenterProximityPlacementModifier> MODIFIER_CODEC = (Codecs.POSITIVE_INT.fieldOf("radius")).xmap( 18 - CenterProximityPlacementModifier::new, a -> a.radius).codec(); 17 + public static final MapCodec<CenterProximityPlacementModifier> MODIFIER_CODEC = (Codecs.POSITIVE_INT.fieldOf("radius")).xmap( 18 + CenterProximityPlacementModifier::new, a -> a.radius); 19 19 private final int radius; 20 20 21 21 private CenterProximityPlacementModifier(int radius) { ··· 36 36 return PlacementModifierType.RARITY_FILTER; 37 37 } 38 38 } 39 - static <P extends PlacementModifier> PlacementModifierType<P> register(String id, Codec<P> codec) { 39 + static <P extends PlacementModifier> PlacementModifierType<P> register(String id, MapCodec<P> codec) { 40 40 return Registry.register(Registries.PLACEMENT_MODIFIER_TYPE, InfinityMod.getId(id), () -> codec); 41 41 } 42 42 public static void registerModifiers() {
+3 -2
src/main/java/net/lerariemann/infinity/var/ModSounds.java
··· 1 1 package net.lerariemann.infinity.var; 2 2 3 + import net.lerariemann.infinity.InfinityMod; 3 4 import net.minecraft.registry.Registries; 4 5 import net.minecraft.registry.Registry; 5 6 import net.minecraft.sound.SoundEvent; 6 7 import net.minecraft.util.Identifier; 7 8 8 9 public class ModSounds { 9 - public static final Identifier IVORY_MUSIC_HOPE = new Identifier("infinity:music.ivory.hope_instilled"); 10 - public static final Identifier IVORY_MUSIC_CHALLENGER = new Identifier("infinity:music.ivory.challenger"); 10 + public static final Identifier IVORY_MUSIC_HOPE = InfinityMod.getId("music.ivory.hope_instilled"); 11 + public static final Identifier IVORY_MUSIC_CHALLENGER = InfinityMod.getId("music.ivory.challenger"); 11 12 public static SoundEvent IVORY_MUSIC_HOPE_EVENT = SoundEvent.of(IVORY_MUSIC_HOPE); 12 13 public static SoundEvent IVORY_MUSIC_CHALLENGER_EVENT = SoundEvent.of(IVORY_MUSIC_CHALLENGER); 13 14
+2 -4
src/main/resources/data/infinity/dimension_type/default_type.json
··· 14 14 "logical_height": 256, 15 15 "monster_spawn_light_level": { 16 16 "type": "uniform", 17 - "value": { 18 - "min_inclusive": 0, 19 - "max_inclusive": 7 20 - } 17 + "min_inclusive": 0, 18 + "max_inclusive": 7 21 19 }, 22 20 "monster_spawn_block_light_limit": 0, 23 21 "infiniburn": "#infiniburn_overworld",
+2 -4
src/main/resources/data/infinity/dimension_type/library_type.json
··· 14 14 "logical_height": 96, 15 15 "monster_spawn_light_level": { 16 16 "type": "uniform", 17 - "value": { 18 - "min_inclusive": 0, 19 - "max_inclusive": 7 20 - } 17 + "min_inclusive": 0, 18 + "max_inclusive": 7 21 19 }, 22 20 "fixed_time": 6000, 23 21 "monster_spawn_block_light_limit": 0,
+2 -4
src/main/resources/data/infinity/dimension_type/sponge_type.json
··· 14 14 "logical_height": 256, 15 15 "monster_spawn_light_level": { 16 16 "type": "uniform", 17 - "value": { 18 - "min_inclusive": 0, 19 - "max_inclusive": 7 20 - } 17 + "min_inclusive": 0, 18 + "max_inclusive": 7 21 19 }, 22 20 "monster_spawn_block_light_limit": 0, 23 21 "infiniburn": "#infiniburn_overworld",
+3 -3
src/main/resources/fabric.mod.json
··· 3 3 "id": "infinity", 4 4 "version": "${version}", 5 5 6 - "name": "Infinite Dimensions 1.20.1", 6 + "name": "Infinite Dimensions 1.21.1", 7 7 "description": "Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.", 8 8 "authors": [ 9 9 "Lera Riemann" ··· 34 34 "depends": { 35 35 "fabricloader": ">=0.14.11", 36 36 "fabric-api": "*", 37 - "minecraft": "~1.20.1", 38 - "java": ">=17" 37 + "minecraft": "~1.21.1", 38 + "java": ">=21" 39 39 }, 40 40 "suggests": { 41 41 "another-mod": "*"
+2 -7
src/main/resources/infinity.mixins.json
··· 7 7 "AbstractFireBlockMixin", 8 8 "ChunkRegionMixin", 9 9 "CreeperEntityMixin", 10 - "EntityMixin", 11 10 "MaterialRuleContextAccess", 12 11 "MinecraftServerMixin", 13 12 "MobEntityMixin", 14 13 "NetherPortalBlockMixin", 15 - "PlayerEntityMixin", 14 + "NetherPortalMixin", 15 + "PointOfInterestTypesMixin", 16 16 "PortalForcerMixin", 17 17 "ServerPlayerEntityMixin", 18 18 "SlimeEntityMixin", 19 19 "WorldChunkMixin", 20 - "mavity.BoatEntityMixin", 21 - "mavity.LivingEntityMixin", 22 - "mavity.PersistentProjectileEntityMixin", 23 - "mavity.SeveralEntitiesMixin", 24 - "mavity.ThrownEntityMixin", 25 20 "mobs.EndermiteEntityMixin", 26 21 "mobs.WaterCreaturesMixin", 27 22 "mobs.passive.AnimalEntityMixin",