Compare commits

..

2 Commits

16 changed files with 160 additions and 104 deletions

View File

@ -9,6 +9,6 @@ plasma_build=22
api_version=1.1.0.1 api_version=1.1.0.1
# Mod Properties # Mod Properties
mod_version = 1.2.0 mod_version = 1.3.0
maven_group = xyz.pixelatedw.finalbeta maven_group = xyz.pixelatedw.finalbeta
archives_base_name = finalbeta archives_base_name = finalbeta

View File

@ -4,6 +4,10 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import net.minecraft.tile.Tile;
import net.minecraft.tile.WoolTile;
public class MainMod implements ModInitializer { public class MainMod implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
@ -11,5 +15,17 @@ public class MainMod implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
ModConfig.instance(); ModConfig.instance();
if (ModConfig.ENABLE_WHITE_WOOL_RECIPE.get()) {
for (int colorId = 0; colorId < 16; ++colorId) {
WyHelper.addShapelessRecipe(new ItemInstance(Tile.WOOL, 1, 0), new Object[]{
new ItemInstance(Tile.WOOL, 1, WoolTile.method_2(colorId)), new ItemInstance(ItemType.dyePowder, 1, 15)});
}
}
if (ModConfig.ENABLE_COAL_AND_REDSTONE_BLOCKS_RECIPE.get()) {
WyHelper.addShapedRecipe(new ItemInstance(ModTile.COAL_BLOCK, 1, 0), "###", "###", "###", '#', ItemType.coal);
WyHelper.addShapedRecipe(new ItemInstance(ModTile.REDSTONE_BLOCK, 1, 0), "###", "###", "###", '#', ItemType.redstone);
}
} }
} }

View File

@ -50,6 +50,8 @@ public class ModConfig {
"Name says it all, furnace minecarts will load chunks as they go on tracks."); "Name says it all, furnace minecarts will load chunks as they go on tracks.");
public static final Option<Double> CLOUDS_HEIGHT = make("Clouds Height", 0.0, public static final Option<Double> CLOUDS_HEIGHT = make("Clouds Height", 0.0,
"Clouds height modifier, goes from 0.0, meaning the default 108 blocks height, to 1.0, meaning a 324 blocks height."); "Clouds height modifier, goes from 0.0, meaning the default 108 blocks height, to 1.0, meaning a 324 blocks height.");
public static final Option<Boolean> ENABLE_COAL_AND_REDSTONE_BLOCKS_RECIPE = make("Enable Coal and Redstone Blocks Recipe", false,
"Allows crafting coal and redstone as blocks for better storage");
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

@ -0,0 +1,59 @@
package xyz.pixelatedw.finalbeta;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.item.ItemType;
import net.minecraft.item.PlaceableTileItem;
import net.minecraft.level.TileView;
import net.minecraft.tile.Tile;
import net.minecraft.tile.TileSounds;
import net.minecraft.tile.material.Material;
public class ModTile extends Tile {
public static final Tile REDSTONE_BLOCK = (new ModTile(100, 176, Material.STONE)).hardness(3.0F).blastResistance(5.0F).sounds(Tile.STONE_SOUNDS).tint(11149858).name("blockRedstone");
public static final Tile COAL_BLOCK = (new ModTile(101, 103, Material.STONE)).hardness(3.0F).blastResistance(5.0F).sounds(Tile.STONE_SOUNDS).tint(1118481).name("blockCoal");
static {
ItemType.byId[REDSTONE_BLOCK.id] = (new PlaceableTileItem(REDSTONE_BLOCK.id - 256)).setName("redstoneBlock");
ItemType.byId[COAL_BLOCK.id] = (new PlaceableTileItem(COAL_BLOCK.id - 256)).setName("coalBlock");
}
private int tint = 16777215;
public ModTile(int id, int texId, Material mat) {
super(id, texId, mat);
}
@Override
public ModTile hardness(float hardness) {
return (ModTile) super.hardness(hardness);
}
@Override
public ModTile blastResistance(float resistance) {
return (ModTile) super.blastResistance(resistance);
}
@Override
public ModTile sounds(TileSounds sounds) {
return (ModTile) super.sounds(sounds);
}
public ModTile tint(int tint) {
this.tint = tint;
return this;
}
@Override
@Environment(EnvType.CLIENT)
public int method_1589(int i) {
return this.tint;
}
@Override
@Environment(EnvType.CLIENT)
public int getTint(TileView tile, int x, int y, int z) {
return this.tint;
}
}

