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

Gcapi 2 and mp support #76

Merged
merged 8 commits into from
Mar 13, 2024
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ yarn_mappings=b1.7.3-build.2
loader_version=0.14.24-babric.1

# Mod Properties
mod_version=2.2.0
mod_version=2.3.0
maven_group=com.github.telvarost
archives_base_name=AnnoyanceFix

# Dependencies
stapi_version=2.0-alpha.1.1

# Extra Dependencies
gcapi_version=1.2.0
gcapi_version=2.0.1
howmanyitems_version=5.1.1
modmenu_version=dcef643
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.telvarost.annoyancefix;

public enum BoatCollisionEnum {
VANILLA("Vanilla"),
DROP_BOAT("Drop Boat"),
INVINCIBLE("Invincible");

final String stringValue;

BoatCollisionEnum() {
this.stringValue = "Vanilla";
}

BoatCollisionEnum(String stringValue) {
this.stringValue = stringValue;
}

@Override
public String toString() {
return stringValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.telvarost.annoyancefix;

import blue.endless.jankson.JsonElement;
import blue.endless.jankson.JsonPrimitive;
import com.google.common.collect.ImmutableMap;
import net.glasslauncher.mods.api.gcapi.api.ConfigFactoryProvider;
import net.glasslauncher.mods.api.gcapi.api.MaxLength;
import net.glasslauncher.mods.api.gcapi.impl.NonFunction;
import net.glasslauncher.mods.api.gcapi.impl.config.ConfigEntry;
import net.glasslauncher.mods.api.gcapi.impl.config.entry.EnumConfigEntry;

import java.lang.reflect.*;
import java.util.function.*;

public class BoatCollisionEnumFactory implements ConfigFactoryProvider {
@Override
public void provideLoadFactories(ImmutableMap.Builder<Type, NonFunction<String, String, String, Field, Object, Boolean, Object, Object, MaxLength, ConfigEntry<?>>> immutableBuilder) {
immutableBuilder.put(BoatCollisionEnum.class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, enumOrOrdinal, defaultEnum, maxLength) ->
{
int enumOrdinal;
if(enumOrOrdinal instanceof Integer ordinal) {
enumOrdinal = ordinal;
}
else {
enumOrdinal = ((BoatCollisionEnum) enumOrOrdinal).ordinal();
}
return new EnumConfigEntry<BoatCollisionEnum>(id, name, description, parentField, parentObject, isMultiplayerSynced, enumOrdinal, ((BoatCollisionEnum) defaultEnum).ordinal(), BoatCollisionEnum.class);
}));
}

@Override
public void provideSaveFactories(ImmutableMap.Builder<Type, Function<Object, JsonElement>> immutableBuilder) {
immutableBuilder.put(BoatCollisionEnum.class, enumEntry -> new JsonPrimitive(((BoatCollisionEnum) enumEntry).ordinal()));
}

@Override
public void provideLoadTypeAdapterFactories(@SuppressWarnings("rawtypes") ImmutableMap.Builder<Type, Class> immutableBuilder) {
immutableBuilder.put(BoatCollisionEnum.class, Integer.class);
}
}
185 changes: 133 additions & 52 deletions src/main/java/com/github/telvarost/annoyancefix/Config.java
Original file line number Diff line number Diff line change
@@ -1,166 +1,247 @@
package com.github.telvarost.annoyancefix;

import blue.endless.jankson.Comment;
import net.glasslauncher.mods.api.gcapi.api.ConfigCategory;
import net.glasslauncher.mods.api.gcapi.api.ConfigName;
import net.glasslauncher.mods.api.gcapi.api.GConfig;
import net.glasslauncher.mods.api.gcapi.api.MaxLength;
import net.glasslauncher.mods.api.gcapi.api.*;

public class Config {

@GConfig(value = "config", visibleName = "AnnoyanceFix Config")
@GConfig(value = "config", visibleName = "AnnoyanceFix")
public static ConfigFields config = new ConfigFields();

public static class AxesConfig {

@ConfigName("Effective On Workbench")
public static Boolean enableAxesEffectiveOnWorkbench = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnWorkbench = true;

@ConfigName("Effective On Noteblock")
public static Boolean enableAxesEffectiveOnNoteblock = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnNoteblock = true;

@ConfigName("Effective On Wood Door")
public static Boolean enableAxesEffectiveOnWoodDoor = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnWoodDoor = true;

@ConfigName("Effective On Ladders")
public static Boolean enableAxesEffectiveOnLadders = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnLadders = true;

@ConfigName("Effective On Signs")
public static Boolean enableAxesEffectiveOnSigns = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnSigns = true;

@ConfigName("Effective On Wood Pressure Plate")
public static Boolean enableAxesEffectiveOnWoodPressurePlate = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnWoodPressurePlate = true;

@ConfigName("Effective On Jukebox")
public static Boolean enableAxesEffectiveOnJukebox = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnJukebox = true;

@ConfigName("Effective On Wood Stairs")
public static Boolean enableAxesEffectiveOnWoodStairs = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnWoodStairs = true;

@ConfigName("Effective On Fence")
public static Boolean enableAxesEffectiveOnFence = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnFence = true;

@ConfigName("Effective On Pumpkin")
public static Boolean enableAxesEffectiveOnPumpkin = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnPumpkin = true;

@ConfigName("Effective On Jack o Lantern")
public static Boolean enableAxesEffectiveOnJackOLantern = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnJackOLantern = true;

@ConfigName("Effective On Trapdoor")
public static Boolean enableAxesEffectiveOnTrapdoor = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enableAxesEffectiveOnTrapdoor = true;
}

public static class PickaxesConfig {

@ConfigName("Effective On Dispenser")
public static Boolean enablePickaxesEffectiveOnDispenser = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnDispenser = true;

@ConfigName("Effective On Normal Rails")
public static Boolean enablePickaxesEffectiveOnNormalRails = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnNormalRails = true;

@ConfigName("Effective On Detector Rails")
public static Boolean enablePickaxesEffectiveOnDetectorRails = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnDetectorRails = true;

@ConfigName("Effective On Golden Rails")
public static Boolean enablePickaxesEffectiveOnGoldenRails = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnGoldenRails = true;

@ConfigName("Effective On Furnace")
public static Boolean enablePickaxesEffectiveOnFurnace = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnFurnace = true;

@ConfigName("Effective On Furnace Lit")
public static Boolean enablePickaxesEffectiveOnFurnaceLit = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnFurnaceLit = true;

@ConfigName("Effective On Cobblestone Stairs")
public static Boolean enablePickaxesEffectiveOnCobblestoneStairs = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnCobblestoneStairs = true;

@ConfigName("Effective On Stone Pressure Plate")
public static Boolean enablePickaxesEffectiveOnStonePressurePlate = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnStonePressurePlate = true;

@ConfigName("Effective On Iron Door")
public static Boolean enablePickaxesEffectiveOnIronDoor = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnIronDoor = true;

@ConfigName("Effective On Redstone Ore")
public static Boolean enablePickaxesEffectiveOnRedstoneOre = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnRedstoneOre = true;

@ConfigName("Effective On Redstone Ore Lit")
public static Boolean enablePickaxesEffectiveOnRedstoneOreLit = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnRedstoneOreLit = true;

@ConfigName("Effective On Stone Button")
public static Boolean enablePickaxesEffectiveOnStoneButton = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnStoneButton = true;

@ConfigName("Effective On Bricks")
public static Boolean enablePickaxesEffectiveOnBricks = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnBricks = true;

@ConfigName("Effective On Mob Spawner")
public static Boolean enablePickaxesEffectiveOnMobSpawner = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean enablePickaxesEffectiveOnMobSpawner = true;
}

public static class RecipesConfig {

@ConfigName("Crafting: Repair Armor")
public static Boolean recipesRepairArmorEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean recipesRepairArmorEnabled = true;

@ConfigName("Crafting: Repair Tools")
public static Boolean recipesRepairToolsEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean recipesRepairToolsEnabled = true;

@ConfigName("Furnace: Add More Wood Items As Fuel")
public static Boolean recipesAdditionalWoodFuelsEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean recipesAdditionalWoodFuelsEnabled = true;

}

public static class ConfigFields {

@ConfigCategory("Config: Axes Are Effective Against")
@Comment("Options here require restart to take effect")
public static final AxesConfig AXES_CONFIG = new AxesConfig();
public final AxesConfig AXES_CONFIG = new AxesConfig();

@ConfigCategory("Config: Pickaxes Are Effective Against")
@Comment("Options here require restart to take effect")
public static final PickaxesConfig PICKAXES_CONFIG = new PickaxesConfig();
public final PickaxesConfig PICKAXES_CONFIG = new PickaxesConfig();

@ConfigCategory("Config: Recipes/Fuels For Crafting/Furnaces")
@Comment("Options here require restart to take effect")
public static final RecipesConfig RECIPES_CONFIG = new RecipesConfig();
public final RecipesConfig RECIPES_CONFIG = new RecipesConfig();

@ConfigName("Boat Drop Fixes Enabled")
public static Boolean boatDropFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean boatDropFixesEnabled = true;

@ConfigName("Boat Speed Collision Behavior")
@MaxLength(3)
@Comment("0 = vanilla, 1 = drop boat, 2 = invincible")
public static Integer boatCollisionBehavior = 2;
@MultiplayerSynced
@ValueOnVanillaServer(integerValue = 0)
public BoatCollisionEnum boatCollisionBehavior = BoatCollisionEnum.INVINCIBLE;

@ConfigName("Bookshelf Fixes Enabled")
public static Boolean bookshelfFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean bookshelfFixesEnabled = true;

@ConfigName("Cobweb Fixes Enabled")
public static Boolean cobwebFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean cobwebFixesEnabled = true;

@ConfigName("Fence Placement Fixes Enabled")
public static Boolean fenceFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean fenceFixesEnabled = true;

@ConfigName("Fence Shape Fixes Enabled")
public static Boolean fenceShapeFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean fenceShapeFixesEnabled = true;

@ConfigName("Flint and Steel Fixes Enabled")
public static Boolean flintAndSteelFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean flintAndSteelFixesEnabled = true;

@ConfigName("Lava Fixes Enabled")
public static Boolean lavaFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean lavaFixesEnabled = true;

@ConfigName("Pick Block Fixes Enabled")
public static Boolean pickBlockFixesEnabled = true;
@Comment("Only searches hotbar on multiplayer")
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean pickBlockFixesEnabled = true;

@ConfigName("Pig Fixes Enabled")
public static Boolean pigFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean pigFixesEnabled = true;

@ConfigName("Stair Fixes Enabled")
public static Boolean stairFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean stairFixesEnabled = true;

@ConfigName("Water Fixes Enabled")
public static Boolean waterFixesEnabled = true;
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean waterFixesEnabled = true;

@ConfigName("Wood Slab Fixes Enabled (Experimental)")
public static Boolean woodenSlabFixesEnabled = false;
@Comment("Does not work in multiplayer")
@MultiplayerSynced
@ValueOnVanillaServer(booleanValue = TriBoolean.FALSE)
public Boolean woodenSlabFixesEnabled = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void combineDurability(ItemUsedInCraftingEvent event) {
&& (true == event.itemCrafted.hasDurability())
)
{
if ( (Config.RecipesConfig.recipesRepairArmorEnabled)
|| (Config.RecipesConfig.recipesRepairToolsEnabled)
if ( (Config.config.RECIPES_CONFIG.recipesRepairArmorEnabled)
|| (Config.config.RECIPES_CONFIG.recipesRepairToolsEnabled)
) {
int craftedItemMaxDurability = event.itemCrafted.getDurability();
int durabilityToAdd = event.itemUsed.getDurability() - event.itemUsed.getDamage();
Expand Down
Loading