Skip to content

Commit

Permalink
1.20 port
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Sep 7, 2023
1 parent 81ca49c commit 82119f2
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
workflow_dispatch:
push:
branches:
- '1.19'
- '1.20.1'
tags-ignore:
- '**'
pull_request:
branches:
- '1.19'
- '1.20.1'

env:
JAVA_DIST: 'zulu'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
tags:
- 'v1.19-*.*.*'
- 'v1.20.1-*.*.*'

env:
JAVA_DIST: 'zulu'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import dev.latvian.mods.kubejs.util.ConsoleJS;
import dev.latvian.mods.kubejs.util.UtilsJS;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.npc.VillagerProfession;
Expand All @@ -30,13 +31,13 @@ public class MoreJSBinding {
@Nullable
public static BlockPos findStructure(BlockPos position, ServerLevel level, String structure, int chunkRadius) {
ResourceOrTag<Structure> rot = ResourceOrTag.get(structure,
Registry.STRUCTURE_REGISTRY);
Registries.STRUCTURE);
return LevelUtils.findStructure(position, level, rot, chunkRadius);
}

@Nullable
public static BlockPos findBiome(BlockPos position, ServerLevel level, String biome, int chunkRadius) {
ResourceOrTag<Biome> rot = ResourceOrTag.get(biome, Registry.BIOME_REGISTRY);
ResourceOrTag<Biome> rot = ResourceOrTag.get(biome, Registries.BIOME);
return LevelUtils.findBiome(position, level, rot, chunkRadius);
}