View File

@ -1,17 +1,17 @@
package xyz.pixelatedw.finalbeta; package xyz.pixelatedw.finalbeta;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
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.entity.player.Player; import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemInstance;
import net.minecraft.recipe.RecipeRegistry;
import xyz.pixelatedw.finalbeta.mixin.MinecraftAccessorMixin;
import xyz.pixelatedw.finalbeta.mixin.RecipeRegistryAccessorMixin;
public class WyHelper { public class WyHelper {
private static final Minecraft INSTANCE;
public static final String SPAWN_TIME_TAG = "SpawnTime"; public static final String SPAWN_TIME_TAG = "SpawnTime";
public static final String PLAY_TIME_TAG = "PlayTime"; public static final String PLAY_TIME_TAG = "PlayTime";
public static long playTime; public static long playTime;
@ -22,47 +22,12 @@ public class WyHelper {
public static final HashMap<Integer, Long> DOOR_UPDATES = new HashMap<>(); public static final HashMap<Integer, Long> DOOR_UPDATES = new HashMap<>();
public static final HashMap<Integer, Boolean> DOOR_STATES = new HashMap<>(); public static final HashMap<Integer, Boolean> DOOR_STATES = new HashMap<>();
static { public static void addShapedRecipe(ItemInstance result, Object... recipe) {
INSTANCE = getInstance(); ((RecipeRegistryAccessorMixin) RecipeRegistry.getInstance()).invokeAddShapedRecipe(result, recipe);
} }
public static Field getField(Class clz, String... names) { public static void addShapelessRecipe(ItemInstance result, Object... ingredients) {
for (String name : names) { ((RecipeRegistryAccessorMixin) RecipeRegistry.getInstance()).invokeAddShapelessRecipe(result, ingredients);
try {
Field field = clz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
continue;
}
}
return null;
}
public static Method getMethod(Class clz, String[] names, Class<?>... params) {
for (String name : names) {
try {
Method method = clz.getDeclaredMethod(name, params);
method.setAccessible(true);
return method;
} catch (NoSuchMethodException ex) {
continue;
}
}
return null;
}
public static Minecraft getInstance() {
if (INSTANCE != null) {
return INSTANCE;
} else {
try {
return (Minecraft) getField(Minecraft.class, "instance", "field_2791").get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
} }
public static long getRealDaysPlayed() { public static long getRealDaysPlayed() {
@ -71,7 +36,7 @@ public class WyHelper {
} }
public static long getGameDaysPlayed() { public static long getGameDaysPlayed() {
long seconds = WyHelper.getInstance().level.getLevelTime() / 20; long seconds = MinecraftAccessorMixin.getMinecraft().level.getLevelTime() / 20;
return Duration.ofSeconds(seconds).toMinutes() / 20; return Duration.ofSeconds(seconds).toMinutes() / 20;
} }

View File

@ -24,7 +24,7 @@ public class ClientPlayerMixin {
@Inject(method = "method_136", at = @At("TAIL")) @Inject(method = "method_136", at = @At("TAIL"))
public void onKeyPressed(int key, boolean state, CallbackInfo ci) { public void onKeyPressed(int key, boolean state, CallbackInfo ci) {
Minecraft mc = WyHelper.getInstance(); Minecraft mc = MinecraftAccessorMixin.getMinecraft();
Player player = (Player) (Object) this; Player player = (Player) (Object) this;
if (player.vehicle != null && key == Keyboard.KEY_LSHIFT && state) { if (player.vehicle != null && key == Keyboard.KEY_LSHIFT && state) {

View File

@ -1,52 +0,0 @@
package xyz.pixelatedw.finalbeta.mixin;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
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 net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import net.minecraft.recipe.RecipeRegistry;
import net.minecraft.tile.Tile;
import net.minecraft.tile.WoolTile;
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) {
registerWhiteWoolRecipe();
hasCustomRecipesRegistered = true;
}
}
private static void registerWhiteWoolRecipe() {
Method method = WyHelper.getMethod(RecipeRegistry.class, new String[] { "addShapelessRecipe", "method_542" }, ItemInstance.class, Object[].class);
if (method == null) {
return;
}
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 (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
ex.printStackTrace();
}
}
}

View File

@ -11,6 +11,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.animal.Chicken; import net.minecraft.entity.animal.Chicken;
import net.minecraft.entity.animal.Pig; import net.minecraft.entity.animal.Pig;
import net.minecraft.entity.monster.Ghast; import net.minecraft.entity.monster.Ghast;
import net.minecraft.entity.monster.Spider;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.Player;
import net.minecraft.entity.projectile.Snowball; import net.minecraft.entity.projectile.Snowball;
import net.minecraft.item.ItemType; import net.minecraft.item.ItemType;
@ -55,7 +56,8 @@ public class LivingEntityMixin {
@Inject(method = "travel", at = @At("HEAD")) @Inject(method = "travel", at = @At("HEAD"))
public void travel(float f, float f1, CallbackInfo ci) { public void travel(float f, float f1, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this; LivingEntity entity = (LivingEntity) (Object) this;
if (ModConfig.ADD_MORE_SOUNDS.get() && entity.isOnLadder() && (entity.velocityY > 0.1 || entity.velocityY < -0.1) && entity.field_1645 % 15 == 0 && !entity.onGround) { if (ModConfig.ADD_MORE_SOUNDS.get() && entity.isOnLadder() && !(entity instanceof Spider)
&& (entity.velocityY > 0.1 || entity.velocityY < -0.1) && entity.field_1645 % 15 == 0 && !entity.onGround) {
float pitch = WyHelper.clamp(0.85f + entity.level.rand.nextFloat() / 2, 0.0f, 1.0f); float pitch = WyHelper.clamp(0.85f + entity.level.rand.nextFloat() / 2, 0.0f, 1.0f);
entity.level.playSound(entity.x, entity.y, entity.z, "sound3.step.ladder", 0.3f, pitch); entity.level.playSound(entity.x, entity.y, entity.z, "sound3.step.ladder", 0.3f, pitch);
} }

View File

@ -0,0 +1,14 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.client.Minecraft;
@Mixin(Minecraft.class)
public interface MinecraftAccessorMixin {
@Accessor("instance")
public static Minecraft getMinecraft() {
throw new AssertionError();
}
}

View File

@ -0,0 +1,16 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.item.ItemInstance;
import net.minecraft.recipe.RecipeRegistry;
@Mixin(RecipeRegistry.class)
public interface RecipeRegistryAccessorMixin {
@Invoker("addShapedRecipe")
void invokeAddShapedRecipe(ItemInstance result, Object... shape);
@Invoker("addShapelessRecipe")
void invokeAddShapelessRecipe(ItemInstance result, Object... materials);
}

View File

@ -13,6 +13,7 @@ import net.minecraft.item.tool.ToolItem;
import net.minecraft.item.tool.ToolMaterial; import net.minecraft.item.tool.ToolMaterial;
import net.minecraft.tile.Tile; import net.minecraft.tile.Tile;
import xyz.pixelatedw.finalbeta.ModConfig; import xyz.pixelatedw.finalbeta.ModConfig;
import xyz.pixelatedw.finalbeta.ModTile;
@Mixin(ToolItem.class) @Mixin(ToolItem.class)
public class ToolItemMixin { public class ToolItemMixin {
@ -22,7 +23,8 @@ public class ToolItemMixin {
Tile.DIAMOND_ORE, Tile.BLOCK_DIAMOND, Tile.ICE, Tile.NETHERRACK, Tile.LAPIS_LAZULI_ORE, Tile.LAPIS_LAZULI_BLOCK, Tile.DIAMOND_ORE, Tile.BLOCK_DIAMOND, Tile.ICE, Tile.NETHERRACK, Tile.LAPIS_LAZULI_ORE, Tile.LAPIS_LAZULI_BLOCK,
// Here starts the list of blocks that are not affected by default // Here starts the list of blocks that are not affected by default
Tile.STAIRS_STONE, Tile.REDSTONE_ORE, Tile.REDSTONE_ORE_LIT, Tile.DOOR_IRON, Tile.BRICK, Tile.FURNACE, Tile.FURNACE_LIT, Tile.STAIRS_STONE, Tile.REDSTONE_ORE, Tile.REDSTONE_ORE_LIT, Tile.DOOR_IRON, Tile.BRICK, Tile.FURNACE, Tile.FURNACE_LIT,
Tile.DISPENSER, Tile.STONE_PRESSURE_PLATE, Tile.RAIL, Tile.DETECTOR_RAIL, Tile.GOLDEN_RAIL, Tile.PISTON, Tile.STICKY_PISTON}; Tile.DISPENSER, Tile.STONE_PRESSURE_PLATE, Tile.RAIL, Tile.DETECTOR_RAIL, Tile.GOLDEN_RAIL, Tile.PISTON, Tile.STICKY_PISTON,
ModTile.COAL_BLOCK, ModTile.REDSTONE_BLOCK};
private static final Tile[] HATCHET_BLOCKS = new Tile[]{Tile.WOOD, Tile.BOOKSHELF, Tile.LOG, Tile.CHEST, private static final Tile[] HATCHET_BLOCKS = new Tile[]{Tile.WOOD, Tile.BOOKSHELF, Tile.LOG, Tile.CHEST,
// Here starts the list of blocks that are not affected by default // Here starts the list of blocks that are not affected by default

View File

@ -0,0 +1,27 @@
package xyz.pixelatedw.finalbeta.mixin;
import java.io.IOException;
import java.util.Properties;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.client.resource.language.TranslationStorage;
@Mixin(TranslationStorage.class)
public class TranslationStorageMixin {
@Shadow
private Properties translations;
@Inject(method = "<init>()V", at = @At("TAIL"))
private void init(CallbackInfo ci) {
try {
this.translations.load(TranslationStorage.class.getResourceAsStream("/assets/finalbeta/lang/en_US.lang"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,3 @@
tile.blockRedstone.name=Redstone Block
tile.blockCoal.name=Coal Block

View File

@ -1,7 +1,7 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"id": "finalbeta", "id": "finalbeta",
"version": "1.2.0", "version": "1.3.0",
"name": "Final Beta", "name": "Final Beta",
"description": "A (Cursed) Fabric mod that adds some quality of life changes and fixes some common issues", "description": "A (Cursed) Fabric mod that adds some quality of life changes and fixes some common issues",

View File

@ -38,12 +38,14 @@
"LevelMixin", "LevelMixin",
"DoorTileMixin", "DoorTileMixin",
"CraftingContainerMixin", "CraftingContainerMixin",
"CraftingInventoryMixin",
"RecipeRegistryMixin", "RecipeRegistryMixin",
"SnowballMixin", "SnowballMixin",
"EntityMixin", "EntityMixin",
"SlimeMixin", "SlimeMixin",
"DimensionMixin" "DimensionMixin",
"TranslationStorageMixin",
"RecipeRegistryAccessorMixin",
"MinecraftAccessorMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": -1 "defaultRequire": -1