Skip to content

Commit

Permalink
add a lot of options for compatibility with claims
Browse files Browse the repository at this point in the history
  • Loading branch information
marlester-dev committed Dec 16, 2024
1 parent 07fd639 commit 4c660a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/b1n_ry/yigd/compat/InvModCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ else if (compatConfig.enableBeansBackpacksCompat)
invCompatMods.add(new BeansBackpacksCompat());
}

if (loader.isModLoaded("common-protection-api"))
if (compatConfig.enableClaimApiCompat && loader.isModLoaded("common-protection-api"))
CommonProtectionApiCompat.init();
if (loader.isModLoaded("orpheus"))
OrpheusCompat.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@

public class CommonProtectionApiCompat {
public static void init() {
AllowBlockUnderGraveGenerationEvent.EVENT.register((grave, currentUnder) ->
YigdConfig.getConfig().graveConfig.blockUnderGrave.generateOnProtectedLand || !ProtectionImpl.isProtected(grave.getWorld(), grave.getPos().down()));
AllowBlockUnderGraveGenerationEvent.EVENT.register((grave, currentUnder) -> {
if (ProtectionImpl.canPlaceBlock(grave.getWorld(), grave.getPos().down(), grave.getOwner(), null)) {
return YigdConfig.getConfig().graveConfig.blockUnderGrave.generateInOwnClaim;
} else {
return YigdConfig.getConfig().graveConfig.blockUnderGrave.generateOnProtectedLand;
}
});

AllowGraveGenerationEvent.EVENT.register((context, grave) -> {
if (ProtectionImpl.isProtected(context.world(), grave.getPos()))
if (ProtectionImpl.canPlaceBlock(context.world(), grave.getPos(), grave.getOwner(), context.player())) {
return YigdConfig.getConfig().compatConfig.standardDropRuleInOwnClaim == DropRule.PUT_IN_GRAVE;
} else {
return YigdConfig.getConfig().compatConfig.standardDropRuleInClaim == DropRule.PUT_IN_GRAVE;

return true;
}
});

DropRuleEvent.EVENT.register((item, slot, context, modify) -> {
if (context == null || !modify) return GraveOverrideAreas.INSTANCE.defaultDropRule;

if (ProtectionImpl.isProtected(context.world(), BlockPos.ofFloored(context.deathPos())))
var player = context.player();
if (ProtectionImpl.canPlaceBlock(context.world(), BlockPos.ofFloored(context.deathPos()), player.getGameProfile(), player)) {
return YigdConfig.getConfig().compatConfig.standardDropRuleInOwnClaim;
} else {
return YigdConfig.getConfig().compatConfig.standardDropRuleInClaim;

return GraveOverrideAreas.INSTANCE.defaultDropRule;
}
});
}
}
12 changes: 10 additions & 2 deletions src/main/java/com/b1n_ry/yigd/config/YigdConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,22 @@ public static class BlockUnderGrave {
add(new MapEntry("minecraft:the_end", "minecraft:end_stone"));
add(new MapEntry("misc", "minecraft:dirt"));
}};
@Comment("Defines whether the block under grave can be generated in claims where the player can NOT place blocks if the claim api compat is enabled.")
public boolean generateOnProtectedLand = false;
@Comment("Defines whether the block under grave can be generated in claims where the player CAN place blocks if the claim api compat is enabled.")
public boolean generateInOwnClaim = true;
}
}

public static class CompatConfig {
@Comment("While PUT_IN_GRAVE, other drop rules will be prioritized")
@Comment("Enables compatibility with Common Protection API (\"Claim API\"), if present")
public boolean enableClaimApiCompat = true;
@Comment("Defines the standard drop rule in claims where the player can NOT place blocks. While PUT_IN_GRAVE, other drop rules will be prioritized")
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public DropRule standardDropRuleInClaim = DropRule.DROP;
@Comment("Defines the standard drop rule in claims where the player CAN place blocks. While PUT_IN_GRAVE, other drop rules will be prioritized")
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public DropRule standardDropRuleInClaim = DropRule.PUT_IN_GRAVE;
public DropRule standardDropRuleInOwnClaim = DropRule.PUT_IN_GRAVE;

public boolean enableAccessoriesCompat = true;
@Comment("While PUT_IN_GRAVE, other drop rules will be prioritized")
Expand Down

0 comments on commit 4c660a7

Please sign in to comment.