Skip to content

Added Optional Offline Protect Only Mode and more #330

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

Open
wants to merge 17 commits into
base: 1.19/dev
Choose a base branch
from

Conversation

1whohears
Copy link

@1whohears 1whohears commented Nov 13, 2024

I would like to be able to disable block protection on my server, but moderating against offline raids is very annoying. The following features can disable chunk protection only when the team is online and able to defend their base.

I also added max_destroy_blocks_per_hour which is meant to prevent players from completely destroying someone else's base in one sitting. I am not sure what the magic number should be, but the idea is that this feature can satisfy some players destructive desires, and also not completely undo a builder's hours of work. This setting should also nerf the strat where people just hide underground and fill in all the holes and never interact with the rest of the server (Ashley if you are reading this, yes this is my call out post on twitter dot com).

I also added the living_entity_attack_blacklist tag in case server owners wanted to protect specific living entities. Entities in this tag are protected similar to tnt protection. If the source is unknown, the entity takes no damage. I saw a comment where it was intentionally decided to not protect living entities at all. The code that protects non living entities (paintings, item frames) is left intact. But I feel it should at least be an option and leave it up to the server owner for living entities. I still want wars to be fought over valuable entities like villagers, but I don't want offline villager raids to happen. This is why I added the protect_entities_offline_only setting.

I tried to implement these features in the least destructive way I could come up with. But stuff like the destroy block counter required some new Protection nodes to be added and other changes because before; placing, left clicking on, and breaking blocks were all considered the same PrivacyProperty and I didn't see how FTBChunksTeamData#canUse could know if a block was being broken otherwise. If y'all don't like something that's what code review is for.

I've testing everything in local multiplayer (--username=Dev2) and it works.

Also I made these changes in the 1.19 branch cause I will be running a small 1.19.2 server. I am not as familiar with mod dev in other versions.

New Configs:
offline_protection_only: If enabled and disable_protection = false enemy players will ONLY be able to damage your claimed chunks if you or your team mates are online.
offline_protection_buffer: If offline_protection_only = true, the time in SECONDS after all members of a team log off, before chunk protection turns on. This setting is meant to discourage combat logging. Set to 0 to disable.
max_destroy_blocks_per_hour: If disable_protection = false, this many blocks can still be destroyed per hour be enemy players. 0 disables this.
destroy_blocks_count_period: If max_destroy_blocks_per_hour > 0, the groups of time in seconds where the number of blocks broken are counted. Groups younger than an hour contribute to the total blocks broken. Groups older than an hour are removed.
protect_entities_offline_only: Only protect the entities listed in the living_entity_attack_blacklist tag when all team members are offline.

New Tags:
edit_blacklist: (Blocks) prevent enemy players from breaking these blocks even if max_destroy_blocks_per_hour > 0
living_entity_attack_blacklist: (EntityTypes) prevent enemy players from attacking these entities. this is very useful when paired with protect_entities_offline_only to stop offline villager raids for example.

… protection mode, max destroy blocks rate, living entity attack blacklist tag, and more
…ck list after it is known that the player doesn't own those chunks.
@CLAassistant
Copy link

CLAassistant commented Nov 13, 2024

CLA assistant check
All committers have signed the CLA.

… a PR to the create mod so that the drills will always fire the block break event. drills do not have an "owner" so the block break player will be null. however without this commit, FTB would still allow drills to break the block because the block break event is not canceled when the player is null.
…ing to try to assign owner players to all of the contraptioins that can break blocks in create. but thankfully I came up with a much simpler solution. create machines are only breaking blocks in force loaded chunks on servers anyway. this option then prevents enemy tunnel bores from getting into a base because friendly force loaded chunks should be surrounded by regular claimed chunks that act as a protective buffer. a version of create that fires the block break event with a null player is still required, but only on the server side...but of course this all assumes all mods have a null check in their block break listeners...
… same "allow if in force loaded chunk" logic. this is the messiest code logic to date. I will fix it later.
…e broken by player caused explosions and they contribute to the max block break per hour.
@MichaelHillcox MichaelHillcox requested a review from desht January 7, 2025 13:57
@desht
Copy link
Contributor

desht commented Feb 20, 2025

Sorry, I realize this has slipped a bit, but I will be taking a look at this as soon as I can. From a quick overview, the changes look good and useful for PvP, but it's important that big changes like this don't end up in 1.19 only, so a port to 1.20 and 1.21 will be required. Fortunately most of this code looks quite to easy to cherry-pick; not too much direct interaction with Minecraft code.

@1whohears
Copy link
Author

Hello! Don't worry I've been slowly adding more features and fixing bugs anyway. Since all the changes are server side I have been using custom builds on a small server to test these changes. As far as I know all the new features work, but it of course requires testing and review from others just to make sure.

I'd say the area that probably needs the most attention is the explosion block counting system. The way I iterate through every block in the explosion list to check if the block break limit is probably not the most efficient way to do it. But that is why everything I added is configurable and disabled by default.

The block counting system could probably be expanded in to a more advanced system where there are different tiers of block breaks. For example, currently breaking a chest is treated the same as dirt.

My other mods are currently exclusively 1.19 so that's why I've been working in this branch. I'm glad y'all are interested in porting these features to other versions! I'm sure we want to make sure all the new stuff is working first of course.

Excited to see y'alls feedback!

…m packets are sent. a common issue when in an enemy chunk is when you eat while holding a shield in the off hand and while looking at a block, the shield replaces the food item on the client side.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants