Security Craft

Security Craft

56M Downloads

Capsule compatibility

Lythom opened this issue ยท 2 comments

commented

Hey ! I'm developping the capsule mod (https://www.curseforge.com/minecraft/mc-mods/capsule) which can basically take
away an area then deploy it elsewhere.

I'm trying to allow players to capture blocks they own but prevent to capture blocks they don't own, which I failed to implement so far for version 1.15.2 (testing with securitycraft 1.8.20.2).

I've got some code to ensure the player is allowed to captured a block by checking placement interactions are permitted. It works fine with area protections mods (like ftb-utils chunk claiming system) but it fails to detect a specific protected block like securitycraft owned blocks.

I tried to improve the check by using the following strategies :

// simulate a BreakEvent and see if a mod have a protection to prevent the break 
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldserver, blockPos, worldserver.getBlockState(blockPos), player);
MinecraftForge.EVENT_BUS.post(event);
return !event.isCanceled();
// simulate a HarvestCheck and see if a mod have a protection to prevent the harvest, assuming the player have the right tool
PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, worldserver.getBlockState(blockPos), true);
MinecraftForge.EVENT_BUS.post(event);
return event.canHarvest();

None of them giving me the expected result (event cancelled): if the not-owner player have a tool to bypass the -1 hardness then the break is allowed.

  • I've found out breaking is prevented by using a hardness of -1 on the blocks, but I don't want to prevent players to capture -1 hardness blocks so that they can capture a Secritycraft block they own.
  • There is a whitelist/blacklist system in capsule that modpack makers can use to prevent abuses, but it would prevent any capture even for owned blocks.

My questions :

  1. Do you have an idea of how I could check If a block is owned or not by a given player, without creating a coupling with securitycraft ? (I prefer not to include any specific API etc. and only use vanilla/forge interfaces to interact with other mods)
  2. Would it be interesting to implement an additional protection into securitycraft on the block by cancelling break or harvest events ? I think it could improve further the compatibilty with any mod using "forced" break on blocks but you'll consider better than me if there is undesirable side effects.

Thanks for the help!

commented

As you might have noticed, block ownership in SecurityCraft is saved in tile entity data. This is also the reason why you should preferrably use our API to query ownership of a block. A simple check would look like this:

if(tileEntity instanceof IOwnable && ((IOwnable)tileEntity).getOwner().isOwner(player)) {
	//do cool stuff
}

I'd rather not cancel break or harvest events, as even I'm not sure of the (potentially negative) implications that may have. One thing I can think of out of the box would be that players in creative mode would not be able to break owned blocks, though that could be mitigated by a simple check I presume.

I could add an unconventional (and very ugly) way using getPlayerRelativeBlockHardness and return different negative values to say whether the player does or does not own the block. However this would be just a hacky way of checking ownership which can already be done in a much nicer way, as outlined above.
Going down that same route, the HarvestCheck event would be really useful (although I imagine it could have side effects as well, as technically the blocks still cannot be broken by normal means), however that one does not provide a position - despite the caller having one available - which is needed for getting the tile entity from the world to determine ownership.

For now, I'm keeping with my opinion that you should be using SecurityCraft's API. Feel free to join our Discord server in the #sc-talk channel for more discussion.

commented

Thanks for the answer, reaching on the discord to see how to use the API.