Added TOML config

master
Wynd 2023-04-08 18:37:56 +03:00
parent 1886b964d0
commit f03c95d213
17 changed files with 219 additions and 96 deletions

View File

@ -16,6 +16,7 @@ repositories {
// Loom adds some essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
mavenCentral()
maven {
name 'Jitpack'
url 'https://jitpack.io/'
@ -43,6 +44,8 @@ dependencies {
transitive false
}
compile 'com.electronwill.night-config:toml:3.6.6'
// API. You technically don't need it, but it's extremely useful for not having to write the same code in every mod.
// modImplementation "io.github.minecraft-cursed-legacy:cursed-legacy-api:${project.api_version}"

View File

@ -3,20 +3,8 @@ package xyz.pixelatedw.betterbeta;
import net.fabricmc.api.ModInitializer;
public class MainMod implements ModInitializer {
// private static WritableConfig config;
@Override
public void onInitialize() {
// // example config
// try {
// config = Configs.loadOrCreate(new Id("modid", "example"),
// ConfigTemplate.builder()
// .addContainer("exampleContainer", container -> container.addDataEntry("someData", "0.5"))
// .build());
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// System.out.println(config.getDoubleValue("exampleContainer.someData"));
}
}

View File

@ -0,0 +1,94 @@
package xyz.pixelatedw.betterbeta;
import java.util.ArrayList;
import java.util.List;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.file.CommentedFileConfigBuilder;
import com.google.common.base.Strings;
public class ModConfig {
private static final String CONFIG_PATH = "config/betterbeta.toml";
private static final List<Option> OPTIONS = new ArrayList<>();
private CommentedFileConfig fileConfig;
public static final Option<Boolean> SUGAR_CANE_ON_SAND = make("Sugar Cane on sand", true, "Allows sugar canes to be placed on sand");
public static final Option<Boolean> ADD_MORE_SOUNDS = make("Add more sounds", true,
"Links a few more sounds from your local 'resources' folder with the game, namely for item breaking, minecarts and chests");
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");
public static final Option<Boolean> FIX_MINECART_FLICKERING = make("Fix minecart flickering", true,
"Fixes minecarts flickering when looking at their backs as a passanger");
public static final Option<Boolean> FIX_MINECART_STOPPING_ON_ITEMS = make("Fix minecart stopping on items", true,
"Fixes minecarts getting stopped by arrows and dropped items on tracks");
public static final Option<Boolean> FIX_FISHING = make("Fix fishing", true, "Fixes fishes going above the player's head when fishing");
public static final Option<Boolean> FIX_LEG_ARMOR_ON_VEHICLES = make("Fix leg armor on vehicles", true,
"Fixes leg armor not properly getting updated when switching poses (start/stop riding a vehicle)");
public static final Option<Boolean> FIX_STAIRS_DROPS = make("Fix stairs drops", true, "Fix stairs not dropping themselves when mined");
public static final Option<Boolean> FIX_PICKAXE_EFFECTIVENESS = make("Fix pickaxe effectiveness", true,
"Fixes pickaxes not being effective agaist certain blocks that it should be effective on");
public static final Option<Boolean> FIX_AXE_EFFECTIVENESS = make("Fix axe effectiveness", true,
"Fixes axes not being effective agaist certain blocks that it should be effective on");
private static ModConfig instance = new ModConfig();
public static final ModConfig instance() {
return instance;
}
public ModConfig() {
CommentedFileConfigBuilder builder = CommentedFileConfig.builder(CONFIG_PATH);
this.fileConfig = builder.autosave().autoreload().build();
this.fileConfig.load();
boolean save = false;
for (Option o : OPTIONS) {
if (!this.fileConfig.contains(o.name)) {
this.fileConfig.add(o.name, o.defaultValue);
this.fileConfig.setComment(o.name, o.description);
save = true;
} else if (!Strings.isNullOrEmpty(o.description) && this.fileConfig.contains(o.name)
&& !this.fileConfig.containsComment(o.name)) {
this.fileConfig.setComment(o.name, o.description);
save = true;
}
}
if (save) {
this.fileConfig.load();
}
}
public static <T> Option<T> make(String name, T defaultValue, String description) {
Option<T> option = new Option(name, defaultValue, description);
OPTIONS.add(option);
return option;
}
public <T> T get(Option<T> o) {
return this.fileConfig.getOrElse(o.name, o.defaultValue);
}
public static class Option<T> {
private String name;
private String description;
private T defaultValue;
public Option(String name, T defaultValue, String description) {
this.name = name;
this.defaultValue = defaultValue;
this.description = description;
}
public Option(String name, T defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
public T get() {
return ModConfig.instance().get(this);
}
}
}

View File

@ -40,6 +40,9 @@ public class WyHelper {
// enemy.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f);
// player.level.spawnEntity(enemy);
boolean b = ModConfig.instance().get(ModConfig.SUGAR_CANE_ON_SAND);
System.out.println(b);
player.level.setLevelTime(0);
player.level.getProperties().setRaining(false);
player.level.getProperties().setRainTime(0);

View File

@ -11,16 +11,19 @@ import net.minecraft.client.render.entity.BipedEntityRenderer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(BipedEntityRenderer.class)
public class BipedRendererMixin {
@Inject(method = "method_827", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/HandItemRenderer;method_1862(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemInstance;)V", shift = Shift.BEFORE))
public void playerRendering(LivingEntity entity, float f, CallbackInfo ci) {
ItemInstance item = entity.getHandRenderItem();
if (item != null && item.itemId == ItemType.bow.id) {
GL11.glRotatef(-5, 1, 0, 0);
GL11.glTranslatef(0.2F, -0.5F, 0.2F);
if(ModConfig.FIX_BOW_MODEL.get()) {
ItemInstance item = entity.getHandRenderItem();
if (item != null && item.itemId == ItemType.bow.id) {
GL11.glRotatef(-5, 1, 0, 0);
GL11.glTranslatef(0.2F, -0.5F, 0.2F);
}
}
}
}

View File

@ -7,12 +7,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.item.ItemType;
import net.minecraft.item.tool.BowItem;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(BowItem.class)
public class BowItemMixin {
@Inject(method = "<init>(I)V", at = @At("TAIL"))
public void init(int i, CallbackInfo ci) {
ItemType item = ((ItemType) (Object) this);
item.method_466();
if(ModConfig.FIX_BOW_MODEL.get()) {
ItemType item = ((ItemType) (Object) this);
item.method_466();
}
}
}

View File

@ -11,6 +11,7 @@ import net.minecraft.container.ChestContainer;
import net.minecraft.entity.player.ClientPlayer;
import net.minecraft.entity.player.Player;
import net.minecraft.inventory.Inventory;
import xyz.pixelatedw.betterbeta.ModConfig;
import xyz.pixelatedw.betterbeta.WyHelper;
@Mixin(ClientPlayer.class)
@ -28,15 +29,19 @@ public class ClientPlayerMixin {
@Inject(method = "openChestScreen", at = @At("TAIL"))
public void openChestScreen(Inventory arg, CallbackInfo ci) {
Player player = (Player) (Object) this;
player.level.playSound(player, "random.chestopen", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
if(ModConfig.ADD_MORE_SOUNDS.get()) {
Player player = (Player) (Object) this;
player.level.playSound(player, "random.chestopen", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
}
}
@Inject(method = "closeContainer", at = @At("HEAD"))
public void closeContainer(CallbackInfo ci) {
Player player = (Player) (Object) this;
if(player.container instanceof ChestContainer) {
player.level.playSound(player, "random.chestclosed", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
if(ModConfig.ADD_MORE_SOUNDS.get()) {
Player player = (Player) (Object) this;
if(player.container instanceof ChestContainer) {
player.level.playSound(player, "random.chestclosed", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
}
}
}
}

View File

@ -7,19 +7,22 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import net.minecraft.entity.FishHook;
import net.minecraft.entity.ItemEntity;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(FishHook.class)
public class FishHookMixin {
@ModifyArgs(method = "method_956", at = @At(value = "INVOKE", target = "Lnet/minecraft/level/Level;spawnEntity(Lnet/minecraft/entity/Entity;)Z"))
private void onFishCaught(Args args) {
ItemEntity item = args.get(0);
FishHook hook = (FishHook) (Object) this;
double x = hook.field_1067.x - hook.x;
double y = hook.field_1067.y - hook.y;
double z = hook.field_1067.z - hook.z;
item.velocityX = x * 0.1D;
item.velocityY = y * 0.1D + Math.sqrt(Math.sqrt(x * x + y * y + z * z)) * 0.05D;
item.velocityZ = z * 0.1D;
if(ModConfig.FIX_FISHING.get()) {
ItemEntity item = args.get(0);
FishHook hook = (FishHook) (Object) this;
double x = hook.field_1067.x - hook.x;
double y = hook.field_1067.y - hook.y;
double z = hook.field_1067.z - hook.z;
item.velocityX = x * 0.1D;
item.velocityY = y * 0.1D + Math.sqrt(Math.sqrt(x * x + y * y + z * z)) * 0.05D;
item.velocityZ = z * 0.1D;
}
}
}

View File

@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemInstance;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(ItemInstance.class)
public class ItemInstanceMixin {
@ -21,9 +22,11 @@ public class ItemInstanceMixin {
@Inject(method = "applyDamage", at = @At("HEAD"))
public void applyDamage(int i, Entity arg, CallbackInfo ci) {
ItemInstance item = (ItemInstance) (Object) this;
if (this.damage + i > item.method_723()) {
arg.level.playSound(arg, "random.break", 0.5f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
if(ModConfig.ADD_MORE_SOUNDS.get()) {
ItemInstance item = (ItemInstance) (Object) this;
if (this.damage + i > item.method_723()) {
arg.level.playSound(arg, "random.break", 0.5f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
}
}
}
}

View File

@ -13,6 +13,7 @@ import net.minecraft.entity.projectile.Arrow;
import net.minecraft.tile.RailTile;
import net.minecraft.util.maths.Box;
import net.minecraft.util.maths.MathsHelper;
import xyz.pixelatedw.betterbeta.ModConfig;
import xyz.pixelatedw.betterbeta.WyHelper;
@Mixin(Minecart.class)
@ -20,14 +21,16 @@ public class MinecartMixin {
private static final double EXTRA_MINECART_XZ_SIZE = 0.3;
private static final double EXTRA_MINECART_Y_SIZE = 0.1;
@Inject(method = "method_1379", at = @At("HEAD"), cancellable = true)
public void onCollision(Entity other, CallbackInfoReturnable<Box> ci) {
if(other instanceof ItemEntity || other instanceof Arrow) {
ci.setReturnValue(null);
if (ModConfig.FIX_MINECART_STOPPING_ON_ITEMS.get()) {
if (other instanceof ItemEntity || other instanceof Arrow) {
ci.setReturnValue(null);
}
}
}
@Inject(method = "tick", at = @At("TAIL"))
public void tick(CallbackInfo ci) {
Minecart minecart = (Minecart) (Object) this;
@ -40,8 +43,10 @@ public class MinecartMixin {
float volume = 0;
float pitch = 0;
if (speed >= 0.01D) {
if(minecart.passenger != null) {
minecart.boundingBox.set(minecart.boundingBox.minX - EXTRA_MINECART_XZ_SIZE, minecart.boundingBox.minY, minecart.boundingBox.minZ - EXTRA_MINECART_XZ_SIZE, minecart.boundingBox.maxX + EXTRA_MINECART_XZ_SIZE, minecart.boundingBox.maxY + EXTRA_MINECART_Y_SIZE, minecart.boundingBox.maxZ + EXTRA_MINECART_XZ_SIZE);
if (minecart.passenger != null && ModConfig.FIX_MINECART_FLICKERING.get()) {
minecart.boundingBox.set(minecart.boundingBox.minX - EXTRA_MINECART_XZ_SIZE, minecart.boundingBox.minY,
minecart.boundingBox.minZ - EXTRA_MINECART_XZ_SIZE, minecart.boundingBox.maxX + EXTRA_MINECART_XZ_SIZE,
minecart.boundingBox.maxY + EXTRA_MINECART_Y_SIZE, minecart.boundingBox.maxZ + EXTRA_MINECART_XZ_SIZE);
}
++minecart.field_1645;
pitch = WyHelper.clamp(pitch + 0.0025F, 0.0F, 1.0F);
@ -51,7 +56,7 @@ public class MinecartMixin {
pitch = 0.0f;
}
if (speed >= 0.01D) {
if (speed >= 0.01D && ModConfig.ADD_MORE_SOUNDS.get()) {
if (minecart.field_1645 % 34 == 1) {
minecart.level.playSound(x, y, z, "minecart.base", volume, pitch);
}

View File

@ -8,19 +8,22 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.Minecraft;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(Minecraft.class)
public class MinecraftMixin {
@Inject(method = "loadSoundFromDir", at = @At("HEAD"))
public void loadSoundFromDir(String string, File file, CallbackInfo ci) {
Minecraft mc = (Minecraft) (Object) this;
int split = string.indexOf("/");
String type = string.substring(0, split);
String newSound = string.substring(split + 1);
// For now only allow the minecart sounds, allowing all of them causes weird effects with same name sounds when the game decides which one to use
// XXX Could always incorporate the sound3 part into the sound's name and have it accessible as sound3.random.bow for example, which would avoid the overlap with current sounds
if (type.equalsIgnoreCase("sound3") && newSound.startsWith("minecart/")) {
mc.soundHelper.method_2011(newSound, file);
if(ModConfig.ADD_MORE_SOUNDS.get()) {
Minecraft mc = (Minecraft) (Object) this;
int split = string.indexOf("/");
String type = string.substring(0, split);
String newSound = string.substring(split + 1);
// For now only allow the minecart sounds, allowing all of them causes weird effects with same name sounds when the game decides which one to use
// XXX Could always incorporate the sound3 part into the sound's name and have it accessible as sound3.random.bow for example, which would avoid the overlap with current sounds
if (type.equalsIgnoreCase("sound3") && newSound.startsWith("minecart/")) {
mc.soundHelper.method_2011(newSound, file);
}
}
}
}

View File

@ -14,31 +14,36 @@ import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import net.minecraft.item.armour.ArmourItem;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(PlayerRenderer.class)
public class PlayerRendererMixin extends LivingEntityRendererMixin{
public class PlayerRendererMixin extends LivingEntityRendererMixin {
@Shadow
private BipedModel field_295; // Armor
@Shadow
private BipedModel field_296; // Legs
@Inject(method = "method_827", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/HandItemRenderer;method_1862(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemInstance;)V", shift = Shift.BEFORE))
public void playerRendering(Player player, float f, CallbackInfo ci) {
ItemInstance item = player.inventory.getHeldItem();
if (item != null && item.itemId == ItemType.bow.id) {
GL11.glTranslatef(0.0F, -0.5F, 0.0F);
if (ModConfig.FIX_BOW_MODEL.get()) {
ItemInstance item = player.inventory.getHeldItem();
if (item != null && item.itemId == ItemType.bow.id) {
GL11.glTranslatef(0.0F, -0.5F, 0.0F);
}
}
}
@Inject(method = "render(Lnet/minecraft/entity/player/Player;DDDFF)V", at = @At("HEAD"))
public void render(Player arg, double d, double d1, double d2, float f, float f1, CallbackInfo ci) {
ItemInstance stack = arg.inventory.getArmourItem(1);
if (stack != null) {
ItemType item = stack.getType();
if (item instanceof ArmourItem) {
this.field_296.isRiding = this.field_909.isRiding;
if (ModConfig.FIX_LEG_ARMOR_ON_VEHICLES.get()) {
ItemInstance stack = arg.inventory.getArmourItem(1);
if (stack != null) {
ItemType item = stack.getType();
if (item instanceof ArmourItem) {
this.field_296.isRiding = this.field_909.isRiding;
}
}
}
}

View File

@ -11,9 +11,4 @@ public class ScreenMixin {
@Shadow
public Minecraft minecraft;
// @Inject(method = "init(Lnet/minecraft/client/Minecraft;II)V", at = @At("HEAD"))
// public void init(Minecraft minecraft, int i, int j, CallbackInfo ci) {
// this.instance = minecraft;
// }
}

View File

@ -8,18 +8,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.render.entity.model.BipedModel;
import net.minecraft.client.render.entity.model.SkeletonModel;
import net.minecraft.client.render.entity.model.ZombieModel;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(ZombieModel.class)
public class SkeletonModelMixin {
@Inject(method = "setAngles", at = @At("TAIL"))
public void setAngles(float f, float f1, float f2, float f3, float f4, float f5, CallbackInfo ci) {
BipedModel model = ((BipedModel) (Object) this);
if(model instanceof SkeletonModel) {
model.leftArm.yaw = 0.45f;
model.rightArm.yaw = -0.2f;
model.leftArm.pitch -= 0.05f;
model.rightArm.pitch -= 0.05f;
model.rightArm.roll += 0.1f;
if(ModConfig.FIX_BOW_MODEL.get()) {
BipedModel model = ((BipedModel) (Object) this);
if(model instanceof SkeletonModel) {
model.leftArm.yaw = 0.45f;
model.rightArm.yaw = -0.2f;
model.leftArm.pitch -= 0.05f;
model.rightArm.pitch -= 0.05f;
model.rightArm.roll += 0.1f;
}
}
}
}

View File

@ -10,23 +10,26 @@ import net.minecraft.item.ItemInstance;
import net.minecraft.level.Level;
import net.minecraft.tile.StairsTile;
import net.minecraft.tile.Tile;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(StairsTile.class)
public class StairsTileMixin {
@Inject(method = "beforeDestroyedByExplosion", at = @At("HEAD"), cancellable = true)
public void beforeDestroyedByExplosion(Level arg, int i, int j, int k, int i1, float f, CallbackInfo ci) {
Tile tile = ((Tile) (Object) this);
ItemInstance item = new ItemInstance(tile.id, 1, 0);
if (!arg.isClient) {
float var6 = 0.7F;
double var7 = arg.rand.nextFloat() * var6 + (1.0F - var6) * 0.5D;
double var9 = arg.rand.nextFloat() * var6 + (1.0F - var6) * 0.5D;
double var11 = arg.rand.nextFloat() * var6 + (1.0F - var6) * 0.5D;
ItemEntity var13 = new ItemEntity(arg, i + var7, j + var9, k + var11, item);
var13.pickupDelay = 10;
arg.spawnEntity(var13);
if(ModConfig.FIX_STAIRS_DROPS.get()) {
Tile tile = ((Tile) (Object) this);
ItemInstance item = new ItemInstance(tile.id, 1, 0);
if (!arg.isClient) {
float var6 = 0.7F;
double var7 = arg.rand.nextFloat() * var6 + (1.0F - var6) * 0.5D;
double var9 = arg.rand.nextFloat() * var6 + (1.0F - var6) * 0.5D;
double var11 = arg.rand.nextFloat() * var6 + (1.0F - var6) * 0.5D;
ItemEntity var13 = new ItemEntity(arg, i + var7, j + var9, k + var11, item);
var13.pickupDelay = 10;
arg.spawnEntity(var13);
}
ci.cancel();
}
ci.cancel();
}
}

View File

@ -9,23 +9,26 @@ import net.minecraft.level.Level;
import net.minecraft.tile.SugarCane;
import net.minecraft.tile.Tile;
import net.minecraft.tile.material.Material;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(SugarCane.class)
public class SugarCaneMixin {
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
public void canPlaceAt(Level arg, int x, int y, int z, CallbackInfoReturnable<Boolean> info) {
int tileBelow = arg.getTileId(x, y - 1, z);
if (tileBelow == Tile.SAND.id) {
boolean flag = false;
// Check if there is a water block around the sand block
flag |= arg.getMaterial(x - 1, y - 1, z) == Material.WATER;
flag |= arg.getMaterial(x + 1, y - 1, z) == Material.WATER;
flag |= arg.getMaterial(x, y - 1, z - 1) == Material.WATER;
flag |= arg.getMaterial(x, y - 1, z + 1) == Material.WATER;
if (flag) {
info.setReturnValue(true);
}
if(ModConfig.SUGAR_CANE_ON_SAND.get()) {
int tileBelow = arg.getTileId(x, y - 1, z);
if (tileBelow == Tile.SAND.id) {
boolean flag = false;
// Check if there is a water block around the sand block
flag |= arg.getMaterial(x - 1, y - 1, z) == Material.WATER;
flag |= arg.getMaterial(x + 1, y - 1, z) == Material.WATER;
flag |= arg.getMaterial(x, y - 1, z - 1) == Material.WATER;
flag |= arg.getMaterial(x, y - 1, z + 1) == Material.WATER;
if (flag) {
info.setReturnValue(true);
}
}
}
}
}

View File

@ -11,6 +11,7 @@ import net.minecraft.item.tool.PickaxeItem;
import net.minecraft.item.tool.ToolItem;
import net.minecraft.item.tool.ToolMaterial;
import net.minecraft.tile.Tile;
import xyz.pixelatedw.betterbeta.ModConfig;
@Mixin(ToolItem.class)
public class ToolItemMixin {
@ -34,9 +35,9 @@ public class ToolItemMixin {
public void init(int i, int j, ToolMaterial arg, Tile[] args, CallbackInfo ci) {
ToolItem tool = ((ToolItem) (Object) this);
if (tool instanceof PickaxeItem) {
if (tool instanceof PickaxeItem && ModConfig.FIX_PICKAXE_EFFECTIVENESS.get()) {
this.field_2712 = PICKAXE_BLOCKS;
} else if (tool instanceof HatchetItem) {
} else if (tool instanceof HatchetItem && ModConfig.FIX_AXE_EFFECTIVENESS.get()) {
this.field_2712 = HATCHET_BLOCKS;
}
}