Skip to content

Commit

Permalink
1.19.2 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
frqnny committed Mar 30, 2023
1 parent 045898b commit 99e2996
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 70 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.18

#Fabric api
fabric_version=0.76.0+1.19.4
fabric_version=0.76.0+1.19.2

# Dependencies
libgui_version=7.0.0-beta.2+1.19.4
libgui_version=6.4.0+1.19
config_version=1.2.3-1.18.1
# Mod Properties
mod_version = 1.0.1+1.19.4
mod_version = 1.0.1+1.19.2
maven_group = io.github.frqnny
archives_base_name = dark-enchanting
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import io.github.frqnny.darkenchanting.config.DarkEnchantingConfig;
import io.github.frqnny.darkenchanting.init.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

public class DarkEnchanting implements ModInitializer {
public static final String MODID = "dark-enchanting";

public static final ItemGroup DARK_ENCHANTING = FabricItemGroup.builder(new Identifier(MODID, "dark_enchanting_group"))
public static final ItemGroup DARK_ENCHANTING = FabricItemGroupBuilder.create(new Identifier(MODID, "dark_enchanting_group"))
.icon(() -> new ItemStack(ModBlocks.DARK_ENCHANTER))
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.frqnny.darkenchanting;

import io.github.frqnny.darkenchanting.client.renderer.DarkEnchanterBlockEntityRenderer;
import io.github.frqnny.darkenchanting.init.ModBlocks;
import io.github.frqnny.darkenchanting.init.ModGUIs;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.minecraft.block.Block;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.screen.PlayerScreenHandler;

public class DarkEnchantingClient implements ClientModInitializer {

Expand All @@ -17,6 +20,7 @@ public static void registerCutout(Block block) {
public void onInitializeClient() {
ModGUIs.clientInit();
ModBlocks.clientInit();
ClientSpriteRegistryCallback.event(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE).register((atlas, registry) -> registry.register(DarkEnchanterBlockEntityRenderer.BOOK_ID));

registerCutout(ModBlocks.DARK_TORCH);
registerCutout(ModBlocks.DARK_TORCH_WALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void populateList() {
return;
}
Object2IntMap<Enchantment> enchantments = new Object2IntOpenHashMap<>(EnchantmentHelper.get(stack));
for (Enchantment enchantment : Registries.ENCHANTMENT) {
for (Enchantment enchantment : Registry.ENCHANTMENT) {
Optional<ConfigEnchantment> configEnchantmentOptional = ConfigEnchantment.getConfigEnchantmentFor(enchantment);

if (configEnchantmentOptional.isPresent()) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public void enchant() {
buf.writeBlockPos(pos);
buf.writeVarInt(enchantmentsToApply.size());
for (var entry : enchantmentsToApply.object2IntEntrySet()) {
buf.writeIdentifier(Registries.ENCHANTMENT.getId(entry.getKey()));
buf.writeIdentifier(Registry.ENCHANTMENT.getId(entry.getKey()));
buf.writeVarInt(entry.getIntValue());
}

Expand Down Expand Up @@ -314,8 +314,8 @@ public void onStackUpdate(ItemStack stack) {
}

@Override
public void onClosed(PlayerEntity player) {
super.onClosed(player);
public void close(PlayerEntity player) {
super.close(player);
this.context.run((world, pos) -> this.dropInventory(player, this.inv));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3f;


@Environment(EnvType.CLIENT)
public class DarkEnchanterBlockEntityRenderer implements BlockEntityRenderer<DarkEnchanterBlockEntity> {
Expand Down Expand Up @@ -45,8 +46,8 @@ public void render(DarkEnchanterBlockEntity blockEntity, float tickDelta, Matrix
}

float newBookRotation = blockEntity.bookRotationPrev + bookRotationChange * tickDelta;
matrices.multiply(RotationAxis.POSITIVE_Y.rotation(-newBookRotation));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(80.0F));
matrices.multiply(Vec3f.POSITIVE_Y.getRadialQuaternion(-newBookRotation));
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(80.0F));
float newPageAngle = MathHelper.lerp(tickDelta, blockEntity.pageAngle, blockEntity.nextPageAngle);
float m = MathHelper.fractionalPart(newPageAngle + 0.25F) * 1.6F - 0.3F;
float n = MathHelper.fractionalPart(newPageAngle + 0.75F) * 1.6F - 0.3F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.github.frqnny.darkenchanting.DarkEnchanting;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.Optional;

Expand Down Expand Up @@ -37,6 +37,6 @@ public static Optional<ConfigEnchantment> getConfigEnchantmentFor(Identifier id)
}

public static Optional<ConfigEnchantment> getConfigEnchantmentFor(Enchantment enchantment) {
return getConfigEnchantmentFor(Registries.ENCHANTMENT.getId(enchantment));
return getConfigEnchantmentFor(Registry.ENCHANTMENT.getId(enchantment));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.registry.Registry;

public class ModBlocks {

Expand All @@ -22,10 +21,10 @@ public class ModBlocks {
public static final BlockEntityType<DarkEnchanterBlockEntity> DE_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(DarkEnchanterBlockEntity::new, DARK_ENCHANTER).build();

public static void init() {
Registry.register(Registries.BLOCK, DarkConduitBlock.ID, DARK_TORCH);
Registry.register(Registries.BLOCK, WallDarkConduitBlock.ID, DARK_TORCH_WALL);
Registry.register(Registries.BLOCK, DarkEnchanterBlock.ID, DARK_ENCHANTER);
Registry.register(Registries.BLOCK_ENTITY_TYPE, DarkEnchanterBlock.ID, DE_BLOCK_ENTITY);
Registry.register(Registry.BLOCK, DarkConduitBlock.ID, DARK_TORCH);
Registry.register(Registry.BLOCK, WallDarkConduitBlock.ID, DARK_TORCH_WALL);
Registry.register(Registry.BLOCK, DarkEnchanterBlock.ID, DARK_ENCHANTER);
Registry.register(Registry.BLOCK_ENTITY_TYPE, DarkEnchanterBlock.ID, DE_BLOCK_ENTITY);
}

public static void clientInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import io.github.frqnny.darkenchanting.client.gui.DarkEnchanterGUI;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.registry.Registry;

public class ModGUIs {
public static final ScreenHandlerType<DarkEnchanterGUI> DARK_ENCHANTER_GUI = new ExtendedScreenHandlerType<>((syncId, inventory, buf) -> new DarkEnchanterGUI(syncId, inventory, ScreenHandlerContext.create(inventory.player.world, buf.readBlockPos())));

public static void init() {
Registry.register(Registries.SCREEN_HANDLER, DarkEnchanting.id("dark_enchanter_gui"), DARK_ENCHANTER_GUI);
Registry.register(Registry.SCREEN_HANDLER, DarkEnchanting.id("dark_enchanter_gui"), DARK_ENCHANTER_GUI);
}

@SuppressWarnings("all")
Expand Down
38 changes: 8 additions & 30 deletions src/main/java/io/github/frqnny/darkenchanting/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,23 @@
import io.github.frqnny.darkenchanting.block.DarkEnchanterBlock;
import io.github.frqnny.darkenchanting.item.TableUpgradeItem;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.item.VerticallyAttachableBlockItem;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.item.WallStandingBlockItem;
import net.minecraft.util.Rarity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;

public class ModItems {

public static final Item DARK_ENCHANTER = new BlockItem(ModBlocks.DARK_ENCHANTER, new FabricItemSettings());
public static final Item DARK_TORCH = new VerticallyAttachableBlockItem(ModBlocks.DARK_TORCH, ModBlocks.DARK_TORCH_WALL, new FabricItemSettings(), Direction.DOWN);
public static final Item TABLE_UPGRADE = new TableUpgradeItem(new FabricItemSettings().maxCount(1).rarity(Rarity.EPIC));
public static final Item DARK_ENCHANTER = new BlockItem(ModBlocks.DARK_ENCHANTER, new FabricItemSettings().group(DarkEnchanting.DARK_ENCHANTING));
public static final Item DARK_TORCH = new WallStandingBlockItem(ModBlocks.DARK_TORCH, ModBlocks.DARK_TORCH_WALL, new FabricItemSettings().group(DarkEnchanting.DARK_ENCHANTING));
public static final Item TABLE_UPGRADE = new TableUpgradeItem(new FabricItemSettings().group(DarkEnchanting.DARK_ENCHANTING).maxCount(1).rarity(Rarity.EPIC));

public static void init() {
Registry.register(Registries.ITEM, DarkEnchanterBlock.ID, DARK_ENCHANTER);
Registry.register(Registries.ITEM, DarkConduitBlock.ID, DARK_TORCH);
Registry.register(Registries.ITEM, TableUpgradeItem.ID, TABLE_UPGRADE);
ItemGroupEvents.modifyEntriesEvent(DarkEnchanting.DARK_ENCHANTING).register(ModItems::addDarkEnchantingBlocks);
ItemGroupEvents.modifyEntriesEvent(DarkEnchanting.DARK_ENCHANTING).register(ModItems::addFunctionalBlocks);
ItemGroupEvents.modifyEntriesEvent(DarkEnchanting.DARK_ENCHANTING).register(ModItems::addTools);
Registry.register(Registry.ITEM, DarkEnchanterBlock.ID, DARK_ENCHANTER);
Registry.register(Registry.ITEM, DarkConduitBlock.ID, DARK_TORCH);
Registry.register(Registry.ITEM, TableUpgradeItem.ID, TABLE_UPGRADE);
}

private static void addDarkEnchantingBlocks(FabricItemGroupEntries entries) {
entries.add(DARK_ENCHANTER);
entries.add(DARK_TORCH);
entries.add(TABLE_UPGRADE);
}

private static void addFunctionalBlocks(FabricItemGroupEntries entries) {
entries.addAfter(Items.SOUL_TORCH, DARK_TORCH);
entries.addAfter(Items.ENCHANTING_TABLE, DARK_ENCHANTER);
}

private static void addTools(FabricItemGroupEntries entries) {
entries.addBefore(Items.ENDER_EYE, TABLE_UPGRADE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;

public class ModPackets {
public static final Identifier APPLY_ENCHANTMENTS = DarkEnchanting.id("apply_enchantments");
Expand All @@ -33,7 +33,7 @@ public static void init() {

for (int i = 0; i < size; i++) {
Identifier id = buf.readIdentifier();
Enchantment enchantment = Registries.ENCHANTMENT.get(id);
Enchantment enchantment = Registry.ENCHANTMENT.get(id);
int level = buf.readVarInt();
enchantmentsToApply.put(enchantment, level);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/github/frqnny/darkenchanting/init/ModTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import io.github.frqnny.darkenchanting.DarkEnchanting;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class ModTags {
public static final TagKey<Block> BOOKSHELVES = TagKey.of(RegistryKeys.BLOCK, new Identifier("c", "bookshelves"));
public static final TagKey<Enchantment> DISABLED = TagKey.of(RegistryKeys.ENCHANTMENT, DarkEnchanting.id("enchantment/disabled"));
public static final TagKey<Block> CRYING_OBSIDIAN = TagKey.of(RegistryKeys.BLOCK, DarkEnchanting.id("crying_obsidian"));
public static final TagKey<Block> BOOKSHELVES = TagKey.of(Registry.BLOCK_KEY, new Identifier("c", "bookshelves"));
public static final TagKey<Enchantment> DISABLED = TagKey.of(Registry.ENCHANTMENT_KEY, DarkEnchanting.id("enchantment/disabled"));
public static final TagKey<Block> CRYING_OBSIDIAN = TagKey.of(Registry.BLOCK_KEY, DarkEnchanting.id("crying_obsidian"));

public static void init() {
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/io/github/frqnny/darkenchanting/util/TagUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import io.github.frqnny.darkenchanting.init.ModTags;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;

public class TagUtils {

public static boolean isEnchantmentDisabled(World world, Enchantment enchantment) {
Registry<Enchantment> registry = world.getRegistryManager().get(RegistryKeys.ENCHANTMENT);
RegistryEntry.Reference<Enchantment> regEntry = registry.entryOf(RegistryKey.of(RegistryKeys.ENCHANTMENT, Registries.ENCHANTMENT.getId(enchantment)));
Registry<Enchantment> registry = world.getRegistryManager().get(Registry.ENCHANTMENT_KEY);
RegistryEntry<Enchantment> regEntry = registry.entryOf(RegistryKey.of(Registry.ENCHANTMENT_KEY, Registry.ENCHANTMENT.getId(enchantment)));
return regEntry.isIn(ModTags.DISABLED);
}
}

0 comments on commit 99e2996

Please sign in to comment.