From da364cfad0eff38c8829e14270d3956ea1eb66bf Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Mon, 5 Aug 2024 02:01:47 +0200 Subject: [PATCH] finished port --- README.md | 4 +-- build.gradle | 33 +++++++++--------- build.properties | 4 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 11 ++++++ .../vazkii/morphtool/AttachementRecipe.java | 16 +++++---- .../java/vazkii/morphtool/ClientHandler.java | 14 ++++---- .../java/vazkii/morphtool/ConfigHandler.java | 2 -- src/main/java/vazkii/morphtool/ModItems.java | 27 -------------- src/main/java/vazkii/morphtool/MorphTool.java | 27 ++++++++------ .../java/vazkii/morphtool/MorphToolItem.java | 30 +++++++--------- .../vazkii/morphtool/MorphingHandler.java | 29 ++++++--------- .../java/vazkii/morphtool/Registries.java | 18 ++++++++++ .../morphtool/network/MessageMorphTool.java | 30 ++++++++++------ .../morphtool/network/NetworkHandler.java | 26 ++++++++++++++ .../vazkii/morphtool/proxy/ClientProxy.java | 1 - .../vazkii/morphtool/proxy/CommonProxy.java | 1 - src/main/resources/META-INF/mods.toml | 15 +++----- .../assets/morphtool/lang/en_us.json | 3 +- .../assets/morphtool/models/item/tool.json | 6 ++-- .../textures/{items => item}/tool.png | Bin 21 files changed, 158 insertions(+), 141 deletions(-) create mode 100644 settings.gradle delete mode 100644 src/main/java/vazkii/morphtool/ModItems.java create mode 100644 src/main/java/vazkii/morphtool/Registries.java create mode 100644 src/main/java/vazkii/morphtool/network/NetworkHandler.java rename src/main/resources/assets/morphtool/textures/{items => item}/tool.png (100%) diff --git a/README.md b/README.md index 11497c4..3db9271 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,2 @@ # Morphing-tool -The wrench to end all wrenches. - -This mod requires [AutoRegLib](https://github.com/Vazkii/AutoRegLib). \ No newline at end of file +The wrench to end all wrenches. \ No newline at end of file diff --git a/build.gradle b/build.gradle index ddcf801..efa751b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,12 @@ -buildscript { - repositories { - maven { url = 'https://maven.minecraftforge.net' } - maven { url = 'https://repo.spongepowered.org/maven' } - jcenter() - mavenCentral() - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - } -} plugins { + id 'eclipse' + id 'maven-publish' + id 'pmd' id 'com.diffplug.spotless' version '5.12.5' + id 'net.minecraftforge.gradle' version '5.1.+' + id 'org.parchmentmc.librarian.forgegradle' version '1.+' + id 'org.spongepowered.mixin' version '0.7.+' } -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'eclipse' -apply plugin: 'maven-publish' -apply plugin: 'pmd' ext.configFile = file('build.properties') ext.config = parseConfig(configFile) @@ -55,7 +46,7 @@ minecraft { property 'forge.logging.console.level', 'debug' mods { - examplemod { + morphtool { source sourceSets.main } } @@ -71,7 +62,7 @@ minecraft { property 'forge.logging.console.level', 'debug' mods { - examplemod { + morphtool { source sourceSets.main } } @@ -79,8 +70,16 @@ minecraft { } } +repositories { + maven { + url "https://cursemaven.com" + } +} + dependencies { minecraft "net.minecraftforge:forge:${config.mc_version}-${config.forge_version}" + + implementation fg.deobf("curse.maven:create-328085:4625535") } spotless { diff --git a/build.properties b/build.properties index b65f91b..f7843c9 100644 --- a/build.properties +++ b/build.properties @@ -1,11 +1,11 @@ #Fri Feb 02 20:11:36 UTC 2024 -mapping_channel=official +mapping_channel=parchment forge_version=47.1.3 mod_id=morphtool dir_repo=./ build_number=36 dir_output=../Build Output/Morphtool/ -mapping_version=1.20.1 +mapping_version=2023.09.03-1.20.1 version=1.7 mod_name=Morph-o-Tool mc_version=1.20.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f371b17..52d9360 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e27d173 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,11 @@ +pluginManagement { + repositories { + gradlePluginPortal() + jcenter() + mavenCentral() + maven { url = 'https://maven.minecraftforge.net/' } + maven { url = 'https://maven.parchmentmc.org' } + maven { url = "https://repo.spongepowered.org/repository/maven-public/" } + } + +} \ No newline at end of file diff --git a/src/main/java/vazkii/morphtool/AttachementRecipe.java b/src/main/java/vazkii/morphtool/AttachementRecipe.java index bc28344..6b0adef 100644 --- a/src/main/java/vazkii/morphtool/AttachementRecipe.java +++ b/src/main/java/vazkii/morphtool/AttachementRecipe.java @@ -1,10 +1,12 @@ package vazkii.morphtool; import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingBookCategory; import net.minecraft.world.item.crafting.CustomRecipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.Level; @@ -12,8 +14,8 @@ public class AttachementRecipe extends CustomRecipe { - public AttachementRecipe(ResourceLocation idIn) { - super(idIn); + public AttachementRecipe(ResourceLocation idIn, CraftingBookCategory pCategory) { + super(idIn, pCategory); } @Override @@ -29,7 +31,7 @@ public boolean matches(CraftingContainer var1, Level var2) { return false; } foundTarget = true; - } else if (stack.getItem() == ModItems.tool) { + } else if (stack.is(Registries.MORPH_TOOL.get())) { if (foundTool) { return false; } @@ -44,14 +46,14 @@ public boolean matches(CraftingContainer var1, Level var2) { } @Override - public ItemStack assemble(CraftingContainer var1) { + public ItemStack assemble(CraftingContainer var1, RegistryAccess pRegistryAccess) { ItemStack tool = ItemStack.EMPTY; ItemStack target = ItemStack.EMPTY; for (int i = 0; i < var1.getContainerSize(); i++) { ItemStack stack = var1.getItem(i); if (!stack.isEmpty()) { - if (stack.getItem() == ModItems.tool) { + if (stack.is(Registries.MORPH_TOOL.get())) { tool = stack; } else { target = stack; @@ -124,7 +126,7 @@ public boolean isTarget(ItemStack stack) { } @Override - public ItemStack getResultItem() { + public ItemStack getResultItem(RegistryAccess pRegistryAccess) { return ItemStack.EMPTY; } @@ -135,7 +137,7 @@ public NonNullList getRemainingItems(CraftingContainer inv) { @Override public RecipeSerializer getSerializer() { - return ModItems.ATTACHMENT; + return Registries.ATTACHMENT.get(); } } diff --git a/src/main/java/vazkii/morphtool/ClientHandler.java b/src/main/java/vazkii/morphtool/ClientHandler.java index cd93a13..7bba066 100644 --- a/src/main/java/vazkii/morphtool/ClientHandler.java +++ b/src/main/java/vazkii/morphtool/ClientHandler.java @@ -15,8 +15,8 @@ import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; - import vazkii.morphtool.network.MessageMorphTool; +import vazkii.morphtool.network.NetworkHandler; import java.util.ArrayList; import java.util.Collections; @@ -39,16 +39,16 @@ public void onTick(ClientTickEvent event) { //Get looked at Mod if (res != null && res.getType() == HitResult.Type.BLOCK) { - BlockState state = player.level.getBlockState(((BlockHitResult) res).getBlockPos()); + BlockState state = player.level().getBlockState(((BlockHitResult) res).getBlockPos()); String modlook = MorphingHandler.getModFromState(state); //Morph tool to looked at Mod newStack = MorphingHandler.getShiftStackForMod(mainHandItem, modlook); } - if (newStack != mainHandItem && !ItemStack.isSame(newStack, mainHandItem)) { + if (newStack != mainHandItem && !ItemStack.isSameItemSameTags(newStack, mainHandItem)) { var inventory = player.getInventory(); inventory.setItem(ConfigHandler.invertHandShift.get() ? inventory.getContainerSize() - 1 : inventory.selected, newStack); - MorphTool.NETWORKHANDLER.sendToServer(new MessageMorphTool(newStack, inventory.selected)); + NetworkHandler.sendToServer(new MessageMorphTool(newStack, inventory.selected)); MorphTool.proxy.updateEquippedItem(); } } @@ -68,7 +68,7 @@ public void onMouseEvent(InputEvent.MouseScrollingEvent event) { //Get looked at Mod if (res != null && res.getType() == HitResult.Type.BLOCK) { - BlockState state = player.level.getBlockState(((BlockHitResult) res).getBlockPos()); + BlockState state = player.level().getBlockState(((BlockHitResult) res).getBlockPos()); modlook = MorphingHandler.getModFromState(state); } @@ -83,10 +83,10 @@ public void onMouseEvent(InputEvent.MouseScrollingEvent event) { } } - if (newStack != mainHandItem && !ItemStack.isSame(newStack, mainHandItem)) { + if (newStack != mainHandItem && !ItemStack.isSameItemSameTags(newStack, mainHandItem)) { var inventory = player.getInventory(); inventory.setItem(ConfigHandler.invertHandShift.get() ? inventory.getContainerSize() - 1 : inventory.selected, newStack); - MorphTool.NETWORKHANDLER.sendToServer(new MessageMorphTool(newStack, inventory.selected)); + NetworkHandler.sendToServer(new MessageMorphTool(newStack, inventory.selected)); MorphTool.proxy.updateEquippedItem(); } } diff --git a/src/main/java/vazkii/morphtool/ConfigHandler.java b/src/main/java/vazkii/morphtool/ConfigHandler.java index 39a54f2..5d78105 100644 --- a/src/main/java/vazkii/morphtool/ConfigHandler.java +++ b/src/main/java/vazkii/morphtool/ConfigHandler.java @@ -2,9 +2,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.Lists; - import net.minecraftforge.common.ForgeConfigSpec; - import org.apache.commons.lang3.tuple.Pair; import java.util.List; diff --git a/src/main/java/vazkii/morphtool/ModItems.java b/src/main/java/vazkii/morphtool/ModItems.java deleted file mode 100644 index 4ad055b..0000000 --- a/src/main/java/vazkii/morphtool/ModItems.java +++ /dev/null @@ -1,27 +0,0 @@ -package vazkii.morphtool; - -import net.minecraft.core.Registry; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.crafting.RecipeSerializer; -import net.minecraft.world.item.crafting.SimpleRecipeSerializer; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.registries.RegisterEvent; -import vazkii.arl.util.RegistryHelper; - -public final class ModItems { - - public static final RecipeSerializer ATTACHMENT = new SimpleRecipeSerializer<>(AttachementRecipe::new); - - public static Item tool = null; - - @SubscribeEvent(priority = EventPriority.HIGHEST) - public static void onRegistryInit(RegisterEvent event) { - if(tool == null) { - tool = new MorphToolItem(); - - RegistryHelper.register(ATTACHMENT, MorphTool.MOD_ID + ":attachment", Registry.RECIPE_SERIALIZER_REGISTRY); - } - } - -} diff --git a/src/main/java/vazkii/morphtool/MorphTool.java b/src/main/java/vazkii/morphtool/MorphTool.java index d610071..4a396a2 100644 --- a/src/main/java/vazkii/morphtool/MorphTool.java +++ b/src/main/java/vazkii/morphtool/MorphTool.java @@ -1,5 +1,7 @@ package vazkii.morphtool; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.ModLoadingContext; @@ -7,34 +9,37 @@ import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.network.NetworkDirection; -import vazkii.arl.network.NetworkHandler; -import vazkii.morphtool.network.MessageMorphTool; +import vazkii.morphtool.network.NetworkHandler; import vazkii.morphtool.proxy.ClientProxy; import vazkii.morphtool.proxy.CommonProxy; @Mod(MorphTool.MOD_ID) public class MorphTool { - public static final String MOD_ID = "morphtool"; - public static NetworkHandler NETWORKHANDLER; public static CommonProxy proxy; public MorphTool() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::commonSetup); - bus.register(ModItems.class); - + + Registries.ITEMS.register(bus); + Registries.SERIALIZERS.register(bus); + + bus.addListener(this::addToCreativeTab); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigHandler.CONFIG_SPEC); - proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new); + proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new); proxy.preInit(); + } - NETWORKHANDLER = new NetworkHandler(MOD_ID, 1); + private void commonSetup(FMLCommonSetupEvent event) { + NetworkHandler.register(); } - public void commonSetup(FMLCommonSetupEvent event) { - NETWORKHANDLER.register(MessageMorphTool.class, NetworkDirection.PLAY_TO_SERVER); + private void addToCreativeTab(BuildCreativeModeTabContentsEvent event) { + if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) { + event.accept(Registries.MORPH_TOOL); + } } } diff --git a/src/main/java/vazkii/morphtool/MorphToolItem.java b/src/main/java/vazkii/morphtool/MorphToolItem.java index 05b7691..4bca2ee 100644 --- a/src/main/java/vazkii/morphtool/MorphToolItem.java +++ b/src/main/java/vazkii/morphtool/MorphToolItem.java @@ -1,35 +1,31 @@ package vazkii.morphtool; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionResult; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.world.level.block.state.BlockState; - -import vazkii.arl.item.BasicItem; -import vazkii.arl.util.TooltipHandler; import javax.annotation.Nullable; - -import java.util.ArrayList; import java.util.List; -public class MorphToolItem extends BasicItem { +public class MorphToolItem extends Item { public MorphToolItem() { - super("morphtool:tool", new Properties().stacksTo(1).tab(CreativeModeTab.TAB_TOOLS)); + super(new Properties().stacksTo(1)); } @Override public InteractionResult useOn(UseOnContext context) { + /*TODO decide if this feature should be kept. The below code doesn't work since 1.19, no one has complained so far tho. BlockState block = context.getLevel().getBlockState(context.getClickedPos()); block.rotate(context.getLevel(), context.getClickedPos(), Rotation.CLOCKWISE_90); + + */ return super.useOn(context); } @@ -40,13 +36,11 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltipList = new ArrayList<>(); - - TooltipHandler.tooltipIfShift(tooltipList, () -> { + if (Screen.hasShiftDown()) { for (String s : data.getAllKeys()) { CompoundTag cmp = data.getCompound(s); if (cmp != null) { @@ -65,9 +59,9 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip.add(Component.literal(tip))); + } else { + tooltip.add(Component.translatable(MorphTool.MOD_ID + ".misc.shift_for_info")); + } } } diff --git a/src/main/java/vazkii/morphtool/MorphingHandler.java b/src/main/java/vazkii/morphtool/MorphingHandler.java index 61f2285..de2ef68 100644 --- a/src/main/java/vazkii/morphtool/MorphingHandler.java +++ b/src/main/java/vazkii/morphtool/MorphingHandler.java @@ -1,10 +1,5 @@ package vazkii.morphtool; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.function.Consumer; - import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -25,6 +20,11 @@ import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.registries.ForgeRegistries; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.function.Consumer; + public final class MorphingHandler { public static final MorphingHandler INSTANCE = new MorphingHandler(); @@ -52,7 +52,7 @@ public void onItemBroken(PlayerDestroyItemEvent event) { } public static void removeItemFromTool(Entity e, ItemStack stack, boolean itemBroken, Consumer consumer) { - if (stack != null && !stack.isEmpty() && isMorphTool(stack) && stack.getItem() != ModItems.tool) { + if (stack != null && !stack.isEmpty() && isMorphTool(stack) && !stack.is(Registries.MORPH_TOOL.get())) { CompoundTag morphData = stack.getTag().getCompound(TAG_MORPH_TOOL_DATA).copy(); ItemStack morph = makeMorphedStack(stack, MINECRAFT, morphData); @@ -73,15 +73,6 @@ public static void removeItemFromTool(Entity e, ItemStack stack, boolean itemBro } copyCmp.remove("display"); - Component displayName = null; - CompoundTag nameCmp = (CompoundTag) copyCmp.get(TAG_MORPH_TOOL_DISPLAY_NAME); - if (nameCmp != null) { - displayName = Component.literal(nameCmp.getString("text")); - } - if (displayName != null && !displayName.getString().isEmpty() && displayName != copy.getHoverName()) { - copy.setHoverName(displayName); - } - copyCmp.remove(TAG_MORPHING_TOOL); copyCmp.remove(TAG_MORPH_TOOL_DISPLAY_NAME); copyCmp.remove(TAG_MORPH_TOOL_DATA); @@ -146,14 +137,14 @@ public static ItemStack makeMorphedStack(ItemStack currentStack, String targetMo ItemStack stack; if (targetMod.equals(MINECRAFT)) { - stack = new ItemStack(ModItems.tool); + stack = new ItemStack(Registries.MORPH_TOOL.get()); } else { CompoundTag targetCmp = morphData.getCompound(targetMod); morphData.remove(targetMod); stack = ItemStack.of(targetCmp); if (stack.isEmpty()) { - stack = new ItemStack(ModItems.tool); + stack = new ItemStack(Registries.MORPH_TOOL.get()); } } @@ -165,7 +156,7 @@ public static ItemStack makeMorphedStack(ItemStack currentStack, String targetMo stackCmp.put(TAG_MORPH_TOOL_DATA, morphData); stackCmp.putBoolean(TAG_MORPHING_TOOL, true); - if (stack.getItem() != ModItems.tool) { + if (!stack.is(Registries.MORPH_TOOL.get())) { CompoundTag displayName = new CompoundTag(); CompoundTag ogDisplayName = displayName; displayName.putString("text", Component.Serializer.toJson(stack.getHoverName())); @@ -209,7 +200,7 @@ public static boolean isMorphTool(ItemStack stack) { return false; } - if (stack.getItem() == ModItems.tool) { + if (stack.is(Registries.MORPH_TOOL.get())) { return true; } diff --git a/src/main/java/vazkii/morphtool/Registries.java b/src/main/java/vazkii/morphtool/Registries.java new file mode 100644 index 0000000..c920200 --- /dev/null +++ b/src/main/java/vazkii/morphtool/Registries.java @@ -0,0 +1,18 @@ +package vazkii.morphtool; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +public final class Registries { + public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MorphTool.MOD_ID); + public static final DeferredRegister> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MorphTool.MOD_ID); + + public static final RegistryObject MORPH_TOOL = ITEMS.register("tool", MorphToolItem::new); + + public static final RegistryObject> ATTACHMENT = SERIALIZERS.register("attachment", () -> new SimpleCraftingRecipeSerializer<>(AttachementRecipe::new)); + +} diff --git a/src/main/java/vazkii/morphtool/network/MessageMorphTool.java b/src/main/java/vazkii/morphtool/network/MessageMorphTool.java index a4f285d..6ae17dc 100644 --- a/src/main/java/vazkii/morphtool/network/MessageMorphTool.java +++ b/src/main/java/vazkii/morphtool/network/MessageMorphTool.java @@ -1,18 +1,16 @@ package vazkii.morphtool.network; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraftforge.network.NetworkEvent; - -import vazkii.arl.network.IMessage; import vazkii.morphtool.ConfigHandler; import vazkii.morphtool.MorphingHandler; -@SuppressWarnings("serial") -public class MessageMorphTool implements IMessage { +import java.util.function.Supplier; - // non-final due to ARL doing serde funkily +public class MessageMorphTool { public ItemStack stack; public int slot; @@ -23,18 +21,30 @@ public MessageMorphTool(ItemStack stack, int slot) { this.slot = slot; } - @Override - public boolean receive(NetworkEvent.Context context) { + public static void serialize(final MessageMorphTool msg, final FriendlyByteBuf buf) { + buf.writeItem(msg.stack); + buf.writeVarInt(msg.slot); + } + + public static MessageMorphTool deserialize(final FriendlyByteBuf buf) { + final MessageMorphTool msg = new MessageMorphTool(); + msg.stack = buf.readItem(); + msg.slot = buf.readVarInt(); + return msg; + } + + public static void handle(MessageMorphTool msg, Supplier ctx) { + NetworkEvent.Context context = ctx.get(); Player player = context.getSender(); if (player != null) { context.enqueueWork(() -> { ItemStack mainHandItem = player.getItemInHand(ConfigHandler.invertHandShift.get() ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND); - if (MorphingHandler.isMorphTool(mainHandItem) && stack != mainHandItem && !ItemStack.isSame(stack, mainHandItem)) { + if (MorphingHandler.isMorphTool(mainHandItem) && msg.stack != mainHandItem && !ItemStack.isSameItem(msg.stack, mainHandItem)) { var inventory = player.getInventory(); - inventory.setItem(ConfigHandler.invertHandShift.get() ? inventory.getContainerSize() - 1 : slot, stack); + inventory.setItem(ConfigHandler.invertHandShift.get() ? inventory.getContainerSize() - 1 : msg.slot, msg.stack); } }); } - return true; + context.setPacketHandled(true); } } diff --git a/src/main/java/vazkii/morphtool/network/NetworkHandler.java b/src/main/java/vazkii/morphtool/network/NetworkHandler.java new file mode 100644 index 0000000..7477b7d --- /dev/null +++ b/src/main/java/vazkii/morphtool/network/NetworkHandler.java @@ -0,0 +1,26 @@ +package vazkii.morphtool.network; + +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.simple.SimpleChannel; +import vazkii.morphtool.MorphTool; + +public class NetworkHandler { + private static SimpleChannel channel; + private static int id = 0; + + public static void register() { + final String protocolVersion = "1"; + channel = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(MorphTool.MOD_ID, "main")) + .networkProtocolVersion(() -> protocolVersion) + .clientAcceptedVersions(protocolVersion::equals) + .serverAcceptedVersions(protocolVersion::equals) + .simpleChannel(); + channel.registerMessage(id++, MessageMorphTool.class, MessageMorphTool::serialize, MessageMorphTool::deserialize, MessageMorphTool::handle); + } + + public static void sendToServer(MSG msg) { + channel.sendToServer(msg); + } + +} diff --git a/src/main/java/vazkii/morphtool/proxy/ClientProxy.java b/src/main/java/vazkii/morphtool/proxy/ClientProxy.java index 626d329..18c27ba 100644 --- a/src/main/java/vazkii/morphtool/proxy/ClientProxy.java +++ b/src/main/java/vazkii/morphtool/proxy/ClientProxy.java @@ -3,7 +3,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.world.InteractionHand; import net.minecraftforge.common.MinecraftForge; - import vazkii.morphtool.ClientHandler; import vazkii.morphtool.ConfigHandler; diff --git a/src/main/java/vazkii/morphtool/proxy/CommonProxy.java b/src/main/java/vazkii/morphtool/proxy/CommonProxy.java index 9307501..1ea7cb9 100644 --- a/src/main/java/vazkii/morphtool/proxy/CommonProxy.java +++ b/src/main/java/vazkii/morphtool/proxy/CommonProxy.java @@ -1,7 +1,6 @@ package vazkii.morphtool.proxy; import net.minecraftforge.common.MinecraftForge; - import vazkii.morphtool.MorphingHandler; public class CommonProxy { diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 31df860..4087e2d 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[40,)" +loaderVersion="[47,)" issueTrackerURL="https://github.com/Vazkii/Morph-o-Tool" license="Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License" @@ -7,20 +7,13 @@ license="Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported Lice modId="morphtool" displayName="Morph-o-Tool" version="${file.jarVersion}" -authors="Vazkii, MoreThanHidden" +authors="Vazkii, MoreThanHidden, Uraneptus" description=''' -The wrench to end all wrenches. -''' -[[dependencies.morphtool]] - modId="autoreglib" - mandatory=true - versionRange="[1.7-52,)" - ordering="AFTER" - side="BOTH" +The wrench to end all wrenches.''' [[dependencies.morphtool]] modId="forge" mandatory=true - versionRange="[38.0.17,)" + versionRange="[47.1.0,)" ordering="AFTER" side="BOTH" diff --git a/src/main/resources/assets/morphtool/lang/en_us.json b/src/main/resources/assets/morphtool/lang/en_us.json index c6a2b7e..109f52c 100644 --- a/src/main/resources/assets/morphtool/lang/en_us.json +++ b/src/main/resources/assets/morphtool/lang/en_us.json @@ -1,4 +1,5 @@ { "morphtool.sudo_name": "Morphing Tool (%s)", - "item.morphtool.tool": "Morphing Tool" + "item.morphtool.tool": "Morphing Tool", + "morphtool.misc.shift_for_info": "§7Hold §bSHIFT§7 for more info" } \ No newline at end of file diff --git a/src/main/resources/assets/morphtool/models/item/tool.json b/src/main/resources/assets/morphtool/models/item/tool.json index 28af368..a9ca97a 100644 --- a/src/main/resources/assets/morphtool/models/item/tool.json +++ b/src/main/resources/assets/morphtool/models/item/tool.json @@ -1,6 +1,6 @@ { - "parent": "item/handheld", - "textures": { - "layer0": "morphtool:items/tool" + "parent": "minecraft:item/handheld", + "textures": { + "layer0": "morphtool:item/tool" } } diff --git a/src/main/resources/assets/morphtool/textures/items/tool.png b/src/main/resources/assets/morphtool/textures/item/tool.png similarity index 100% rename from src/main/resources/assets/morphtool/textures/items/tool.png rename to src/main/resources/assets/morphtool/textures/item/tool.png