Skip to content

Commit 09ce356

Browse files
Pablete1234KaevonD
authored andcommitted
Further cleanup and bugfixes
Signed-off-by: Pablo Herrera <pabloherrerapalacio@gmail.com>
1 parent 4c62a80 commit 09ce356

File tree

7 files changed

+82
-94
lines changed

7 files changed

+82
-94
lines changed

core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public void onClickEvent(PlayerInteractEvent event) {
122122
}
123123
}
124124
case ProjectileDefinition.BlockEntityType ce -> {
125-
var be = BlockEntity.spawnBlockEntity(
126-
player.getEyeLocation(), definition.blockMaterial, ce.size(), velocity);
127-
new BlockRunner(definition, be, player, player.getEyeLocation());
125+
Location loc = player.getEyeLocation();
126+
var be = BlockEntity.spawnBlockEntity(loc, definition.blockMaterial, ce.size(), velocity);
127+
new BlockRunner(definition, be, player, loc);
128128
}
129129
}
130130

@@ -371,11 +371,9 @@ private void cancel() {
371371

372372
private boolean blockDisplayCollision(Location location) {
373373
double radius = 0.5 * ce.size();
374-
// Make location be center of the entity instead of feet
375-
location.setY(location.getY() + radius);
376374

377375
if (definition.damage != null) {
378-
for (Player victim : location.getNearbyPlayers(0.5 * ce.size())) {
376+
for (Player victim : location.getNearbyPlayers(radius)) {
379377
var mpVictim = match.getPlayer(victim);
380378
if (MatchPlayers.canInteract(mpVictim) && mpVictim.getParty() != shooterParty) {
381379
victim.damage(definition.damage, player);
@@ -384,13 +382,12 @@ private boolean blockDisplayCollision(Location location) {
384382
}
385383
}
386384
if (ce.solidBlockCollision()) {
387-
388385
int x1 = (int) Math.floor(location.getX() - radius);
389-
int y1 = (int) Math.floor(location.getY());
386+
int y1 = (int) Math.floor(location.getY() - radius);
390387
int z1 = (int) Math.floor(location.getZ() - radius);
391388

392389
int x2 = (int) Math.floor(location.getX() + radius);
393-
int y2 = (int) Math.floor(location.getY() + ce.size());
390+
int y2 = (int) Math.floor(location.getY() + radius);
394391
int z2 = (int) Math.floor(location.getZ() + radius);
395392

396393
Location loc = location.clone();
@@ -407,8 +404,6 @@ private boolean blockDisplayCollision(Location location) {
407404
}
408405
}
409406

410-
// revert back to normal
411-
location.setY(location.getY() - radius);
412407
return false;
413408
}
414409
}

platform/platform-modern/src/main/java/tc/oc/pgm/platform/modern/entities/ModernBlockEntity.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
public class ModernBlockEntity implements BlockEntity.Factory {
1919
@Override
2020
public BlockEntity spawnBlockEntity(
21-
Location loc, BlockMaterialData blockMaterialData, float size, Vector velocity) {
22-
Location corrected = loc.clone();
21+
Location center, BlockMaterialData blockMaterialData, float size, Vector velocity) {
22+
Location corrected = center.clone();
2323
corrected.setPitch(0);
2424
corrected.setYaw(0);
25-
final BlockDisplay entity = loc.getWorld().spawn(corrected, BlockDisplay.class);
25+
final BlockDisplay entity = center.getWorld().spawn(corrected, BlockDisplay.class);
2626
entity.setBlock(((ModernBlockMaterialData) blockMaterialData).getBlock());
2727
entity.setTeleportDuration(1);
2828

@@ -31,8 +31,8 @@ public BlockEntity spawnBlockEntity(
3131

3232
final Matrix4f rotationMatrix = new Matrix4f();
3333
final Quaternionf rotation = new Quaternionf();
34-
rotation.rotateLocalX((float) Math.toRadians(-loc.getPitch()));
35-
rotation.rotateLocalY((float) Math.toRadians(180 - loc.getYaw()));
34+
rotation.rotateLocalX((float) Math.toRadians(-center.getPitch()));
35+
rotation.rotateLocalY((float) Math.toRadians(180 - center.getYaw()));
3636
rotation.get(rotationMatrix);
3737

3838
final Matrix4f scaleMatrix = new Matrix4f().scale(size);
@@ -44,12 +44,8 @@ public BlockEntity spawnBlockEntity(
4444

4545
private record Impl(Entity entity) implements BlockEntity {
4646

47-
public Location getLocation() {
48-
return entity.getLocation();
49-
}
50-
51-
public void teleport(Location loc) {
52-
entity.teleport(loc);
47+
public void teleport(Location center) {
48+
entity.teleport(center);
5349
}
5450

5551
@Override

platform/platform-modern/src/main/java/tc/oc/pgm/platform/modern/impl/ModernNMSHacks.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import org.bukkit.craftbukkit.entity.CraftFirework;
6262
import org.bukkit.craftbukkit.generator.CraftWorldInfo;
6363
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
64-
import org.bukkit.entity.BlockDisplay;
6564
import org.bukkit.entity.Entity;
6665
import org.bukkit.entity.Fireball;
6766
import org.bukkit.entity.Firework;
@@ -451,9 +450,4 @@ public int getMaxWorldSize(World world) {
451450
public int allocateEntityId() {
452451
return Bukkit.getUnsafe().nextEntityId();
453452
}
454-
455-
@Override
456-
public boolean isBlockDisplayEntity(Class<? extends Entity> entity) {
457-
return entity.isAssignableFrom(BlockDisplay.class);
458-
}
459453
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package tc.oc.pgm.platform.sportpaper.entities;
2+
3+
import static tc.oc.pgm.util.platform.Supports.Variant.SPORTPAPER;
4+
5+
import net.minecraft.server.v1_8_R3.EntityArmorStand;
6+
import org.bukkit.Location;
7+
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand;
8+
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFallingSand;
9+
import org.bukkit.entity.ArmorStand;
10+
import org.bukkit.util.Vector;
11+
import tc.oc.pgm.util.bukkit.entities.BlockEntity;
12+
import tc.oc.pgm.util.material.BlockMaterialData;
13+
import tc.oc.pgm.util.platform.Supports;
14+
15+
@Supports(SPORTPAPER)
16+
public class SpBlockEntity implements BlockEntity.Factory {
17+
// We use a falling sand entity, which is 1 block high, so we want to lower actual positon by half
18+
// of that
19+
private static final double OFFSET = 0.5d;
20+
21+
@Override
22+
public BlockEntity spawnBlockEntity(
23+
Location center, BlockMaterialData blockMaterialData, float size, Vector velocity) {
24+
center.setY(center.getY() - OFFSET);
25+
var fallingBlock = blockMaterialData.spawnFallingBlock(center);
26+
var stand = center.getWorld().spawn(center, ArmorStand.class);
27+
stand.setCustomNameVisible(false);
28+
stand.setVisible(false);
29+
stand.setMarker(true);
30+
stand.setBasePlate(false);
31+
stand.setGravity(false);
32+
stand.setPassenger(fallingBlock);
33+
34+
// Reset the original location
35+
center.setY(center.getY() + OFFSET);
36+
37+
var nmsStand = ((CraftArmorStand) stand).getHandle();
38+
var nmsFallingSand = ((CraftFallingSand) fallingBlock).getHandle();
39+
// Noclip makes movement ignore all collisions (faster), which we don't need as we run our own
40+
nmsStand.noclip = true;
41+
nmsFallingSand.noclip = true;
42+
43+
return new Impl(stand, nmsStand);
44+
}
45+
46+
private record Impl(ArmorStand bukkit, EntityArmorStand nms) implements BlockEntity {
47+
@Override
48+
public void teleport(Location l) {
49+
// We NEED to use NMS move because bukkit's teleport does not work on entities with passengers
50+
nms.move(l.getX() - nms.locX, l.getY() - nms.locY - OFFSET, l.getZ() - nms.locZ);
51+
}
52+
53+
@Override
54+
public void remove() {
55+
bukkit.getPassenger().remove();
56+
bukkit.remove();
57+
}
58+
}
59+
}

platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/entities/SpCustomEntities.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

platform/platform-sportpaper/src/main/java/tc/oc/pgm/platform/sportpaper/impl/SpNMSHacks.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,4 @@ public int getMaxWorldSize(World world) {
225225
public int allocateEntityId() {
226226
return Bukkit.allocateEntityId();
227227
}
228-
229-
@Override
230-
public boolean isBlockDisplayEntity(Class<? extends Entity> entity) {
231-
return false;
232-
}
233228
}

util/src/main/java/tc/oc/pgm/util/bukkit/entities/BlockEntity.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
import tc.oc.pgm.util.material.BlockMaterialData;
66
import tc.oc.pgm.util.platform.Platform;
77

8+
/**
9+
* Implements a wrapper for block-like entities, used for projectiles. Modern implementations will
10+
* use display entities, legacy (1.8) will use falling sand. <br>
11+
*
12+
* @implNote For this class, location is actually the center of the entity
13+
*/
814
public interface BlockEntity {
915
BlockEntity.Factory FACTORY = Platform.get(BlockEntity.Factory.class);
1016

1117
static BlockEntity spawnBlockEntity(
12-
Location loc, BlockMaterialData blockMaterialData, float size, Vector velocity) {
13-
return FACTORY.spawnBlockEntity(loc, blockMaterialData, size, velocity);
18+
Location center, BlockMaterialData blockMaterialData, float size, Vector velocity) {
19+
return FACTORY.spawnBlockEntity(center, blockMaterialData, size, velocity);
1420
}
1521

16-
Location getLocation();
17-
18-
void teleport(Location loc);
22+
void teleport(Location center);
1923

2024
void remove();
2125

2226
interface Factory {
2327
BlockEntity spawnBlockEntity(
24-
Location loc, BlockMaterialData blockMaterialData, float size, Vector velocity);
28+
Location center, BlockMaterialData blockMaterialData, float size, Vector velocity);
2529
}
2630
}

0 commit comments

Comments
 (0)