Skip to content

Commit

Permalink
Add config for items that toggle off the mod. Fix #414, Fix #408
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Jan 27, 2024
1 parent d2d81fd commit 3729f61
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public static void upgradeConfig(FirstPersonSettings conf) {
"create:extendo_grip", "create:handheld_worldshaper", "map_atlases:atlas")));
conf.configVersion = 1;
}
if (conf.configVersion < 2) {
conf.autoToggleModItems.add("exposure:camera");
conf.configVersion = 2;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class FirstPersonSettings {

public int configVersion = 1;
public int configVersion = 2;
public boolean enabledByDefault = true;
public int xOffset = 0;
public int sneakXOffset = 0;
Expand All @@ -20,5 +20,7 @@ public class FirstPersonSettings {
public Set<String> autoVanillaHands = new HashSet<>(Arrays.asList("antiqueatlas:antique_atlas",
"twilightforest:filled_magic_map", "twilightforest:filled_maze_map", "twilightforest:filled_ore_map",
"create:potato_cannon", "create:extendo_grip", "create:handheld_worldshaper", "map_atlases:atlas"));

public Set<String> autoToggleModItems = new HashSet<>(Arrays.asList("exposure:camera"));

}
40 changes: 30 additions & 10 deletions src/main/java/dev/tr7zw/firstperson/LogicHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ public class LogicHandler {
@Getter
private Vec3 offset = Vec3.ZERO; // Current offset used for rendering
private Set<Item> autoVanillaHandItems = new HashSet<>();
private Set<Item> autoDisableItems = new HashSet<>();

void registerDefaultHandlers() {
FirstPersonAPI.registerPlayerHandler((ActivationHandler) () -> {
if (client.player.isAutoSpinAttack() || client.player.isFallFlying()
|| (client.player.getSwimAmount(1f) != 0 && !isCrawlingOrSwimming(client.player))) {
return true;
}
if (autoDisableItems.contains(client.player.getMainHandItem().getItem())
|| autoDisableItems.contains(client.player.getOffhandItem().getItem())) {
return true;
}
// spotless:off
//#if MC >= 11700
if (client.player.isScoping()) {
//#if MC >= 11700
if (client.player.isScoping()) {
return true;
}
//#endif
//spotless:on
//#endif
//spotless:on
return false;
});
}
Expand Down Expand Up @@ -143,24 +148,28 @@ public boolean isCrawlingOrSwimming(Player player) {

public boolean showVanillaHands() {
return fpm.getConfig().vanillaHands || autoVanillaHandItems.contains(client.player.getMainHandItem().getItem())
|| autoVanillaHandItems.contains(client.player.getOffhandItem().getItem());
|| autoVanillaHandItems.contains(client.player.getOffhandItem().getItem())
|| autoDisableItems.contains(client.player.getMainHandItem().getItem())
|| autoDisableItems.contains(client.player.getOffhandItem().getItem());
}

public boolean showVanillaHands(ItemStack mainhand, ItemStack offhand) {
return fpm.getConfig().vanillaHands || autoVanillaHandItems.contains(mainhand.getItem())
|| autoVanillaHandItems.contains(offhand.getItem());
|| autoVanillaHandItems.contains(offhand.getItem()) || autoDisableItems.contains(mainhand.getItem())
|| autoDisableItems.contains(offhand.getItem());
}

public void addAutoVanillaHandsItem(Item item) {
autoVanillaHandItems.add(item);
}

public void clearAutoVanillaHandsList() {
autoVanillaHandItems.clear();
public void addAutoDisableItem(Item item) {
autoDisableItems.add(item);
}

public void reloadAutoVanillaHandsSettings() {
clearAutoVanillaHandsList();
autoVanillaHandItems.clear();
autoDisableItems.clear();
Item invalid = NMSHelper.getItem(new ResourceLocation("minecraft", "air"));
for (String itemId : fpm.getConfig().autoVanillaHands) {
try {
Expand All @@ -173,6 +182,17 @@ public void reloadAutoVanillaHandsSettings() {
}
}
FirstPersonBase.LOGGER.info("Loaded Vanilla Hands items: {}", autoVanillaHandItems);
for (String itemId : fpm.getConfig().autoToggleModItems) {
try {
Item item = NMSHelper.getItem(new ResourceLocation(itemId.split(":")[0], itemId.split(":")[1]));
if (invalid != item) {
addAutoDisableItem(item);
}
} catch (Exception ex) {
FirstPersonBase.LOGGER.info("Unknown item to add to the auto disable list: {}", itemId);
}
}
FirstPersonBase.LOGGER.info("Loaded Auto Disable items: {}", autoDisableItems);
}

}

0 comments on commit 3729f61

Please sign in to comment.