Moved the white wool recipe in a safer place, added config options and updated the README

master
Wynd 2024-01-08 01:20:43 +02:00
parent 8e7c3b4b13
commit 4a76c0fc82
7 changed files with 69 additions and 25 deletions

View File

@ -71,6 +71,18 @@ Real life days are calculated differently from the world time but are stored in
</details> </details>
<details><summary>Items can now be repaired at crafting tables</summary>
<video controls src="https://i.imgur.com/UrLHQDh.mp4" />
</details>
<details><summary>Dyed wool can be turned back into white wool using bone meal</summary>
<video controls src="https://i.imgur.com/Uwk3K2t.mp4" />
</details>
### Fixes ### Fixes
<details><summary>Fixes selected blocks being rendered under text in containers</summary> <details><summary>Fixes selected blocks being rendered under text in containers</summary>

View File

@ -1,33 +1,11 @@
package xyz.pixelatedw.finalbeta; package xyz.pixelatedw.finalbeta;
import java.lang.reflect.Method;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import net.minecraft.recipe.RecipeRegistry;
import net.minecraft.tile.Tile;
import net.minecraft.tile.WoolTile;
public class MainMod implements ModInitializer { public class MainMod implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
ModConfig.instance(); ModConfig.instance();
this.addWhiteWoolRecipe();
}
private void addWhiteWoolRecipe() {
Method method = RecipeRegistry.class.getDeclaredMethods()[2];
method.setAccessible(true);
try {
// Makes new recipes for all colored wools so they can be dyed back white using bone meal
for (int colorId = 0; colorId < 16; ++colorId) {
method.invoke(RecipeRegistry.getInstance(), new ItemInstance(Tile.WOOL, 1, 0), new Object[]{
new ItemInstance(Tile.WOOL, 1, WoolTile.method_2(colorId)), new ItemInstance(ItemType.dyePowder, 1, 15)});
}
} catch (Exception ex) {
ex.printStackTrace();
}
} }
} }

View File

@ -32,6 +32,10 @@ public class ModConfig {
"Allows the player to drop the entire stack they're holding using Shift + Q (or whatever drop key they have set)"); "Allows the player to drop the entire stack they're holding using Shift + Q (or whatever drop key they have set)");
public static final Option<Boolean> ENABLE_TIME_TRACKING = make("Enable Time Tracking", true, public static final Option<Boolean> ENABLE_TIME_TRACKING = make("Enable Time Tracking", true,
"Adds a Days Played entry in the F3 overlay displaying number of ingame days and real life days played in that world"); "Adds a Days Played entry in the F3 overlay displaying number of ingame days and real life days played in that world");
public static final Option<Boolean> ENABLE_REPAIR = make("Enable Item Repair", true,
"Allows 2 or more items of the same type to be repaired using a crafting table using the same formula as modern day vanilla uses");
public static final Option<Boolean> ENABLE_WHITE_WOOL_RECIPE = make("Enable White Wool Recipe", true,
"Allows dyed wool to be dyed back white using bone meal");
public static final Option<Boolean> FIX_BOW_MODEL = make("Fix bow model", true, public static final Option<Boolean> FIX_BOW_MODEL = make("Fix bow model", true,
"Makes the box model held by players and skeletons bigger and facing forward"); "Makes the box model held by players and skeletons bigger and facing forward");

View File

@ -2,11 +2,17 @@ package xyz.pixelatedw.finalbeta;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.time.Duration; import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import net.minecraft.recipe.RecipeRegistry;
import net.minecraft.tile.Tile;
import net.minecraft.tile.WoolTile;
public class WyHelper { public class WyHelper {
@ -63,8 +69,21 @@ public class WyHelper {
return val < min ? min : Math.min(val, max); return val < min ? min : Math.min(val, max);
} }
public static void registerWhiteWoolRecipe() {
Method method = RecipeRegistry.class.getDeclaredMethods()[2];
method.setAccessible(true);
try {
// Makes new recipes for all colored wools so they can be dyed back white using bone meal
for (int colorId = 0; colorId < 16; ++colorId) {
method.invoke(RecipeRegistry.getInstance(), new ItemInstance(Tile.WOOL, 1, 0), new Object[]{
new ItemInstance(Tile.WOOL, 1, WoolTile.method_2(colorId)), new ItemInstance(ItemType.dyePowder, 1, 15)});
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void cheatCommand(Player player) { public static void cheatCommand(Player player) {
// player.level.setLevelTime(0); // player.level.setLevelTime(0);
// player.level.getProperties().setRaining(false); // player.level.getProperties().setRaining(false);
// player.level.getProperties().setRainTime(0); // player.level.getProperties().setRainTime(0);

View File

@ -8,12 +8,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.container.CraftingContainer; import net.minecraft.container.CraftingContainer;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemInstance; import net.minecraft.item.ItemInstance;
import xyz.pixelatedw.finalbeta.ModConfig;
@Mixin(CraftingContainer.class) @Mixin(CraftingContainer.class)
public class CraftingContainerMixin { public class CraftingContainerMixin {
@Inject(method = "onContentsChanged", at = @At("HEAD"), cancellable = true) @Inject(method = "onContentsChanged", at = @At("HEAD"), cancellable = true)
public void onContentsChanged(Inventory inventory, CallbackInfo ci) { public void onContentsChanged(Inventory inventory, CallbackInfo ci) {
if (!ModConfig.ENABLE_REPAIR.get()) {
return;
}
CraftingContainer container = ((CraftingContainer)(Object)this); CraftingContainer container = ((CraftingContainer)(Object)this);
ItemInstance resultItem = null; ItemInstance resultItem = null;

View File

@ -0,0 +1,25 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.container.Container;
import net.minecraft.inventory.CraftingInventory;
import xyz.pixelatedw.finalbeta.ModConfig;
import xyz.pixelatedw.finalbeta.WyHelper;
@Mixin(CraftingInventory.class)
public class CraftingInventoryMixin {
private static boolean hasCustomRecipesRegistered = false;
@Inject(method = "<init>", at = @At("TAIL"))
public void init(Container container, int x, int y, CallbackInfo ci) {
if (ModConfig.ENABLE_WHITE_WOOL_RECIPE.get() && !hasCustomRecipesRegistered) {
WyHelper.registerWhiteWoolRecipe();
hasCustomRecipesRegistered = true;
}
}
}

View File

@ -37,7 +37,8 @@
"LevelPropertiesMixin", "LevelPropertiesMixin",
"LevelMixin", "LevelMixin",
"DoorTileMixin", "DoorTileMixin",
"CraftingContainerMixin" "CraftingContainerMixin",
"CraftingInventoryMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": -1 "defaultRequire": -1