Added TOML config
parent
1886b964d0
commit
f03c95d213
|
@ -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}"
|
||||
|
||||
|
|
|
@ -4,19 +4,7 @@ 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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -11,12 +11,14 @@ 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) {
|
||||
if(ModConfig.FIX_BOW_MODEL.get()) {
|
||||
ItemInstance item = entity.getHandRenderItem();
|
||||
if (item != null && item.itemId == ItemType.bow.id) {
|
||||
GL11.glRotatef(-5, 1, 0, 0);
|
||||
|
@ -24,3 +26,4 @@ public class BipedRendererMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
if(ModConfig.FIX_BOW_MODEL.get()) {
|
||||
ItemType item = ((ItemType) (Object) this);
|
||||
item.method_466();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ 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) {
|
||||
if(ModConfig.FIX_FISHING.get()) {
|
||||
ItemEntity item = args.get(0);
|
||||
FishHook hook = (FishHook) (Object) this;
|
||||
double x = hook.field_1067.x - hook.x;
|
||||
|
@ -23,3 +25,4 @@ public class FishHookMixin {
|
|||
item.velocityZ = z * 0.1D;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -23,10 +24,12 @@ public class MinecartMixin {
|
|||
|
||||
@Inject(method = "method_1379", at = @At("HEAD"), cancellable = true)
|
||||
public void onCollision(Entity other, CallbackInfoReturnable<Box> ci) {
|
||||
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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ 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) {
|
||||
if(ModConfig.ADD_MORE_SOUNDS.get()) {
|
||||
Minecraft mc = (Minecraft) (Object) this;
|
||||
int split = string.indexOf("/");
|
||||
String type = string.substring(0, split);
|
||||
|
@ -24,3 +26,4 @@ public class MinecraftMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ 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 {
|
||||
|
@ -26,14 +27,17 @@ public class PlayerRendererMixin extends LivingEntityRendererMixin{
|
|||
|
||||
@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) {
|
||||
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) {
|
||||
if (ModConfig.FIX_LEG_ARMOR_ON_VEHICLES.get()) {
|
||||
ItemInstance stack = arg.inventory.getArmourItem(1);
|
||||
if (stack != null) {
|
||||
ItemType item = stack.getType();
|
||||
|
@ -43,3 +47,4 @@ public class PlayerRendererMixin extends LivingEntityRendererMixin{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -8,11 +8,13 @@ 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) {
|
||||
if(ModConfig.FIX_BOW_MODEL.get()) {
|
||||
BipedModel model = ((BipedModel) (Object) this);
|
||||
if(model instanceof SkeletonModel) {
|
||||
model.leftArm.yaw = 0.45f;
|
||||
|
@ -23,3 +25,4 @@ public class SkeletonModelMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,14 @@ 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) {
|
||||
if(ModConfig.FIX_STAIRS_DROPS.get()) {
|
||||
Tile tile = ((Tile) (Object) this);
|
||||
ItemInstance item = new ItemInstance(tile.id, 1, 0);
|
||||
if (!arg.isClient) {
|
||||
|
@ -30,3 +32,4 @@ public class StairsTileMixin {
|
|||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,13 @@ 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) {
|
||||
if(ModConfig.SUGAR_CANE_ON_SAND.get()) {
|
||||
int tileBelow = arg.getTileId(x, y - 1, z);
|
||||
if (tileBelow == Tile.SAND.id) {
|
||||
boolean flag = false;
|
||||
|
@ -29,3 +31,4 @@ public class SugarCaneMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue