Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20 #81

Merged
merged 4 commits into from
Aug 7, 2024
Merged

1.20 #81

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Morphing-tool
The wrench to end all wrenches.

This mod requires [AutoRegLib](https://github.com/Vazkii/AutoRegLib).
The wrench to end all wrenches.
31 changes: 9 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -55,7 +46,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
morphtool {
source sourceSets.main
}
}
Expand All @@ -71,7 +62,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
morphtool {
source sourceSets.main
}
}
Expand All @@ -81,16 +72,12 @@ minecraft {

repositories {
maven {
// for AutoRegLib
name "blamejared"
url "https://maven.blamejared.com/"
url "https://cursemaven.com"
}
}

dependencies {
minecraft "net.minecraftforge:forge:${config.mc_version}-${config.forge_version}"

implementation fg.deobf("vazkii.autoreglib:AutoRegLib:${config.arl_version}")
}

spotless {
Expand Down
13 changes: 6 additions & 7 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#Wed Aug 07 17:27:15 UTC 2024
mapping_channel=official
forge_version=43.1.52
#Fri Feb 02 20:11:36 UTC 2024
mapping_channel=parchment
forge_version=47.1.3
mod_id=morphtool
dir_repo=./
build_number=38
arl_version=1.8.2-56.125
dir_output=../Build Output/Morphtool/
mapping_version=1.19.2
version=1.6
mapping_version=2023.09.03-1.20.1
version=1.7
mod_name=Morph-o-Tool
mc_version=1.19.2
mc_version=1.20.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -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/" }
}

}
16 changes: 9 additions & 7 deletions src/main/java/vazkii/morphtool/AttachementRecipe.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
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;
import net.minecraftforge.registries.ForgeRegistries;

public class AttachementRecipe extends CustomRecipe {

public AttachementRecipe(ResourceLocation idIn) {
super(idIn);
public AttachementRecipe(ResourceLocation idIn, CraftingBookCategory pCategory) {
super(idIn, pCategory);
}

@Override
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -124,7 +126,7 @@ public boolean isTarget(ItemStack stack) {
}

@Override
public ItemStack getResultItem() {
public ItemStack getResultItem(RegistryAccess pRegistryAccess) {
return ItemStack.EMPTY;
}

Expand All @@ -135,7 +137,7 @@ public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {

@Override
public RecipeSerializer<?> getSerializer() {
return ModItems.ATTACHMENT;
return Registries.ATTACHMENT.get();
}

}
14 changes: 7 additions & 7 deletions src/main/java/vazkii/morphtool/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Expand All @@ -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);
}

Expand All @@ -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();
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/vazkii/morphtool/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/vazkii/morphtool/ModItems.java

This file was deleted.

27 changes: 16 additions & 11 deletions src/main/java/vazkii/morphtool/MorphTool.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
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;
import net.minecraftforge.fml.common.Mod;
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);
}
}

}
25 changes: 9 additions & 16 deletions src/main/java/vazkii/morphtool/MorphToolItem.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package vazkii.morphtool;

import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos;
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;
Expand All @@ -14,18 +14,13 @@
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
Expand All @@ -46,13 +41,11 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List<Compone
}

CompoundTag data = stack.getTag().getCompound(MorphingHandler.TAG_MORPH_TOOL_DATA);
if (data.getAllKeys().size() == 0) {
if (data.getAllKeys().isEmpty()) {
return;
}

List<String> tooltipList = new ArrayList<>();

TooltipHandler.tooltipIfShift(tooltipList, () -> {
if (Screen.hasShiftDown()) {
for (String s : data.getAllKeys()) {
CompoundTag cmp = data.getCompound(s);
if (cmp != null) {
Expand All @@ -71,9 +64,9 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List<Compone
}
}
}
});

tooltipList.forEach(tip -> tooltip.add(Component.literal(tip)));
} else {
tooltip.add(Component.translatable(MorphTool.MOD_ID + ".misc.shift_for_info"));
}
}

}
Loading
Loading