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

initial work backporting release 2.4

+231 -284
+1 -2
common/src/main/java/net/lerariemann/infinity/InfinityMod.java
··· 19 19 public class InfinityMod { 20 20 public static final String MOD_ID = "infinity"; 21 21 public static final Logger LOGGER = LoggerFactory.getLogger("Infinite Dimensions"); 22 - public static Path configPath = PlatformMethods.getConfigPath() 22 + public static Path configPath = PlatformMethods.getConfigPath(); 23 23 public static Path utilPath = configPath.resolve(".util"); 24 24 public static Path invocationLock = configPath.resolve("modular/invocation.lock"); 25 25 ··· 38 38 rootConfigPathInJar = PlatformMethods.getRootConfigPath(); 39 39 ConfigManager.updateInvocationLock(); 40 40 ConfigManager.unpackDefaultConfigs(); 41 - ModComponentTypes.registerComponentTypes(); 42 41 ModStatusEffects.registerModEffects(); 43 42 ModItemFunctions.registerItemFunctions(); 44 43 ModEntities.registerEntities();
+2 -19
common/src/main/java/net/lerariemann/infinity/block/custom/AltarBlock.java
··· 3 3 import net.lerariemann.infinity.block.entity.BiomeBottleBlockEntity; 4 4 import net.lerariemann.infinity.registry.core.ModBlocks; 5 5 import net.lerariemann.infinity.registry.var.ModCriteria; 6 + import net.lerariemann.infinity.util.BackportMethods; 6 7 import net.lerariemann.infinity.util.var.BishopBattle; 7 8 import net.minecraft.block.*; 8 - import net.minecraft.component.ComponentChanges; 9 - import net.minecraft.component.DataComponentTypes; 10 - import net.minecraft.component.type.BlockStateComponent; 11 - import net.minecraft.component.type.CustomModelDataComponent; 12 9 import net.minecraft.entity.player.PlayerEntity; 13 10 import net.minecraft.item.DyeItem; 14 11 import net.minecraft.item.ItemStack; ··· 68 65 world.setBlockState(pos, state.with(COLOR, i)); 69 66 } 70 67 71 - public static ComponentChanges toComponentChanges(BlockState state) { 72 - int color = state.get(AltarBlock.COLOR); 73 - boolean flower = state.get(AltarBlock.FLOWER); 74 - if (color > 0 || flower) return ComponentChanges.builder().add(DataComponentTypes.BLOCK_STATE, 75 - new BlockStateComponent(Map.of()) 76 - .with(AltarBlock.COLOR, color) 77 - .with(AltarBlock.FLOWER, flower)) 78 - .add(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(color + 79 - (flower ? AltarBlock.numColors : 0))) 80 - .build(); 81 - return ComponentChanges.EMPTY; 82 - } 83 - 84 68 @Override 85 - public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) { 69 + public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { 86 70 ItemStack res = super.getPickStack(world, pos, state); 87 - res.applyChanges(toComponentChanges(state)); 88 71 return res; 89 72 } 90 73
+1 -1
common/src/main/java/net/lerariemann/infinity/block/custom/IridescentBlock.java
··· 43 43 } 44 44 45 45 @Override 46 - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { 46 + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { 47 47 if (player.getStackInHand(Hand.MAIN_HAND).isOf(ModItems.STAR_OF_LANG.get())) { 48 48 BlockState state1 = toStatic(state); 49 49 if (state1 != null) {
+2 -21
common/src/main/java/net/lerariemann/infinity/block/entity/ChromaticBlockEntity.java
··· 70 70 color = Color.HSBtoRGB(hue / 360f, saturation / 255f, brightness / 255f) & 0xFFFFFF; 71 71 } 72 72 73 - @Override 74 - protected void addComponents(ComponentMap.Builder componentMapBuilder) { 75 - super.addComponents(componentMapBuilder); 76 - componentMapBuilder.add(ModComponentTypes.COLOR.get(), color); 77 - } 78 - @Override 79 - protected void readComponents(BlockEntity.ComponentsAccess components) { 80 - super.readComponents(components); 81 - setColor(components.getOrDefault(ModComponentTypes.COLOR.get(), 0xFFFFFF)); 82 - } 83 - 84 - public static ComponentMap asMap(int i) { 85 - return ComponentMap.builder() 86 - .add(ModComponentTypes.COLOR.get(), i) 87 - .build(); 88 - } 89 - public ComponentMap asMap() { 90 - return asMap(getTint()); 91 - } 92 73 public short offset(short orig, short amount, AtomicBoolean cancel) { 93 74 if (amount < 0 ? orig == 0 : orig == 255) { 94 75 cancel.set(true); ··· 158 139 159 140 @Override 160 141 public void readNbt(NbtCompound nbt) { 161 - super.readNbt(nbt, registryLookup); 142 + super.readNbt(nbt); 162 143 if (nbt.contains("color", NbtElement.INT_TYPE)) 163 144 setColor(nbt.getInt("color")); 164 145 else if (nbt.contains("color", NbtElement.COMPOUND_TYPE)) { ··· 171 152 } 172 153 @Override 173 154 protected void writeNbt(NbtCompound nbt) { 174 - super.writeNbt(nbt, registryLookup); 155 + super.writeNbt(nbt); 175 156 NbtCompound color = new NbtCompound(); 176 157 color.putShort("h", hue); 177 158 color.putShort("s", saturation);
+3 -2
common/src/main/java/net/lerariemann/infinity/compat/emi/ChromaticEmiRecipe.java
··· 37 37 38 38 @Override 39 39 public void addWidgets(WidgetHolder widgets) { 40 - widgets.addSlot(inputs.getFirst(), 0, 0); 40 + widgets.addSlot(inputs.get(0), 0, 0); 41 41 MutableText text = Text.translatable(Util.createTranslationKey("chromatic", this.id)); 42 42 Map<Integer, MutableText> chars = new HashMap<>(); 43 43 text.asOrderedText().accept((index, style, codepoint) -> { ··· 49 49 for (int i = 0; i < len; i++) { 50 50 MutableText ch = chars.get(i); 51 51 if (ch == null) continue; 52 - finalText.append(ch.withColor(getCharColor(i, len))); 52 + var chStyle = ch.setStyle(Style.EMPTY.withColor(getCharColor(i, len))); 53 + finalText.append(chStyle); 53 54 } 54 55 if (infoId != null) 55 56 widgets.add(new TextWidgetWithTooltip(Text.literal("ℹ").formatted(Formatting.GRAY)
-3
common/src/main/java/net/lerariemann/infinity/compat/emi/EmiCompat.java
··· 16 16 import net.lerariemann.infinity.util.InfinityMethods; 17 17 import net.lerariemann.infinity.util.PlatformMethods; 18 18 import net.minecraft.client.MinecraftClient; 19 - import net.minecraft.component.DataComponentTypes; 20 - import net.minecraft.component.type.PotionContentsComponent; 21 19 import net.minecraft.item.ItemStack; 22 20 import net.minecraft.item.Items; 23 21 import net.minecraft.potion.Potions; 24 22 import net.minecraft.recipe.Ingredient; 25 - import net.minecraft.recipe.RecipeEntry; 26 23 import net.minecraft.recipe.RecipeManager; 27 24 import net.minecraft.registry.DynamicRegistryManager; 28 25 import net.minecraft.util.Identifier;
+4 -5
common/src/main/java/net/lerariemann/infinity/compat/emi/IridesenceCraftingEmiRecipe.java
··· 9 9 import net.minecraft.registry.DynamicRegistryManager; 10 10 11 11 public class IridesenceCraftingEmiRecipe extends BasicEmiRecipe { 12 - public IridesenceCraftingEmiRecipe(RecipeEntry<CollisionCraftingRecipe> recipeEntry, DynamicRegistryManager registryManager) { 13 - super(EmiCompat.IRIDESCENCE_CRAFTING, recipeEntry.id(), 118, 18); 14 - CollisionCraftingRecipe recipe = recipeEntry.value(); 15 - this.inputs.add(EmiIngredient.of(recipe.getInput())); 16 - this.outputs.add(EmiStack.of(recipe.getOutput(registryManager))); 12 + public IridesenceCraftingEmiRecipe(CollisionCraftingRecipe recipeEntry, DynamicRegistryManager registryManager) { 13 + super(EmiCompat.IRIDESCENCE_CRAFTING, recipeEntry.getId(), 118, 18); 14 + this.inputs.add(EmiIngredient.of(recipeEntry.getInput())); 15 + this.outputs.add(EmiStack.of(recipeEntry.getOutput(registryManager))); 17 16 } 18 17 19 18 @Override
+1
common/src/main/java/net/lerariemann/infinity/entity/custom/AbstractChessFigure.java
··· 11 11 import net.minecraft.nbt.NbtCompound; 12 12 import net.minecraft.predicate.entity.EntityPredicates; 13 13 import net.minecraft.registry.tag.FluidTags; 14 + import net.minecraft.scoreboard.AbstractTeam; 14 15 import net.minecraft.scoreboard.Team; 15 16 import net.minecraft.server.world.ServerWorld; 16 17 import net.minecraft.sound.SoundEvent;
+2 -2
common/src/main/java/net/lerariemann/infinity/entity/custom/AntEntity.java
··· 135 135 } 136 136 137 137 @Override 138 - public boolean canBeLeashed() { 138 + public boolean canBeLeashedBy(PlayerEntity player) { 139 139 return !isInBattle(); 140 140 } 141 + 141 142 @Override 142 143 public boolean canWalkOnFluid(FluidState state) { 143 144 return state.isIn(FluidTags.WATER); ··· 165 166 @Override 166 167 public ActionResult interactMob(PlayerEntity player, Hand hand) { 167 168 if (!this.hasPassengers() 168 - && this.getAttributeValue(EntityAttributes.GENERIC_SCALE) > 2 169 169 && player.getStackInHand(hand).isEmpty()) { 170 170 this.putPlayerOnBack(player); 171 171 return ActionResult.success(this.getWorld().isClient);
+3 -4
common/src/main/java/net/lerariemann/infinity/entity/custom/BishopEntity.java
··· 46 46 47 47 @Nullable 48 48 @Override 49 - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData) { 50 - entityData = super.initialize(world, difficulty, spawnReason, entityData); 49 + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt) { 50 + entityData = super.initialize(world, difficulty, spawnReason, entityData, entityNbt); 51 51 updateAttackType(); 52 52 return entityData; 53 53 } ··· 160 160 } 161 161 162 162 @Override 163 - public void shootAt(LivingEntity target, float pullProgress) { 163 + public void attack(LivingEntity target, float pullProgress) { 164 164 ItemStack bow = Items.BOW.getDefaultStack(); 165 165 PersistentProjectileEntity persistentProjectileEntity = 166 166 ProjectileUtil.createArrowProjectile(this, getProjectileType(), pullProgress, bow); ··· 184 184 || effect.getBoolean("Instant")) return Items.ARROW.getDefaultStack(); 185 185 return ChaosSkeleton.setPotion(Items.TIPPED_ARROW.getDefaultStack(), 186 186 effect.getInt("Color"), 187 - effect.getString("Name"), 188 187 200); 189 188 } 190 189 }
+2 -2
common/src/main/java/net/lerariemann/infinity/entity/custom/BishopNodeMaker.java
··· 13 13 public int getSuccessors(PathNode[] successors, PathNode node) { 14 14 int i = 0; 15 15 int j = 0; 16 - PathNodeType pathNodeType = this.getNodeType(node.x, node.y + 1, node.z); 17 - PathNodeType pathNodeType2 = this.getNodeType(node.x, node.y, node.z); 16 + PathNodeType pathNodeType = this.getNodeType(this.entity, node.x, node.y + 1, node.z); 17 + PathNodeType pathNodeType2 = this.getNodeType(this.entity, node.x, node.y, node.z); 18 18 if (this.entity.getPathfindingPenalty(pathNodeType) >= 0.0F && pathNodeType2 != PathNodeType.STICKY_HONEY) { 19 19 j = MathHelper.floor(Math.max(1.0F, this.entity.getStepHeight())); 20 20 }
+2 -3
common/src/main/java/net/lerariemann/infinity/entity/custom/ChaosPawn.java
··· 148 148 149 149 @Override 150 150 @Nullable 151 - public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData) { 152 - initFromBlock(world.getBlockState(this.getBlockPos().down())); 151 + public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable NbtCompound entityNbt) { initFromBlock(world.getBlockState(this.getBlockPos().down())); 153 152 double i = random.nextDouble() * 40; 154 153 Objects.requireNonNull(this.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH)).setBaseValue(i); 155 154 this.setHealth((float)i); ··· 157 156 if ((a = (int)(0.1*i)) > 0) { 158 157 this.equipLootStack( 159 158 EquipmentSlot.HEAD, 160 - Registries.ITEM.get(new Identifier(InfinityMod.provider.randomName(r, "items"))).getDefaultStack().copyWithCount(a)); 159 + Registries.ITEM.get(new Identifier(InfinityMod.provider.randomName(i, "items"))).getDefaultStack().copyWithCount(a)); 161 160 ((MobEntityAccess)this).infinity$setPersistent(false); 162 161 } 163 162 return super.initialize(world, difficulty, spawnReason, entityData, entityNbt);
+8 -4
common/src/main/java/net/lerariemann/infinity/entity/custom/ChaosSkeleton.java
··· 21 21 import net.minecraft.potion.PotionUtil; 22 22 import net.minecraft.potion.Potions; 23 23 import net.minecraft.registry.Registries; 24 - import net.minecraft.registry.RegistryKeys; 25 - import net.minecraft.registry.entry.RegistryEntry; 26 24 import net.minecraft.server.world.ServerWorld; 27 25 import net.minecraft.sound.SoundEvents; 28 26 import net.minecraft.text.Style; ··· 34 32 import net.minecraft.world.ServerWorldAccess; 35 33 import net.minecraft.world.World; 36 34 import org.jetbrains.annotations.Nullable; 35 + import org.joml.Vector3f; 37 36 38 37 import java.util.*; 39 38 ··· 130 129 } 131 130 } 132 131 if (itemStack.isOf(Items.GLASS_BOTTLE)) { 133 - ItemStack itemStack2 = setPotion(Items.POTION.getDefaultStack(), this.getColorForRender(), this.getEffect(), this.getDuration() * 20); 132 + ItemStack itemStack2 = setPotion(Items.POTION.getDefaultStack(), this.getEffectRawId(), this.getDuration() * 20); 134 133 ItemStack itemStack3 = ItemUsage.exchangeStack(itemStack, player, itemStack2, false); 135 134 player.setStackInHand(hand, itemStack3); 136 135 this.playSound(SoundEvents.ITEM_BOTTLE_FILL, 1.0f, 1.0f); ··· 160 159 public String getEffect() { 161 160 return this.dataTracker.get(effect); 162 161 } 162 + 163 + public int getEffectRawId() { 164 + return reg.getRawId(getEffect()); 165 + } 166 + 163 167 @Override 164 - public int getColor() { 168 + public int getColorRaw() { 165 169 return this.dataTracker.get(color); 166 170 } 167 171
+5 -3
common/src/main/java/net/lerariemann/infinity/entity/custom/ChaosSlime.java
··· 83 83 this.dataTracker.set(color, c); 84 84 } 85 85 @Override 86 - public int getColor() { 86 + public Vector3f getColor() { 87 87 return this.dataTracker.get(color); 88 88 } 89 89 ··· 99 99 100 100 @Override 101 101 protected ParticleEffect getParticles() { 102 - return new DustParticleEffect(particleColorFromInt(this.getColorForRender()), 1.0f); 102 + return new DustParticleEffect(particleColorFromInt(this.getColorRaw()), 1.0f); 103 103 } 104 104 @Override 105 105 protected SoundEvent getHurtSound(DamageSource source) { ··· 125 125 @Override 126 126 public void writeCustomDataToNbt(NbtCompound nbt) { 127 127 super.writeCustomDataToNbt(nbt); 128 - nbt.putInt("color", getColor()); 128 + nbt.putFloat("red", this.dataTracker.get(color).x); 129 + nbt.putFloat("green", this.dataTracker.get(color).y); 130 + nbt.putFloat("blue", this.dataTracker.get(color).z); 129 131 nbt.putString("core", Registries.BLOCK.getId(this.getCore().getBlock()).toString()); 130 132 } 131 133
+13 -7
common/src/main/java/net/lerariemann/infinity/entity/custom/TintableEntity.java
··· 8 8 import java.awt.*; 9 9 10 10 public interface TintableEntity { 11 + boolean hasCustomName(); 12 + Text getName(); 13 + int getId(); 14 + int getAge(); 15 + 11 16 default Vector3f particleColorFromInt(int i) { 12 17 float f = (float)(i >> 16 & 0xFF) / 255.0f; 13 18 float g = (float)(i >> 8 & 0xFF) / 255.0f; 14 19 float h = (float)(i & 0xFF) / 255.0f; 15 20 return new Vector3f(f, g, h); 16 21 } 22 + 23 + 17 24 default Vector3f getColorNamed() { 18 25 if (hasCustomName()) { 19 26 String s = getName().getString(); ··· 34 41 int n = getAge() + getId(); 35 42 float hue = n / 400.f; 36 43 hue = hue - (int) hue; 37 - return colorFromInt(Color.getHSBColor(hue, 1.0f, 1.0f).getRGB()); 44 + return particleColorFromInt(Color.getHSBColor(hue, 1.0f, 1.0f).getRGB()); 38 45 } 39 46 } 40 47 return null; 41 48 } 42 49 43 - default int getColorForRender() { 44 - int v = getColorNamed(); 45 - if (v!=-1) return v; 46 - return ColorHelper.Argb.fullAlpha(this.getColor()); 50 + default Vector3f getColor() { 51 + Vector3f v = getColorNamed(); 52 + if (v!=null) return v; 53 + return particleColorFromInt(this.getColorRaw()); 47 54 } 48 - 49 - default int getColor() { 55 + default int getColorRaw() { 50 56 return 0; 51 57 } 52 58 default float getAlpha() {
+4 -6
common/src/main/java/net/lerariemann/infinity/iridescence/Iridescence.java
··· 115 115 DyeColor.PINK); 116 116 117 117 static Block getRandomColorBlock(WorldAccess world, String str) { 118 - return Registries.BLOCK.get(Identifier.of(dyeColors.get(world.getRandom().nextInt(dyeColors.size())).getName() + "_" + str)); 118 + return Registries.BLOCK.get(new Identifier(dyeColors.get(world.getRandom().nextInt(dyeColors.size())).getName() + "_" + str)); 119 119 } 120 120 static Block getRandomColorBlock(double d, String str) { 121 - return Registries.BLOCK.get(Identifier.of(dyeColors.get((int)(d* dyeColors.size())).getName() + "_" + str)); 121 + return Registries.BLOCK.get(new Identifier(dyeColors.get((int)(d* dyeColors.size())).getName() + "_" + str)); 122 122 } 123 123 124 124 int ticksInHour = 1200; ··· 131 131 } 132 132 return -1; 133 133 } 134 - 135 - int ticksInHour = 1200; 136 134 137 135 static int getFullEffectLength(int amplifier) { 138 136 return getOnsetLength() + getEffectLength(amplifier); ··· 205 203 static void tryBeginJourney(LivingEntity entity, int amplifier, boolean willingly) { 206 204 amplifier = Iridescence.getAmplifierOnApply(entity, amplifier); 207 205 if (amplifier >= 0) { 208 - entity.addStatusEffect(new StatusEffectInstance(ModStatusEffects.IRIDESCENT_EFFECT, 206 + entity.addStatusEffect(new StatusEffectInstance(ModStatusEffects.IRIDESCENT_EFFECT.value(), 209 207 Iridescence.getFullEffectLength(amplifier), 210 208 amplifier, true, true)); 211 209 entity.removeStatusEffect(ModStatusEffects.IRIDESCENT_COOLDOWN.value()); ··· 214 212 entity.addStatusEffect(new StatusEffectInstance(ModStatusEffects.IRIDESCENT_COOLDOWN.value(), 215 213 cooldownDuration, amplifier > 0 ? 1 : 0, true, false)); 216 214 if (entity instanceof ServerPlayerEntity player) { 217 - ModCriteria.IRIDESCENT.get().trigger(player, willingly, amplifier); 215 + ModCriteria.IRIDESCENT.trigger(player, willingly, amplifier); 218 216 } 219 217 } 220 218 }
+8 -5
common/src/main/java/net/lerariemann/infinity/iridescence/IridescenceLiquidBlock.java
··· 26 26 @Override 27 27 public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { 28 28 super.onEntityCollision(state, world, pos, entity); 29 - if (world.getFluidState(pos).getLevel() > 3 && world instanceof ServerWorld w) switch (entity) { 30 - case PlayerEntity player -> Iridescence.tryBeginJourney(player, 4, false); 31 - case MobEntity ent -> Iridescence.tryApplyEffect(ent); 32 - case ItemEntity item -> { 29 + if (world.getFluidState(pos).getLevel() > 3 && world instanceof ServerWorld w) { 30 + if (Objects.requireNonNull(entity) instanceof PlayerEntity player) { 31 + Iridescence.tryBeginJourney(player, 4, false); 32 + } else if (entity instanceof MobEntity ent) { 33 + Iridescence.tryApplyEffect(ent); 34 + } else if (entity instanceof ItemEntity item) { 33 35 if (!Iridescence.isIridescentItem(item.getStack()) && item.getOwner() instanceof LivingEntity le && 34 36 !Iridescence.getPhase(le).equals(Iridescence.Phase.INITIAL)) 35 37 ModItemFunctions.checkCollisionRecipes(w, item, ModItemFunctions.IRIDESCENCE_CRAFTING_TYPE.get(), 36 38 new NbtCompound()); 37 39 } 40 + } 38 41 } 39 - } 42 + }
+13 -23
common/src/main/java/net/lerariemann/infinity/iridescence/IridescentEffect.java
··· 11 11 import net.minecraft.entity.effect.StatusEffectInstance; 12 12 import net.minecraft.entity.mob.Angerable; 13 13 import net.minecraft.entity.mob.MobEntity; 14 + import net.minecraft.particle.ParticleEffect; 14 15 import net.minecraft.server.network.ServerPlayerEntity; 15 16 import net.minecraft.sound.SoundEvents; 16 17 import net.minecraft.util.Identifier; ··· 37 38 } 38 39 39 40 public void onRemoved(LivingEntity entity) { 40 - switch (entity) { 41 - case ServerPlayerEntity player -> { 42 - unloadShader(player); 43 - if (player.isInvulnerable()) endJourney(player, true, 0); 44 - } 45 - case ChaosPawn pawn -> { 46 - if (pawn.getRandom().nextBoolean()) { 47 - pawn.unchess(); 48 - pawn.playSound(SoundEvents.ENTITY_ZOMBIE_VILLAGER_CONVERTED, 1.0f, 1.0f); 49 - convTriggers(pawn); 50 - } 51 - } 52 - case MobEntity currEntity -> endConversion(currEntity); 53 - default -> { 41 + if (Objects.requireNonNull(entity) instanceof ServerPlayerEntity player) { 42 + unloadShader(player); 43 + if (player.isInvulnerable()) endJourney(player, true, 0); 44 + } else if (entity instanceof ChaosPawn pawn) { 45 + if (pawn.getRandom().nextBoolean()) { 46 + pawn.unchess(); 47 + pawn.playSound(SoundEvents.ENTITY_ZOMBIE_VILLAGER_CONVERTED, 1.0f, 1.0f); 48 + convTriggers(pawn); 54 49 } 50 + } else if (entity instanceof MobEntity currEntity) { 51 + endConversion(currEntity); 55 52 } else if (entity instanceof MobEntity currEntity) { 56 53 endConversion(currEntity); 57 54 } else if (entity instanceof MobEntity currEntity) { ··· 82 79 } 83 80 } 84 81 85 - @Override 86 - public ParticleEffect createParticle(StatusEffectInstance effect) { 87 - float hue = effect.getDuration() / 13.0f; 88 - return EntityEffectParticleEffect.create( 89 - ParticleTypes.ENTITY_EFFECT, ColorHelper.Argb.fullAlpha(Color.HSBtoRGB(hue - (int)hue, 1.0f, 1.0f))); 90 - } 91 - 92 82 public static class Setup extends InstantStatusEffect { 93 83 public Setup(StatusEffectCategory category, int color) { 94 84 super(category, color); 95 85 } 96 86 97 87 @Override 98 - public void onApplied(LivingEntity entity, int amplifier) { 99 - super.onApplied(entity, amplifier); 88 + public void onApplied(LivingEntity entity, AttributeContainer attributes, int amplifier) { 89 + super.onApplied(entity, attributes, amplifier); 100 90 tryBeginJourney(entity, amplifier, true); 101 91 } 102 92 }
+9 -7
common/src/main/java/net/lerariemann/infinity/item/ChromaticBlockItem.java
··· 4 4 import net.lerariemann.infinity.registry.core.ModComponentTypes; 5 5 import net.lerariemann.infinity.registry.core.ModItems; 6 6 import net.lerariemann.infinity.util.BackportMethods; 7 + import net.lerariemann.infinity.util.var.ColorLogic; 7 8 import net.minecraft.block.Block; 8 9 import net.minecraft.block.BlockState; 9 10 import net.minecraft.entity.player.PlayerEntity; 10 11 import net.minecraft.item.BlockItem; 11 12 import net.minecraft.item.ItemStack; 13 + import net.minecraft.text.Style; 14 + import net.minecraft.text.Text; 12 15 import net.minecraft.util.Hand; 13 16 import net.minecraft.util.math.BlockPos; 14 17 import net.minecraft.world.World; ··· 19 22 super(block, settings); 20 23 } 21 24 22 - @Override 23 - public ComponentChanges.Builder getPortalComponents(InfinityPortalBlockEntity ipbe) { 24 - return ComponentChanges.builder() 25 - .add(ModComponentTypes.COLOR.get(), ipbe.getPortalColor()); 26 - } 27 - 28 25 //todo: implement this properly 29 26 @Override 30 27 protected boolean postPlacement(BlockPos pos, World world, @Nullable PlayerEntity player, ItemStack stack, BlockState state) { ··· 32 29 if (player != null && player.getStackInHand(Hand.OFF_HAND) 33 30 .isOf(ModItems.CHROMATIC_MATTER.get()) 34 31 && world.getBlockEntity(pos) instanceof ChromaticBlockEntity cbe) { 35 - cbe.setColor(BackportMethods.getOrDefaultInt(stack, ModComponentTypes.COLOR, 0xFFFFFF)); 32 + cbe.setColor(BackportMethods.getOrDefaultInt(stack, ModComponentTypes.KEY_COLOR, 0xFFFFFF)); 36 33 } 37 34 return bl; 35 + } 36 + 37 + @Override 38 + public Text getName() { 39 + return Text.translatable(this.getTranslationKey()).setStyle(Style.EMPTY.withColor(ColorLogic.defaultChromatic)); 38 40 } 39 41 }
+19 -31
common/src/main/java/net/lerariemann/infinity/item/ChromaticItem.java
··· 2 2 3 3 import net.lerariemann.infinity.block.custom.AltarBlock; 4 4 import net.lerariemann.infinity.block.entity.ChromaticBlockEntity; 5 + import net.lerariemann.infinity.registry.core.ModBlocks; 5 6 import net.lerariemann.infinity.registry.core.ModComponentTypes; 7 + import net.lerariemann.infinity.registry.var.ModTags; 6 8 import net.lerariemann.infinity.util.BackportMethods; 7 9 import net.lerariemann.infinity.util.var.ColorLogic; 8 10 import net.minecraft.block.BlockState; ··· 11 13 import net.minecraft.item.ItemStack; 12 14 import net.minecraft.item.ItemUsageContext; 13 15 import net.minecraft.sound.SoundEvents; 16 + import net.minecraft.text.Style; 17 + import net.minecraft.text.Text; 14 18 import net.minecraft.util.ActionResult; 15 19 import net.minecraft.util.DyeColor; 16 20 import net.minecraft.util.Hand; 17 21 import net.minecraft.util.math.BlockPos; 18 22 import net.minecraft.world.World; 19 23 20 - import java.awt.*; 21 24 import java.util.concurrent.atomic.AtomicBoolean; 22 25 23 26 public class ChromaticItem extends Item implements PortalDataHolder { ··· 29 32 player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 0.5f, pitch); 30 33 } 31 34 32 - static ComponentChanges ofColor(int color) { 33 - return ComponentChanges.builder() 34 - .add(ModComponentTypes.COLOR.get(), color) 35 - .remove(ModComponentTypes.DYE_COLOR.get()) 36 - .remove(ModComponentTypes.HUE.get()) 37 - .build(); 38 - } 39 - static ComponentChanges ofHue(int hue) { 40 - return ComponentChanges.builder() 41 - .add(ModComponentTypes.COLOR.get(), Color.HSBtoRGB(hue/360f, 1.0f, 1.0f) & 0xFFFFFF) 42 - .remove(ModComponentTypes.DYE_COLOR.get()) 43 - .add(ModComponentTypes.HUE.get(), hue) 44 - .build(); 45 - } 46 - static ComponentChanges ofDye(DyeColor dyeColor) { 47 - return ComponentChanges.builder() 48 - .add(ModComponentTypes.COLOR.get(), ColorLogic.getChromaticColor(dyeColor)) 49 - .add(ModComponentTypes.DYE_COLOR.get(), dyeColor.getName()) 50 - .remove(ModComponentTypes.HUE.get()) 51 - .build(); 52 - } 53 - 54 35 @Override 55 36 public ActionResult useOnBlock(ItemUsageContext context) { 56 37 PlayerEntity player = context.getPlayer(); ··· 61 42 62 43 public boolean useOnBlock(PlayerEntity player, Hand hand, World world, BlockPos pos, ItemStack currStack) { 63 44 BlockState oldState = world.getBlockState(pos); 64 - int currColor = currStack.getOrDefault(ModComponentTypes.COLOR.get(), 0xFFFFFF); 45 + int currColor = BackportMethods.getOrDefaultInt(currStack, ModComponentTypes.KEY_COLOR, 0xFFFFFF); 65 46 if (player.isSneaking()) { //copy color 66 47 ItemStack newStack = currStack.copy(); 67 48 int i = -1; ··· 72 53 else { 73 54 int hue = (altarState - 1) * (360 / (AltarBlock.numColors - 1)); 74 55 if (!ColorLogic.matchesPureHue(currColor, hue)) 75 - newStack.applyChanges(ofHue(hue)); 56 + BackportMethods.apply(newStack, ModComponentTypes.HUE, hue); 76 57 else return false; 77 58 } 78 59 } 79 60 else { //copy color from vanilla blocks 80 61 DyeColor dyeColor = ColorLogic.getColorByState(oldState); 81 62 if (dyeColor != null && 82 - !dyeColor.getName().equals(newStack.getOrDefault(ModComponentTypes.DYE_COLOR.get(), "null"))) { 83 - newStack.applyChanges(ofDye(dyeColor)); 63 + !(dyeColor.getId() == (BackportMethods.getOrDefaultInt(newStack, ModComponentTypes.DYE_COLOR, -1)))) { 64 + BackportMethods.apply(newStack, ModComponentTypes.DYE_COLOR, dyeColor.getId()); 84 65 } 85 66 else return false; 86 67 } 87 68 if (i > 0) { 88 - if (i != currColor) newStack.applyChanges(ofColor(i)); 69 + if (i != currColor) BackportMethods.apply(newStack, ModComponentTypes.DYE_COLOR, i); 89 70 else return false; 90 71 } 91 72 player.setStackInHand(hand, newStack); ··· 94 75 } 95 76 else { //paste color to blocks 96 77 if (oldState.isIn(ModTags.IRIDESCENT_BLOCKS)) return false; 97 - boolean bl = currStack.contains(ModComponentTypes.DYE_COLOR.get()); 98 - BlockState state = ColorLogic.recolor(bl ? currStack.get(ModComponentTypes.DYE_COLOR.get()) : "infinity:chromatic", oldState); 78 + boolean bl = BackportMethods.contains(currStack, ModComponentTypes.DYE_COLOR); 79 + BlockState state; 80 + if (bl) state = ColorLogic.recolor(BackportMethods.getOrDefaultString(currStack, ModComponentTypes.DYE_COLOR, "infinity:chromatic"), oldState); 81 + else state = ColorLogic.recolor("infinity:chromatic", oldState); 99 82 if (state == null) return false; 100 83 world.setBlockState(pos, state); 101 84 AtomicBoolean cancel = new AtomicBoolean(false); 102 85 if (!bl && world.getBlockEntity(pos) instanceof ChromaticBlockEntity cbe) { 103 - int hue = currStack.getOrDefault(ModComponentTypes.HUE.get(), -1); 86 + int hue = BackportMethods.getOrDefaultInt(currStack, ModComponentTypes.HUE, -1); 104 87 if (hue > 0) cbe.setColor(hue, 255, 255, cancel); 105 88 else cbe.setColor(currColor, cancel); 106 89 } ··· 110 93 } 111 94 } 112 95 return false; 96 + } 97 + 98 + @Override 99 + public Text getName() { 100 + return Text.translatable(this.getTranslationKey()).setStyle(Style.EMPTY.withColor(ColorLogic.defaultChromatic)); 113 101 } 114 102 }
+4 -4
common/src/main/java/net/lerariemann/infinity/item/F4Item.java
··· 125 125 BlockPos lowerCenter = player.getBlockPos().offset(dir, 4); 126 126 ItemStack stack = player.getStackInHand(hand); 127 127 128 - int size_x = BackportMethods.getOrDefaultInt(stack, ModItemFunctions.SIZE_X, 3); 129 - int size_y = BackportMethods.getOrDefaultInt(stack, ModItemFunctions.SIZE_Y, 3); 128 + int size_x = BackportMethods.getOrDefaultInt(stack, ModComponentTypes.SIZE_X, 3); 129 + int size_y = BackportMethods.getOrDefaultInt(stack, ModComponentTypes.SIZE_Y, 3); 130 130 131 131 if (size_y % 2 == 0) { 132 132 double d = dir2.equals(Direction.Axis.X) ? player.getPos().x : player.getPos().z; ··· 187 187 Direction.Axis dir2 = 188 188 player.getHorizontalFacing().getAxis().equals(Direction.Axis.X) ? Direction.Axis.Z : Direction.Axis.X; 189 189 190 - int size_x = BackportMethods.getOrDefaultInt(stack, ModItemFunctions.SIZE_X, 3); 191 - int size_y = BackportMethods.getOrDefaultInt(stack, ModItemFunctions.SIZE_Y, 3); 190 + int size_x = BackportMethods.getOrDefaultInt(stack, ModComponentTypes.SIZE_X, 3); 191 + int size_y = BackportMethods.getOrDefaultInt(stack, ModComponentTypes.SIZE_Y, 3); 192 192 193 193 //validating the place position 194 194 for (int j = -1; j <= size_y; j++) for (int k = -1; k <= size_x; k++) {
+25 -10
common/src/main/java/net/lerariemann/infinity/item/IridescentPotionItem.java
··· 3 3 import net.lerariemann.infinity.iridescence.Iridescence; 4 4 import net.lerariemann.infinity.registry.core.ModComponentTypes; 5 5 import net.lerariemann.infinity.registry.core.ModStatusEffects; 6 + import net.lerariemann.infinity.util.BackportMethods; 7 + import net.lerariemann.infinity.util.var.ColorLogic; 6 8 import net.minecraft.advancement.criterion.Criteria; 7 - import net.minecraft.component.type.PotionContentsComponent; 9 + import net.minecraft.client.item.TooltipContext; 8 10 import net.minecraft.entity.LivingEntity; 9 11 import net.minecraft.entity.effect.StatusEffectInstance; 10 12 import net.minecraft.entity.player.PlayerEntity; ··· 12 14 import net.minecraft.item.ItemStack; 13 15 import net.minecraft.item.ItemUsage; 14 16 import net.minecraft.item.Items; 15 - import net.minecraft.item.tooltip.TooltipType; 17 + import net.minecraft.potion.PotionUtil; 16 18 import net.minecraft.server.network.ServerPlayerEntity; 17 19 import net.minecraft.stat.Stats; 20 + import net.minecraft.text.Style; 18 21 import net.minecraft.text.Text; 19 22 import net.minecraft.util.Hand; 20 23 import net.minecraft.util.TypedActionResult; ··· 30 33 } 31 34 32 35 @Override 36 + public boolean hasGlint(ItemStack stack) { 37 + return true; 38 + } 39 + 40 + @Override 33 41 public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { 34 - int level = stack.getOrDefault(ModComponentTypes.CHARGE.get(), 0); 42 + int level = BackportMethods.getOrDefaultInt(stack, ModComponentTypes.F4_CHARGE, 0); 35 43 if (!world.isClient) Iridescence.tryBeginJourney(user, level, true); 36 44 if (user instanceof PlayerEntity player) { 37 45 if (user instanceof ServerPlayerEntity spe) { 38 46 Criteria.CONSUME_ITEM.trigger(spe, stack); 39 47 } 40 48 player.incrementStat(Stats.USED.getOrCreateStat(this)); 41 - stack.decrementUnlessCreative(1, player); 42 49 43 - if (!player.isInCreativeMode()) 50 + if (!player.isCreative()) { 51 + stack.decrement(1); 44 52 player.getInventory().insertStack(new ItemStack(Items.GLASS_BOTTLE)); 53 + } 54 + 45 55 } 46 56 else if (stack.isEmpty()) { 47 57 return new ItemStack(Items.GLASS_BOTTLE); ··· 51 61 } 52 62 53 63 @Override 54 - public int getMaxUseTime(ItemStack stack, LivingEntity user) { 64 + public int getMaxUseTime(ItemStack stack) { 55 65 return 32; 56 66 } 57 67 ··· 66 76 } 67 77 68 78 @Override 69 - public void appendTooltip(ItemStack stack, Item.TooltipContext context, List<Text> tooltip, TooltipType type) { 70 - int level = stack.getOrDefault(ModComponentTypes.CHARGE.get(), 0); 71 - List<StatusEffectInstance> effects = List.of(new StatusEffectInstance(ModStatusEffects.IRIDESCENT_EFFECT, 79 + public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext type) { 80 + int level = BackportMethods.getOrDefaultInt(stack, ModComponentTypes.F4_CHARGE, 0); 81 + List<StatusEffectInstance> effects = List.of(new StatusEffectInstance(ModStatusEffects.IRIDESCENT_EFFECT.value(), 72 82 Iridescence.getFullEffectLength(level), level)); 73 - PotionContentsComponent.buildTooltip(effects, tooltip::add, 1.0F, context.getUpdateTickRate()); 83 + PotionUtil.buildTooltip(effects, tooltip::add, 1.0F, level); 84 + } 85 + 86 + @Override 87 + public Text getName() { 88 + return Text.translatable(this.getTranslationKey()).setStyle(Style.EMPTY.withColor(ColorLogic.defaultChromatic)); 74 89 } 75 90 }
-11
common/src/main/java/net/lerariemann/infinity/item/TransfiniteKeyItem.java
··· 20 20 super(settings); 21 21 } 22 22 23 - @Override 24 - public ComponentChanges.Builder getPortalComponents(InfinityPortalBlockEntity ipbe) { 25 - Identifier id = ipbe.getDimension(); 26 - int color = (ipbe.getWorld() instanceof ServerWorld w) ? 27 - PortalColorApplier.of(id, w.getServer()).apply(BlockPos.ORIGIN) : 28 - (int)InfinityMethods.getNumericFromId(id); 29 - return ComponentChanges.builder() 30 - .add(ModComponentTypes.DESTINATION.get(), id) 31 - .add(ModComponentTypes.COLOR.get(), color & 0xFFFFFF); 32 - } 33 - 34 23 @NotNull 35 24 @Override 36 25 public Identifier getDestination(ItemStack stack) {
+2 -2
common/src/main/java/net/lerariemann/infinity/item/function/F4RechargingRecipe.java
··· 48 48 if (charge > 0) return Items.OBSIDIAN.getDefaultStack().copyWithCount(Math.min(charge, 64)); //"removing obsidian" recipe 49 49 } 50 50 ItemStack result = f4.copy(); 51 - BackportMethods.apply(result, ModItemFunctions.F4_CHARGE, charge+i); 51 + BackportMethods.apply(result, ModComponentTypes.F4_CHARGE, charge+i); 52 52 return result; 53 53 } 54 54 ··· 70 70 if (charge == 0) return defaultedList; //"clearing data" recipe 71 71 charge = Math.max(charge - 64, 0); 72 72 ItemStack result = f4.copy(); 73 - BackportMethods.apply(result, ModItemFunctions.F4_CHARGE, charge); 73 + BackportMethods.apply(result, ModComponentTypes.F4_CHARGE, charge); 74 74 defaultedList.set(f4pos, result); 75 75 return defaultedList; 76 76 }
+5 -7
common/src/main/java/net/lerariemann/infinity/mixin/iridescence/BrewingRecipeRegistryMixin.java
··· 1 1 package net.lerariemann.infinity.mixin.iridescence; 2 2 3 3 import net.lerariemann.infinity.registry.core.ModItems; 4 - import net.minecraft.component.DataComponentTypes; 5 - import net.minecraft.component.type.PotionContentsComponent; 6 4 import net.minecraft.item.ItemStack; 7 5 import net.minecraft.potion.Potion; 8 6 import net.minecraft.recipe.BrewingRecipeRegistry; ··· 18 16 @Mixin(BrewingRecipeRegistry.class) 19 17 public class BrewingRecipeRegistryMixin { 20 18 @Inject(method = "isValidIngredient", at = @At("RETURN"), cancellable = true) 21 - void inj(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { 19 + private static void inj(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { 22 20 cir.setReturnValue(cir.getReturnValue() || stack.isOf(ModItems.CHROMATIC_MATTER.get())); 23 21 } 24 22 25 23 @Inject(method="hasPotionRecipe", at = @At("RETURN"), cancellable = true) 26 - void inj(ItemStack input, ItemStack ingredient, CallbackInfoReturnable<Boolean> cir) { 24 + private static void inj(ItemStack input, ItemStack ingredient, CallbackInfoReturnable<Boolean> cir) { 27 25 if (ingredient.isOf(ModItems.CHROMATIC_MATTER.get())) { 28 26 Optional<RegistryEntry<Potion>> optional = input.getOrDefault(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT).potion(); 29 - if (optional.isPresent() && optional.get().matchesId(Identifier.ofVanilla("awkward"))) cir.setReturnValue(true); 27 + if (optional.isPresent() && optional.get().matchesId(new Identifier("awkward"))) cir.setReturnValue(true); 30 28 } 31 29 } 32 30 33 31 @Inject(method = "craft", at = @At("HEAD"), cancellable = true) 34 - void inj2(ItemStack ingredient, ItemStack input, CallbackInfoReturnable<ItemStack> cir) { 32 + private static void inj2(ItemStack ingredient, ItemStack input, CallbackInfoReturnable<ItemStack> cir) { 35 33 if (!input.isEmpty() && ingredient.isOf(ModItems.CHROMATIC_MATTER.get())) { 36 34 Optional<RegistryEntry<Potion>> optional = input.getOrDefault(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT).potion(); 37 - if (optional.isPresent() && optional.get().matchesId(Identifier.ofVanilla("awkward"))) 35 + if (optional.isPresent() && optional.get().matchesId(new Identifier("awkward"))) 38 36 cir.setReturnValue(ModItems.CHROMATIC_POTION.get().getDefaultStack()); 39 37 } 40 38 }
+5 -4
common/src/main/java/net/lerariemann/infinity/mixin/iridescence/ItemStackMixin.java
··· 4 4 import com.llamalad7.mixinextras.sugar.ref.LocalRef; 5 5 import net.lerariemann.infinity.iridescence.Iridescence; 6 6 import net.lerariemann.infinity.registry.var.ModTags; 7 + import net.minecraft.client.item.TooltipContext; 7 8 import net.minecraft.entity.player.PlayerEntity; 8 9 import net.minecraft.item.Item; 9 10 import net.minecraft.item.ItemStack; 10 - import net.minecraft.item.tooltip.TooltipType; 11 11 import net.minecraft.registry.tag.TagKey; 12 12 import net.minecraft.text.MutableText; 13 + import net.minecraft.text.Style; 13 14 import net.minecraft.text.Text; 15 + import net.minecraft.util.DyeColor; 14 16 import org.spongepowered.asm.mixin.Mixin; 15 17 import org.spongepowered.asm.mixin.Shadow; 16 18 import org.spongepowered.asm.mixin.injection.At; ··· 25 27 26 28 @Inject(method="getTooltip", at = @At(value = "INVOKE", 27 29 target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 0)) 28 - void inj(Item.TooltipContext context, PlayerEntity player, TooltipType type, CallbackInfoReturnable<List<Text>> cir, 29 - @Local LocalRef<MutableText> mutableText) { 30 + void inj(PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List<Text>> cir, @Local LocalRef<MutableText> mutableText) { 30 31 if (isIn(ModTags.IRIDESCENT_ITEMS)) { 31 - mutableText.set(mutableText.get().withColor(Iridescence.getTimeBasedColor())); 32 + mutableText.set(mutableText.get().setStyle(Style.EMPTY.withColor(Iridescence.getTimeBasedColor()))); 32 33 } 33 34 } 34 35 }
+3 -2
common/src/main/java/net/lerariemann/infinity/mixin/options/PlayerManagerMixin.java
··· 70 70 }); 71 71 } 72 72 InfinityMod.LOGGER.info("Sending sound pack to client"); 73 - if (InfinityMod.provider.rule("useSoundSyncPackets")) InfinityMethods.sendS2CPayload(player, new ModPayloads.DownloadSoundPack( 74 - CommonIO.read(player.server.getSavePath(WorldSavePath.DATAPACKS).resolve("client_sound_pack_data.json")))); 73 + // TODO soundpacks 74 + // if (InfinityMod.provider.rule("useSoundSyncPackets")) InfinityMethods.sendS2CPayload(player, new ModPayloads.DownloadSoundPack( 75 + // CommonIO.read(player.server.getSavePath(WorldSavePath.DATAPACKS).resolve("client_sound_pack_data.json")))); 75 76 } 76 77 77 78 @Inject(method="sendWorldInfo", at = @At("TAIL"))
+2 -1
common/src/main/java/net/lerariemann/infinity/registry/core/ModComponentTypes.java
··· 4 4 5 5 public static String DESTINATION = "key_destination"; 6 6 public static String BIOME_CONTENTS = "biome_contents"; 7 - public static String COLOR = "color"; 7 + public static String KEY_COLOR = "key_color"; 8 + public static String HUE = "hue"; 8 9 public static String DYE_COLOR = "dye_color"; 9 10 public static String F4_CHARGE = "f4_charge"; 10 11 public static String SIZE_X = "f4_size_x";
+2 -10
common/src/main/java/net/lerariemann/infinity/registry/core/ModItemFunctions.java
··· 13 13 import net.minecraft.block.DispenserBlock; 14 14 import net.minecraft.block.dispenser.ItemDispenserBehavior; 15 15 import net.minecraft.client.world.ClientWorld; 16 - import net.minecraft.component.ComponentChanges; 17 16 import net.minecraft.entity.Entity; 18 17 import net.minecraft.entity.ItemEntity; 19 18 import net.minecraft.entity.LivingEntity; ··· 37 36 import org.jetbrains.annotations.Nullable; 38 37 39 38 import java.util.Optional; 40 - import java.util.function.Function; 41 39 42 40 import static net.lerariemann.infinity.InfinityMod.MOD_ID; 43 41 import static net.lerariemann.infinity.registry.core.ModItems.TRANSFINITE_KEY; 44 42 45 43 public class ModItemFunctions { 46 - 47 - public static String SIZE_X = "f4_size_x"; 48 - public static String SIZE_Y = "f4_size_y"; 49 - public static String F4_CHARGE = "f4_charge"; 50 - public static String DESTINATION = "key_destination"; 51 - public static String COLOR = "key_color"; 52 44 53 45 public static final DeferredRegister<LootFunctionType> LOOT_FUNCTION_TYPES = 54 46 DeferredRegister.create(MOD_ID, RegistryKeys.LOOT_FUNCTION_TYPE); ··· 131 123 }, w); 132 124 if (match.isEmpty()) return; 133 125 134 - ItemStack resStack = match.get().value().getResult(w.getRegistryManager()); 135 - componentFunction.apply(resStack.getItem()).ifPresent(resStack::applyChanges); 126 + ItemStack resStack = match.get().getOutput(w.getRegistryManager()); 127 + // componentFunction.apply(resStack.getItem()).ifPresent(resStack::applyChanges); 136 128 137 129 Vec3d v = itemEntity.getVelocity(); 138 130 ItemEntity result = new ItemEntity(w, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(),
+5 -7
common/src/main/java/net/lerariemann/infinity/registry/core/ModItems.java
··· 50 50 registerBlockItemAfter(ModBlocks.IRIDESCENT_CARPET, ItemGroups.COLORED_BLOCKS, Items.PINK_CARPET, BlockItem::new); 51 51 public static final RegistrySupplier<ChromaticBlockItem> CHROMATIC_WOOL = 52 52 registerBlockItemAfter(ModBlocks.CHROMATIC_WOOL, ItemGroups.COLORED_BLOCKS, Items.PINK_WOOL, 53 - new Item.Settings().component(ModComponentTypes.COLOR.get(), ColorLogic.defaultChromatic), 53 + new Item.Settings(), 54 54 ChromaticBlockItem::new); 55 55 public static final RegistrySupplier<ChromaticBlockItem> CHROMATIC_CARPET = 56 56 registerBlockItemAfter(ModBlocks.CHROMATIC_CARPET, ItemGroups.COLORED_BLOCKS, Items.PINK_CARPET, 57 - new Item.Settings().component(ModComponentTypes.COLOR.get(), ColorLogic.defaultChromatic), 57 + new Item.Settings(), 58 58 ChromaticBlockItem::new); 59 59 public static final RegistrySupplier<Item> BIOME_BOTTLE_ITEM = 60 60 registerBlockItemAfter(ModBlocks.BIOME_BOTTLE, ItemGroups.INGREDIENTS, Items.EXPERIENCE_BOTTLE, BiomeBottleItem::new); ··· 91 91 new FoodComponent.Builder().alwaysEdible().build())); 92 92 public static final RegistrySupplier<ChromaticItem> CHROMATIC_MATTER = 93 93 registerItemAfter("chromatic_matter", ItemGroups.INGREDIENTS, Items.DISC_FRAGMENT_5, ChromaticItem::new, 94 - new Item.Settings().component(ModComponentTypes.COLOR.get(), ColorLogic.defaultChromatic)); 94 + new Item.Settings()); 95 95 public static final RegistrySupplier<Item> WHITE_MATTER = 96 96 registerItemAfter("white_matter", ItemGroups.INGREDIENTS, Items.DISC_FRAGMENT_5, Item::new); 97 97 public static final RegistrySupplier<Item> BLACK_MATTER = ··· 110 110 new Item.Settings().rarity(Rarity.RARE)); 111 111 public static final RegistrySupplier<Item> IRIDESCENT_POTION = 112 112 registerItemAfter("iridescent_potion", ItemGroups.FOOD_AND_DRINK, Items.HONEY_BOTTLE, IridescentPotionItem::new, 113 - new Item.Settings().component(ModComponentTypes.CHARGE.get(), 4) 114 - .rarity(Rarity.UNCOMMON) 115 - .component(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true)); 113 + new Item.Settings()); 116 114 public static final RegistrySupplier<Item> CHROMATIC_POTION = 117 115 registerItemAfter("chromatic_potion", ItemGroups.FOOD_AND_DRINK, Items.HONEY_BOTTLE, IridescentPotionItem::new, 118 - new Item.Settings().component(ModComponentTypes.CHARGE.get(), 0)); 116 + new Item.Settings()); 119 117 120 118 public static <T extends Item> RegistrySupplier<T> register(String item, Item.Settings settings, Function<Item.Settings, T> constructor) { 121 119 return ITEMS.register(item, () -> constructor.apply(settings));
+14 -25
common/src/main/java/net/lerariemann/infinity/registry/var/ModCriteria.java
··· 104 104 } 105 105 } 106 106 107 - public static class IridescentCriterion extends AbstractCriterion<IridescenceConditions> { 107 + public static class IridescentCriterion extends AbstractCriterion<EmptyConditions> { 108 + static final Identifier ID = InfinityMethods.getId("iridescence"); 109 + 108 110 public void trigger(ServerPlayerEntity player, boolean willing, int level) { 109 - this.trigger(player, (conditions) -> conditions.test(willing, level)); 111 + this.trigger(player, (conditions) -> true); 110 112 } 111 113 114 + 112 115 @Override 113 - public Codec<IridescenceConditions> getConditionsCodec() { 114 - return IridescenceConditions.CODEC; 116 + protected EmptyConditions conditionsFromJson(JsonObject obj, LootContextPredicate lootContextPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) { 117 + return new EmptyConditions(lootContextPredicate, ID); 118 + } 119 + 120 + @Override 121 + public Identifier getId() { 122 + return ID; 115 123 } 116 124 } 117 125 ··· 172 180 } 173 181 } 174 182 175 - public record IridescenceConditions(Optional<LootContextPredicate> player, Optional<Boolean> willing, Optional<Integer> minLevel) implements AbstractCriterion.Conditions { 176 - public static final Codec<IridescenceConditions> CODEC = RecordCodecBuilder.create( 177 - instance -> instance.group( 178 - EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(IridescenceConditions::player), 179 - Codec.BOOL.optionalFieldOf("willing").forGetter(IridescenceConditions::willing), 180 - Codec.INT.optionalFieldOf("min_level").forGetter(IridescenceConditions::minLevel) 181 - ) 182 - .apply(instance, IridescenceConditions::new) 183 - ); 184 - 185 - public boolean test(boolean isWilling, int level) { 186 - return (willing.isEmpty() || isWilling == willing.get()) && (minLevel.isEmpty() || level >= minLevel.get()); 187 - } 188 - } 189 - 190 - public static RegistrySupplier<DimensionOpenedCriterion> DIMS_OPENED; 191 - public static RegistrySupplier<DimensionClosedCriterion> DIMS_CLOSED; 192 - public static RegistrySupplier<WhoRemainsCriterion> WHO_REMAINS; 193 - public static RegistrySupplier<IridescentCriterion> IRIDESCENT; 194 - public static RegistrySupplier<BiomeBottleCriterion> BIOME_BOTTLE; 195 - public static RegistrySupplier<ConvertMobCriterion> CONVERT_MOB; 183 + public static class DataConditions extends AbstractCriterionConditions { 184 + private final int score; 196 185 197 186 public DataConditions(LootContextPredicate player, int score, Identifier ID) { 198 187 super(ID, player);
+1 -1
common/src/main/java/net/lerariemann/infinity/registry/var/ModPlacementModifiers.java
··· 44 44 ModPlacementModifiers.CenterProximityPlacementModifier.MODIFIER_CODEC); 45 45 46 46 static RegistrySupplier<PlacementModifierType<?>> register(String id, MapCodec<? extends PlacementModifier> codec) { 47 - return PLACEMENT_MODIFIER_TYPES.register(id, () -> getType(codec)); 47 + return PLACEMENT_MODIFIER_TYPES.register(id, () -> () -> ((MapCodec<PlacementModifier>) codec).codec()); 48 48 } 49 49 public static void registerModifiers() { 50 50 PLACEMENT_MODIFIER_TYPES.register();
+11 -1
common/src/main/java/net/lerariemann/infinity/util/BackportMethods.java
··· 1 1 package net.lerariemann.infinity.util; 2 2 3 + import net.lerariemann.infinity.registry.core.ModComponentTypes; 3 4 import net.lerariemann.infinity.registry.core.ModItemFunctions; 4 5 import net.minecraft.item.ItemStack; 5 6 import net.minecraft.util.Identifier; 6 7 import org.jetbrains.annotations.Nullable; 8 + 9 + import java.util.Objects; 7 10 8 11 public class BackportMethods { 9 12 public static int getOrDefaultInt(ItemStack stack, String key, int i) { ··· 22 25 return i; 23 26 } 24 27 28 + public static boolean contains(ItemStack stack, String key) { 29 + if (stack.hasNbt()) { 30 + return !Objects.requireNonNull(stack.getSubNbt(key)).isEmpty(); 31 + } 32 + return false; 33 + } 34 + 25 35 public static ItemStack apply(ItemStack stack, String key, int i) { 26 36 if (stack.hasNbt()) { 27 37 assert stack.getNbt() != null; ··· 49 59 50 60 public static @Nullable String getDimensionComponents(ItemStack stack) { 51 61 if (stack.getNbt() != null) { 52 - return stack.getNbt().getString(ModItemFunctions.DESTINATION); 62 + return stack.getNbt().getString(ModComponentTypes.DESTINATION); 53 63 } 54 64 return null; 55 65 }
+49 -49
common/src/main/java/net/lerariemann/infinity/util/config/SoundScanner.java
··· 10 10 import net.lerariemann.infinity.util.core.CommonIO; 11 11 import net.lerariemann.infinity.util.core.RandomProvider; 12 12 import net.lerariemann.infinity.util.loading.DimensionGrabber; 13 - import net.minecraft.block.jukebox.JukeboxSong; 14 13 import net.minecraft.client.MinecraftClient; 15 14 import net.minecraft.nbt.NbtCompound; 16 15 import net.minecraft.nbt.NbtElement; ··· 34 33 /** 35 34 * Pipeline for generating custom sound events and jukebox song definitions for every music track in the game. 36 35 */ 36 + // TODO soundpacks 37 37 public record SoundScanner(Map<Identifier, Resource> soundIds) { 38 38 /** Holds a map which allows to get the list of all sound IDs in existence and .ogg data for each. 39 39 * Seeded by {@link SoundListMixin} on client launch. */ ··· 50 50 * <p>On player connect, the server sends a {@link ModPayloads.DownloadSoundPack} payload to the client. 51 51 * <p>If the server already contains data upon which the client should create its resource pack, it holds this data. 52 52 * <p>Otherwise, this payload is empty, and the server relies on the client to create it and send it back to the server for future use. */ 53 - public static void unpackDownloadedPack(ModPayloads.DownloadSoundPack payload, Object clientContext) { 54 - MinecraftClient cl = ModPayloads.client(clientContext); 55 - //the client unpacks a non-empty payload only when needed, meaning only if it doesn't have necessary files yet 56 - if (!payload.songIds().isEmpty() && !Files.exists(cl.getResourcePackDir().resolve("infinity/assets/infinity/sounds.json"))) { 57 - cl.execute(() -> saveResourcePack(cl, payload.songIds().getList("entries", NbtElement.STRING_TYPE).stream() 58 - .map(NbtElement::asString).map(Identifier::of), false)); 59 - } 60 - else if (isPreloaded()) { 61 - cl.execute(() -> { 62 - NbtCompound jukeboxes = saveResourcePack(cl, getMatchingLoadedIds(), true); 63 - NbtCompound res = new NbtCompound(); 64 - NbtList songIds = new NbtList(); 65 - getMatchingLoadedIds().forEach(id -> songIds.add(NbtString.of(id.toString()))); 66 - res.put("entries", songIds); 67 - res.put("jukeboxes", jukeboxes); 68 - ClientPlayNetworking.send(new ModPayloads.UploadJukeboxes(res)); 69 - }); 70 - } 71 - } 53 + // public static void unpackDownloadedPack(ModPayloads.DownloadSoundPack payload, Object clientContext) { 54 + // MinecraftClient cl = ModPayloads.client(clientContext); 55 + // //the client unpacks a non-empty payload only when needed, meaning only if it doesn't have necessary files yet 56 + // if (!payload.songIds().isEmpty() && !Files.exists(cl.getResourcePackDir().resolve("infinity/assets/infinity/sounds.json"))) { 57 + // cl.execute(() -> saveResourcePack(cl, payload.songIds().getList("entries", NbtElement.STRING_TYPE).stream() 58 + // .map(NbtElement::asString).map(Identifier::of), false)); 59 + // } 60 + // else if (isPreloaded()) { 61 + // cl.execute(() -> { 62 + // NbtCompound jukeboxes = saveResourcePack(cl, getMatchingLoadedIds(), true); 63 + // NbtCompound res = new NbtCompound(); 64 + // NbtList songIds = new NbtList(); 65 + // getMatchingLoadedIds().forEach(id -> songIds.add(NbtString.of(id.toString()))); 66 + // res.put("entries", songIds); 67 + // res.put("jukeboxes", jukeboxes); 68 + // ClientPlayNetworking.send(new ModPayloads.UploadJukeboxes(res)); 69 + // }); 70 + // } 71 + // } 72 72 /** 73 73 * Generating and saving a resource pack from a stream of identifiers that correspond to music tracks. 74 74 * @param sendJukeboxes if this is true, the method also generates and returns data that needs to be sent to the server ··· 80 80 songIds.forEach(id -> { 81 81 String str = id.toString().replace(".ogg", "").replace("sounds/", ""); 82 82 List<String> arr = Arrays.stream(str.split("[:/]")).toList(); //preloading IDs 83 - String songID = "disc." + arr.getFirst() + "." + arr.getLast(); 83 + String songID = "disc." + arr.get(0) + "." + arr.get(arr.size()-1); 84 84 String subtitleID = "infinity:subtitles." + songID; 85 - String subtitleData = InfinityMethods.formatAsTitleCase(arr.getFirst() + " - " + arr.getLast()); 85 + String subtitleData = InfinityMethods.formatAsTitleCase(arr.get(0) + " - " + arr.get(arr.size()-1)); 86 86 87 87 NbtList soundForRPList = new NbtList(); 88 88 soundForRPList.add(NbtString.of(str)); ··· 100 100 } catch (IOException e) { 101 101 length = 600; 102 102 } 103 - jukeboxes.put(arr.getLast(), getJukeboxDef(songID, subtitleID, length)); 103 + jukeboxes.put(arr.get(arr.size()-1), getJukeboxDef(songID, subtitleID, length)); 104 104 } 105 105 }); 106 106 CommonIO.write(soundsForRP, client.getResourcePackDir().resolve("infinity/assets/infinity"), "sounds.json"); ··· 108 108 return jukeboxes; 109 109 } 110 110 111 - /** Receiver for a C2S {@link ModPayloads.UploadJukeboxes} payload, which holds data to send to clients in the future for them to 111 + /** Receiver for a C2S {@link ModPayloads} payload, which holds data to send to clients in the future for them to 112 112 * generate custom sound resource packs, as well as jukebox song definitions corresponding to this data. */ 113 - public static void unpackUploadedJukeboxes(ModPayloads.UploadJukeboxes payload, ServerPlayNetworking.Context context) { 114 - if (!InfinityMod.provider.rule("useSoundSyncPackets")) return; 115 - NbtCompound data = payload.data(); 116 - if (!data.contains("jukeboxes") || !data.contains("entries")) return; 117 - MinecraftServer server = context.player().server; 118 - if (Files.exists(server.getSavePath(WorldSavePath.DATAPACKS).resolve("client_sound_pack_data.json"))) return; 119 - 120 - unpackUploadedJukeboxes(server, data.getCompound("jukeboxes")); 121 - data.remove("jukeboxes"); 122 - NbtCompound packData = new NbtCompound(); 123 - packData.put("entries", data.get("entries")); 124 - CommonIO.write(packData, server.getSavePath(WorldSavePath.DATAPACKS), "client_sound_pack_data.json"); 125 - } 113 + // public static void unpackUploadedJukeboxes(ModPayloads payload, ServerPlayNetworking.Context context) { 114 + // if (!InfinityMod.provider.rule("useSoundSyncPackets")) return; 115 + // NbtCompound data = payload.data(); 116 + // if (!data.contains("jukeboxes") || !data.contains("entries")) return; 117 + // MinecraftServer server = context.player().server; 118 + // if (Files.exists(server.getSavePath(WorldSavePath.DATAPACKS).resolve("client_sound_pack_data.json"))) return; 119 + // 120 + // unpackUploadedJukeboxes(server, data.getCompound("jukeboxes")); 121 + // data.remove("jukeboxes"); 122 + // NbtCompound packData = new NbtCompound(); 123 + // packData.put("entries", data.get("entries")); 124 + // CommonIO.write(packData, server.getSavePath(WorldSavePath.DATAPACKS), "client_sound_pack_data.json"); 125 + // } 126 126 public static void unpackUploadedJukeboxes(MinecraftServer server, NbtCompound allJukeboxes) { 127 127 Path pathJukeboxes = server.getSavePath(WorldSavePath.DATAPACKS).resolve("infinity/data/infinity/jukebox_song"); 128 128 for (String key: allJukeboxes.getKeys()) { ··· 130 130 CommonIO.write(jukebox, pathJukeboxes, key + ".json"); 131 131 } 132 132 } 133 - grabJukeboxes(server); 133 + // grabJukeboxes(server); 134 134 } 135 135 /** Injects freshly received jukebox song definitions into the server's registries, config files and {@link RandomProvider}. */ 136 - public static void grabJukeboxes(MinecraftServer server) { 137 - Path pathJukeboxes = server.getSavePath(WorldSavePath.DATAPACKS).resolve("infinity/data/infinity/jukebox_song"); 138 - InfinityMod.LOGGER.info("grabbing jukeboxes"); 139 - DimensionGrabber grabber = new DimensionGrabber(server.getRegistryManager()); 140 - grabber.buildGrabber(JukeboxSong.CODEC, RegistryKeys.JUKEBOX_SONG).grabAll(pathJukeboxes); 141 - grabber.close(); 142 - if (!((MinecraftServerAccess)server).infinity$needsInvocation()) { 143 - ConfigFactory.of(server.getRegistryManager().get(RegistryKeys.JUKEBOX_SONG)).generate("misc", "jukeboxes"); 144 - InfinityMod.updateProvider(server); 145 - } 146 - } 136 + // public static void grabJukeboxes(MinecraftServer server) { 137 + // Path pathJukeboxes = server.getSavePath(WorldSavePath.DATAPACKS).resolve("infinity/data/infinity/jukebox_song"); 138 + // InfinityMod.LOGGER.info("grabbing jukeboxes"); 139 + // DimensionGrabber grabber = new DimensionGrabber(server.getRegistryManager()); 140 + // grabber.buildGrabber(JukeboxSong.CODEC, RegistryKeys.JUKEBOX_SONG).grabAll(pathJukeboxes); 141 + // grabber.close(); 142 + // if (!((MinecraftServerAccess)server).infinity$needsInvocation()) { 143 + // ConfigFactory.of(server.getRegistryManager().get(RegistryKeys.JUKEBOX_SONG)).generate("misc", "jukeboxes"); 144 + // InfinityMod.updateProvider(server); 145 + // } 146 + // } 147 147 148 148 /** 149 149 Getting a duration of an OGG file from its byte data; <a href="https://stackoverflow.com/a/44407355">implementation from StackOverflow</a>.
+1
gradle.properties
··· 7 7 maven_group = net.lerariemann 8 8 archives_name = infinity 9 9 enabled_platforms = fabric,forge 10 + tbversion = 0 10 11 11 12 # Minecraft properties 12 13 minecraft_version = 1.20.1