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

A lot of new options for compatibility with claims #195

Open
wants to merge 5 commits into
base: 1.20-fabric
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.enableProtectionApiCompat && 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 @@ -6,28 +6,36 @@
import com.b1n_ry.yigd.events.DropRuleEvent;
import com.b1n_ry.yigd.util.DropRule;
import com.b1n_ry.yigd.util.GraveOverrideAreas;
import eu.pb4.common.protection.impl.ProtectionImpl;
import eu.pb4.common.protection.api.CommonProtection;
import net.minecraft.util.math.BlockPos;

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 (CommonProtection.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 (CommonProtection.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 (CommonProtection.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 protection 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 protection 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 enableProtectionApiCompat = 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
Loading