Expand Down Expand Up @@ -124,7 +125,7 @@ public static TradeFilter ofTradeFilter(@Nullable Object o) {
.map(Object::toString)
.map(ResourceLocation::tryParse)
.filter(Objects::nonNull)
.map(Registry.VILLAGER_PROFESSION::getOptional)
.map(BuiltInRegistries.VILLAGER_PROFESSION::getOptional)
.flatMap(Optional::stream)
.collect(Collectors.toSet());
filter.setProfessions(professions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.base.Preconditions;
import dev.latvian.mods.kubejs.event.EventResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void setRequiredLevel(int level) {
public void updateClue() {
var enchantments = getEnchantments();
var instance = enchantments.get(EnchantmentTableChangedJS.this.random.nextInt(enchantments.size()));
EnchantmentTableChangedJS.this.menu.enchantClue[index] = Registry.ENCHANTMENT.getId(
EnchantmentTableChangedJS.this.menu.enchantClue[index] = BuiltInRegistries.ENCHANTMENT.getId(
instance.enchantment);
EnchantmentTableChangedJS.this.menu.levelClue[index] = instance.level;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.almostreliable.morejs.features.villager.IntRange;
import com.google.common.base.Preconditions;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void clearEnchantments() {
public List<ResourceLocation> getEnchantmentIds() {
return getEnchantments()
.stream()
.map(e -> Registry.ENCHANTMENT.getKey(e.enchantment))
.map(e -> BuiltInRegistries.ENCHANTMENT.getKey(e.enchantment))
.filter(Objects::nonNull)
.toList();
}
Expand All @@ -85,7 +85,7 @@ public boolean hasEnchantment(ResourceLocation id) {
}

public boolean hasEnchantment(ResourceLocation id, IntRange range) {
Enchantment enchantment = Registry.ENCHANTMENT.getOptional(id).orElse(null);
Enchantment enchantment = BuiltInRegistries.ENCHANTMENT.getOptional(id).orElse(null);
if (enchantment == null) return false;
for (EnchantmentInstance enchantmentInstance : getEnchantments()) {
if (enchantmentInstance.enchantment == enchantment && range.test(enchantmentInstance.level)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.almostreliable.morejs.features.enchantment;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.EnchantmentMenu;
Expand Down Expand Up @@ -47,6 +47,6 @@ public EnchantmentInstance getClue() {
}

public ResourceLocation getClueId() {
return Registry.ENCHANTMENT.getKey(getClue().enchantment);
return BuiltInRegistries.ENCHANTMENT.getKey(getClue().enchantment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.event.EventJS;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
Expand All @@ -27,16 +27,16 @@ public void printEnchantmentInstances() {
enchantments
.stream()
.sorted((ei1, ei2) -> {
ResourceLocation key1 = Registry.ENCHANTMENT.getKey(ei1.enchantment);
ResourceLocation key2 = Registry.ENCHANTMENT.getKey(ei2.enchantment);
ResourceLocation key1 = BuiltInRegistries.ENCHANTMENT.getKey(ei1.enchantment);
ResourceLocation key2 = BuiltInRegistries.ENCHANTMENT.getKey(ei2.enchantment);
assert key1 != null;
assert key2 != null;
int c = key1.toString().compareTo(key2.toString());
if (c != 0) return c;
return Integer.compare(ei1.level, ei2.level);
})
.forEach(ei -> ConsoleJS.SERVER.info(
Registry.ENCHANTMENT.getKey(ei.enchantment) + " (Level: " + ei.level + ")"));
BuiltInRegistries.ENCHANTMENT.getKey(ei.enchantment) + " (Level: " + ei.level + ")"));
}

public List<EnchantmentInstance> getEnchantmentInstances() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.google.common.base.Preconditions;
import dev.latvian.mods.kubejs.event.EventJS;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
Expand Down Expand Up @@ -46,9 +46,9 @@ public void removeByPotion(@Nullable Potion input, @Nullable Ingredient ingredie
boolean matches = matchesInput && matchesIngredient && matchesOutput;
if (matches) {
ConsoleJS.STARTUP.info(
"Removed potion brewing recipe: " + Registry.POTION.getKey(getInputPotionFromMix(mix)) + " + " +
"Removed potion brewing recipe: " + BuiltInRegistries.POTION.getKey(getInputPotionFromMix(mix)) + " + " +
StringUtils.abbreviate(mix.ingredient.toJson().toString(), 64) + " -> " +
Registry.POTION.getKey(getOutputPotionFromMix(mix)));
BuiltInRegistries.POTION.getKey(getOutputPotionFromMix(mix)));
}
return matches;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void add(CompoundTag tag) {
Mth.clamp(posTag.getDouble(1), 0, borderSize.getY()),
Mth.clamp(posTag.getDouble(2), 0, borderSize.getZ())
);
BlockPos blockPos = new BlockPos(pos);
BlockPos blockPos = new BlockPos(Mth.floor(pos.x), Mth.floor(pos.y), Mth.floor(pos.z));
this.entities.add(new StructureTemplate.StructureEntityInfo(pos, blockPos, tag));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.almostreliable.morejs.features.villager.trades.*;
import com.almostreliable.morejs.util.WeightedList;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

import java.util.Collection;
import java.util.Set;
Expand Down Expand Up @@ -38,7 +37,7 @@ public static boolean isMoreJSTrade(VillagerTrades.ItemListing listing) {
}

public static Collection<VillagerProfession> getProfessions() {
return Registry.VILLAGER_PROFESSION
return BuiltInRegistries.VILLAGER_PROFESSION
.stream()
.filter(p -> !p.name().equals("none"))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.entity.LivingEntityEventJS;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.entity.npc.Villager;
Expand Down Expand Up @@ -58,7 +58,7 @@ public List<Enchantment> getEnchantments() {

public void printEnchantments() {
ConsoleJS.SERVER.info("Potential Enchantments: " + enchantments.stream()
.flatMap(e -> Registry.ENCHANTMENT.getResourceKey(e).stream())
.flatMap(e -> BuiltInRegistries.ENCHANTMENT.getResourceKey(e).stream())
.map(key -> key.location().toString())
.sorted(String::compareToIgnoreCase)
.collect(Collectors.joining(", ")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.almostreliable.morejs.features.villager.TradeItem;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
Expand All @@ -29,7 +29,7 @@ public class EnchantedItemTrade extends TransformableTrade<EnchantedItemTrade> {
public EnchantedItemTrade(TradeItem[] inputs, Item itemToEnchant) {
super(inputs);
this.itemToEnchant = itemToEnchant;
enchantments = Registry.ENCHANTMENT.stream().toList();
enchantments = BuiltInRegistries.ENCHANTMENT.stream().toList();
}

public EnchantedItemTrade enchantments(Enchantment... enchantments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.almostreliable.morejs.features.villager.TradeItem;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.Item;
Expand All @@ -28,7 +28,7 @@ public class PotionTrade extends TransformableTrade<PotionTrade> {
public PotionTrade(TradeItem[] inputs) {
super(inputs);
this.itemForPotion = Items.POTION;
potions = Registry.POTION.stream().toList();
potions = BuiltInRegistries.POTION.stream().toList();
}

public PotionTrade item(Item item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.almostreliable.morejs.util.ResourceOrTag;
import com.almostreliable.morejs.util.WeightedList;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
Expand Down Expand Up @@ -36,7 +36,7 @@ public static TreasureMapTrade forStructure(TradeItem[] input, WeightedList<Obje
if (o == null) {
return null;
}
return ResourceOrTag.get(o.toString(), Registry.STRUCTURE_REGISTRY);
return ResourceOrTag.get(o.toString(), Registries.STRUCTURE);
});

MapPosInfo.Provider func = (level, entity) -> {
Expand All @@ -53,7 +53,7 @@ public static TreasureMapTrade forBiome(TradeItem[] input, WeightedList<Object>
if (o == null) {
return null;
}
return ResourceOrTag.get(o.toString(), Registry.BIOME_REGISTRY);
return ResourceOrTag.get(o.toString(), Registries.BIOME);
});

MapPosInfo.Provider func = (level, entity) -> {
Expand Down Expand Up @@ -88,7 +88,7 @@ public TreasureMapTrade scale(byte scale) {
@Override
@Nullable
public MerchantOffer createOffer(Entity trader, RandomSource random) {
if (trader.getLevel() instanceof ServerLevel level) {
if (trader.level() instanceof ServerLevel level) {
MapPosInfo info = destinationPositionFunc.apply(level, trader);
if (info == null) return null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.almostreliable.morejs.mixin.enchanting;

import dev.latvian.mods.rhino.util.RemapForJS;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.enchantment.Enchantment;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -12,6 +12,6 @@ public class EnchantmentMixin {
@RemapForJS("getId")
public ResourceLocation morejs$getId() {
//noinspection ConstantConditions
return Registry.ENCHANTMENT.getKey((Enchantment) (Object) this);
return BuiltInRegistries.ENCHANTMENT.getKey((Enchantment) (Object) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.almostreliable.morejs.util.Utils;
import dev.latvian.mods.rhino.util.HideFromJS;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
Expand All @@ -31,7 +31,7 @@ public class StructureBlockInfoMixin implements StructureBlockInfoModification {

@Override
public String getId() {
return Registry.BLOCK.getKey(state.getBlock()).toString();
return BuiltInRegistries.BLOCK.getKey(state.getBlock()).toString();
}

@Override
Expand All @@ -41,7 +41,7 @@ public Block getBlock() {

@Override
public void setBlock(ResourceLocation id) {
Block block = Registry.BLOCK
Block block = BuiltInRegistries.BLOCK
.getOptional(id)
.orElseThrow(() -> new IllegalArgumentException("Block not found: " + id));
state = block.defaultBlockState();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.almostreliable.morejs.mixin.villager;

import com.almostreliable.morejs.features.villager.OfferExtension;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.MerchantScreen;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -35,11 +36,11 @@ public MerchantScreenMixin(MerchantMenu abstractContainerMenu, Inventory invento
}

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/trading/MerchantOffer;isOutOfStock()Z", ordinal = 0))
private void morejs$disableButtonsIfNeeded(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
private void morejs$disableButtonsIfNeeded(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
try {
var offer = this.menu.getOffers().get(this.shopItem);
if (morejs$offerIsDisabled(offer) && this.isHovering(186, 35, 22, 21, mouseX, mouseY)) {
this.renderTooltip(poseStack,
guiGraphics.renderTooltip(Minecraft.getInstance().font,
Component.literal("You don't meet the requirements to buy this item."),
mouseX,
mouseY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.datafixers.util.Pair;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.structure.Structure;
Expand All @@ -16,7 +16,7 @@ public class LevelUtils {
public static BlockPos findStructure(BlockPos position, ServerLevel level, ResourceOrTag<Structure> rot, int chunkRadius) {
return level
.registryAccess()
.registry(Registry.STRUCTURE_REGISTRY)
.registry(Registries.STRUCTURE)
.flatMap(rot::asHolderSet)
.map(holderSet -> level
.getChunkSource()
Expand Down
2 changes: 2 additions & 0 deletions Common/src/main/resources/morejs.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ accessible class net/minecraft/world/item/alchemy/PotionBrewing$Mix
accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix from Ljava/lang/Object;
accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix ingredient Lnet/minecraft/world/item/crafting/Ingredient;
accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix to Ljava/lang/Object;

accessible field net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate$StructureBlockInfo pos Lnet/minecraft/core/BlockPos;

0 comments on commit 82119f2

Please sign in to comment.