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

Glass protection barrier rework #469

Merged
merged 48 commits into from
Jul 16, 2023

Conversation

IIHERO4
Copy link
Contributor

@IIHERO4 IIHERO4 commented Mar 31, 2022

ReImplement how explosives are treated overall, focusing on TNT bug #292.
IMPORTANT NOTES:

  • This is completely untested, I didnt have anytime to test every version but it should work on theory
  • 1.17 and 1.18 Version support is not implemented yet, so it needs some work from another person to copy the NMS implementation
  • 1.17 and 1.18 calculateExplosionBlocks will throw an error (because its not implement ofc)
  • when calculateExplosionBlocks is not implement in the BedWars.nms, it will use simple block detection methods such as isProtectedByGlass and Arena#isPlacedBlock (the acutal events will catch the error and perform alternatives)
  • Event BlockExplodeEvent uses the same simple detection methods as stated above

This creates four new methods to VersionSupport and NMS support:

  • public List<Block> calculateExplosionBlocks(IArena arena, Entity source, Location explosionLocation, float radius, boolean fire) 1
  • public abstract List<Block> calculateExplosionBlocks(IArena arena, Entity source, Location explosionLocation, float radius, boolean fire, BiFunction<Location, Block, Boolean> callback) 2
  • public boolean isGlass(Material type)
  • public boolean isProtectedByGlass(Location pov, Block block) 3

Config Added explosion-settings.explosion-size, Possible Values: auto | {Any Number}

Footnotes

  1. Uses calculateExplosionBlocks(IArena arena, Entity source, Location explosionLocation, float radius, boolean fire, BiFunction<Location, Block, Boolean> callback) but with a predefined callback that is cached and made specifically for arenas

  2. Mostly copied from its respective version Explosion NMS class, acts just like the vanilla one but with more control over the calculation of the exploded blocks

  3. Performs a simple ray tracing to check whether the POV and the block have any glass block in between them

* isProtectedByGlass performs ray tracing to ensure there is no glass
  inbetween
* Copied from net.minecraft.server.v1_8_R3.Explosion#a() (The NMS implementation of
  https://minecraft.fandom.com/wiki/Explosion#Model_of_block_destruction)
* Add Config explosion-settings.explosion-size
* if size is set to auto OR any negative value it will cache the actual
  size of that entity, if it could not cache it (not found) then the
  default implementation is used (removing and protecting blocks)
@IIHERO4
Copy link
Contributor Author

IIHERO4 commented Mar 31, 2022

needs testing and a look from an actual dev 💀

@IIHERO4
Copy link
Contributor Author

IIHERO4 commented Mar 31, 2022

New Issue has appeared (isProtectedGlass) particularly when iterating using BlockIterator some situations it doesnt work Example:
2022-04-01_01 13 06

When placing the tnt instead of the green wool, the red wool gets destroyed
when observing the path BlockIterator takes, it make sense:
image

As When plugging the parameters, the direction vector is (1, 0, -1) which generates this zigzag pattern

Really need some help on this one [SOLVED]

@LolFin2022
Copy link

Me nub.. So no help ;)

@tomkeuper
Copy link
Collaborator

tomkeuper commented Feb 27, 2023

Note that currently the only supported versions are: 1_8_R3, 1_12_R1, 1_16_R3, 1_17_R1, 1_18_R2 and 1_19_R2
Version support for other version could/should be removed

Copy link
Collaborator

@tomkeuper tomkeuper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once 1.19 support is implented and the other not supported versions are removed we could give this pr a shot.


Explosion explosion = new Explosion(world, sourceEntity, null, null, locX, locY, locZ, radius, fire, Explosion.Effect.BREAK);
ExplosionDamageCalculator calculator = (sourceEntity == null ? STATIC_DMG_CALC : new ExplosionDamageCalculatorEntity(sourceEntity));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    // Copied from Explosion#a() (The NMS implementation of https://minecraft.fandom.com/wiki/Explosion#Model_of_block_destruction)

@andrei1058
Copy link
Owner

What's the impact on the main thread tho?

@IIHERO4
Copy link
Contributor Author

IIHERO4 commented Mar 10, 2023

I should note that In some cases this fails and over protect it as in the ray casting is too fat for example a block that is protected from one side and not the other will get protected because we check for the "components" of the ray
(B = block, G = glass, A = air, T = tnt)

B G
A T

ray checking:
R x
y (Since x hits G so its "protected")

I cant really work out a fix for this.

a second note is that i believe you could try to do it inside the NMS implementation itself instead of calling isProtected but i just didnt bother after couple of tries

@IIHERO4
Copy link
Contributor Author

IIHERO4 commented Mar 10, 2023

What's the impact on the main thread tho?

as far as im using it, it has close to none but you could tweak the "step" param to make less checks

# Conflicts:
#	bedwars-api/src/main/java/com/andrei1058/bedwars/api/server/VersionSupport.java
#	bedwars-plugin/src/main/java/com/andrei1058/bedwars/listeners/BreakPlace.java
#	versionsupport_1_10_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_10_R1/v1_10_R1.java
#	versionsupport_1_11_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_11_R1/v1_11_R1.java
#	versionsupport_1_12_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_12_R1/v1_12_R1.java
#	versionsupport_1_13_R2/src/main/java/com/andrei1058/bedwars/support/version/v1_13_R2/v1_13_R2.java
#	versionsupport_1_14_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_14_R1/v1_14_R1.java
#	versionsupport_1_15_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_15_R1/v1_15_R1.java
#	versionsupport_1_16_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_16_R1/v1_16_R1.java
#	versionsupport_1_16_R2/src/main/java/com/andrei1058/bedwars/support/version/v1_16_R2/v1_16_R2.java
#	versionsupport_1_8_R3/src/main/java/com/andrei1058/bedwars/support/version/v1_8_R3/v1_8_R3.java
#	versionsupport_1_9_R2/src/main/java/com/andrei1058/bedwars/support/version/v1_9_R2/v1_9_R2.java
#	versionsupport_v1_16_R3/src/main/java/com/andrei1058/bedwars/support/version/v1_16_R3/v1_16_R3.java
#	versionsupport_v1_17_R1/src/main/java/com/andrei1058/bedwars/support/version/v1_17_R1/v1_17_R1.java
@andrei1058 andrei1058 temporarily deployed to development June 24, 2023 17:10 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development June 24, 2023 20:10 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development July 15, 2023 19:06 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development July 16, 2023 14:33 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development July 16, 2023 14:41 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development July 16, 2023 14:48 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development July 16, 2023 14:50 — with GitHub Actions Inactive
@andrei1058 andrei1058 temporarily deployed to development July 16, 2023 14:51 — with GitHub Actions Inactive
if (explosionSize < 0) {
// Size is auto

InfoContainer prevInfo = cachedPrimes.get(e.getEntity());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to add NBT data on the entity, so we can avoid involving a new cache cleaner thread.

@andrei1058 andrei1058 changed the title Explosives rework Glass protection barrier rework Jul 16, 2023
@andrei1058 andrei1058 merged commit 535b44f into andrei1058:master Jul 16, 2023
1 check passed
andrei1058 added a commit that referenced this pull request Nov 10, 2023
* Fix sidebar title animation not working #660

* Fixed wins placeholder not in lobby sidebar #658

* Fixed NPE when clicking outside of shop inventory #664

* Fixed command error when lobby location is not set

* Added unformatted player name to kill message and bed destroy

* Added Netherite armor to 1.16+ (#657)

* Added missing items in v1_12_R1

* Fixed level just showing numer (#661)

* expose sidebar on API

* a few updates (#632)

* Italian Language Update

* Fix Moneys reward team-support on Solo & update variables names

* add sidebar init event

* fix team identifier length (#682)

* Bug fixes and placeholder adjustments (#685)

read pr details

* fix no tab formatting for first player (#692)

* fix losing permanent items on rejoin (#385)

* fix scoreboard getting send twice (#690)

* fix void tp on newer servers

* fix swords disappearing (#686)

* fix invisibility potion compatibility with 1.8.8

* fix lobby tablist (#701)

* Add translation for Simplified Chinese (#628)

Co-authored-by: hugeBlack <[email protected]>
Co-authored-by: YukiEnd233 <[email protected]>

* Remove hand from hideArmor

* fix placeholders

* Fix elapsed time always null (#574)

* fix header and footer

* clean up

* should fix #699

* Remove Deprecation Warning for Version and Update getServerVersion Methods (#623)

* Remove Version Deprecation Warning

* update methods that use getServerVersion()

* Update Sidebar API link in README.md for new sidebar

* More ReadME changes

* Back to Java 11 and some clean up

* Mark PrePartyListener for removal

* Massive Clean up

* Improve TeamEliminatedEvent JavaDoc

* Updates

* fix #712
fix #681

* Add user texture to player head (#333)

* Add gamesPlayed placeholder

* Fixed placeholder typos

* remove unnecessary teams

* fix placeholder

completely fix #724

* fix player name invisible on 1.8

* removed replace gens with air (#529)

* add check if respawning (#732)

* Add catch for teleport exceptions

* Add global placeholders

* Add global placeholders to header and footer (#730)

* Add invis removed message

* fix papi support

* keep old placeholder at least for a few updates

* Bug fixes (#740)

* fix no tab formatting for first player (#692)

* fix losing permanent items on rejoin (#385)

* fix scoreboard getting send twice (#690)

* fix void tp on newer servers

* fix swords disappearing (#686)

* fix invisibility potion compatibility with 1.8.8

* fix lobby tablist (#701)

* Remove hand from hideArmor

* fix placeholders

* Fix elapsed time always null (#574)

* fix header and footer

* clean up

* should fix #699

* fix #712
fix #681

* Add user texture to player head (#333)

* Add gamesPlayed placeholder

* Fixed placeholder typos

* remove unnecessary teams

* fix placeholder

completely fix #724

* fix player name invisible on 1.8

* removed replace gens with air (#529)

* add check if respawning (#732)

* Add catch for teleport exceptions

* Add global placeholders

* Add global placeholders to header and footer (#730)

* Add invis removed message

* fix papi support

* keep old placeholder at least for a few updates

---------

Co-authored-by: Andrei Dascălu <[email protected]>
Co-authored-by: andrei1058 <[email protected]>

* clean up

* Internal Party Additions (Promote, list/info commands) (#715)

* getOwner and promote methods to Party interface

* Add /party promote command and English Lang

* Add /party info/list commands

* break;

* add Romanian Lang

* add Italian Lang

* add Other Lang

* clean up

* clean up

* clean up

* add missing messages

* do not break addons

---------

Co-authored-by: Andrei Dascălu <[email protected]>

* Update Russian.java (#696)

update translations
Co-authored-by: Andrei Dascălu <[email protected]>

* add missing return

* Fix #760 (#792)

* Added placeholders {team} and {teamColor} to display the player team and its corresponding colors on the teleporter (#796)

* Added placeholders for {team} and {teamColor} to display the player team and their corresponding colors on the teleporter

* Fixed an error in calculating the player teleporter gui size

* limit size to 54

---------

Co-authored-by: Andrei Dascălu <[email protected]>

* Reduce some race conditions with IArena#getStatus (#775)

* Added support for 1.19_R3 (#761)

Co-authored-by: ItzCodex <[email protected]>

* Fix dropping and picking up items if main lobby is set on shared mode (#805)

* tag event handler

* fix drop/ pick up if main lobby is set on SHARED server type

* readme update (#811)

* Fixed bug where Dream Defender and Bed Bug were spawning at player's location instead of where they clicked. (#813)

Co-authored-by: PmzHeroV69 <[email protected]>

* Add 1.20 support (#814)

* add 1.20 support

* mention jetbrains

* add new sidebar version that supports 1.20

* fix missing dependency on 1.17+ (#817)

* world restore adapters update (#820)

* world restore adapters update

* update workflow

* update workflow

* update workflow

* update workflow

* add missing dependency

* Glass protection barrier rework (#469)

* Add VersionSupport#calculateExplosionBlocks

* Add isGlass & isProtectedByGlass to VersionSupport

* isProtectedByGlass performs ray tracing to ensure there is no glass
  inbetween

* Change VersionSupport#calculateExplosionBlocks implementation

* Implement v1_8_R3#calculateExplosionBlocks

* Copied from net.minecraft.server.v1_8_R3.Explosion#a() (The NMS implementation of
  https://minecraft.fandom.com/wiki/Explosion#Model_of_block_destruction)

* Implement v1_9_R2#calculateExplosionBlocks

* Implement v1_10_R1#calculateExplosionBlocks

* Implement v1_11_R1#calculateExplosionBlocks

* Implement v1_12_R1#calculateExplosionBlocks

* Implement v1_13_R2#calculateExplosionBlocks

* Fix wrong behavior from locY in calculateExplosionBlocks

* Implement v1_14_R1#calculateExplosionBlocks

* Fix tnt breaking blocks under water @ 1.13

* Fix locY @ 1.12

* Fix blocks under water getting exploded

* Fix comments

* Implement v1_15_R1#calculateExplosionBlocks

* Implement v1_16_*#calculateExplosionBlocks

* Add exceptions for not implemented versions of calculateExplosionBlocks

* Change radius of explosion to float instead of int

* Reimplement explosive-related events to use NMS/better detection

* Add Config explosion-settings.explosion-size
* if size is set to auto OR any negative value it will cache the actual
  size of that entity, if it could not cache it (not found) then the
  default implementation is used (removing and protecting blocks)

* Fix location hashing rounding instead of flooring coords

* Add function caching to the default callback of calculateExplosionBlocks

* Add comment describing whatever this is

* Fix ExplosionPrimeEvent not being check correctly

* Fix distances being calculated wrong in VersionSupport#isProtectedByGlass

* Add BlockRay for better ray tracing

* Reimplement VersionSupport#isProtected and its events

* Fix typo

* Remove debug junk

* Add cache cleaning for BreakPlace

* test if block is placed in special cases

* Fix air being counted as a block

* Increase caching lifetime & change keys to Entity

* always manage explosions even if blockList is empty

* Fix imports

* Fix inaccurate calculation of the delta vector in BlockRay

* Add the 3 missing components to BlockRay

* wip

* wip

* implement explosion function

* improvements and clean up

* clean up

* clean up

* clean up

* fix typo

---------

Co-authored-by: Andrei Dascălu <[email protected]>

* Fix default tower item (#831)

Fixed bug where wrong tower item was added as invalid material in shop.yml

* version string update

* change heal pool work (#832)

* change heal pool work

Since the upgrade price is likely to be different for each arena group, if the upgrade has a heal-pool in the name, it is changed to work

* Fix magic miner upgrade (#830)

* Fix magic miner upgrade

Fixed bug where magic miner upgrade was showing wrong material name in version 1.13 and above.

* Fix heal pool not working (#829)

Fixed bug preventing heal pool from working with wrong config path

* Fix sword upgrade (#828)

Fixed bug where upgrade-swords purchases in the upgrade shop didn't apply to axes

* fix missed implementation

* Fix Parties getParty with player UUID (#860)

* fix not loading (#875)

* Sidebar and Tab improvements, session stats remake (#845)

tab rework, sidebar imrovements, new top system and session statistics

* add 1.20 r2 support (#896)

* add 1.20 r2 support

* version string update

* Fix PAF Null issue (#853)

* Fix PAF Null issue

* Update Github actions

* Build 1.20 module against 1.20.1

* fix disablearena command (#839)

Changed this arena to not be disabled if a game is in progress

The reason for the change is that many errors occur when disableArena and enableArena. I will upload the file

* correct silverfish name (#840)

correct silverfish name

* Fix block protection (#841)

* Fix block protection

Fixed bug where shop protection and upgrades protection and generators protection did not work

* fix

fix

* SpoilPlayerTNTFeature code improvements (#892)

SpoilPlayerTNTFeature code improvements

---------

Co-authored-by: Tom Keuper <[email protected]>
Co-authored-by: Yuri <[email protected]>
Co-authored-by: skbeh <[email protected]>
Co-authored-by: hugeBlack <[email protected]>
Co-authored-by: YukiEnd233 <[email protected]>
Co-authored-by: J.T. McQuigg <[email protected]>
Co-authored-by: Matveev_ <[email protected]>
Co-authored-by: grass <[email protected]>
Co-authored-by: Tom <[email protected]>
Co-authored-by: ItzCodex <[email protected]>
Co-authored-by: PmzHeroV69 <[email protected]>
Co-authored-by: PmzHeroV69 <[email protected]>
Co-authored-by: IIHERO4 <[email protected]>
Co-authored-by: Yenil <[email protected]>
Co-authored-by: AlessioDP <[email protected]>
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.

6 participants