Skip to content

Commit

Permalink
feat: new 1.20.3 entity types and spigot-version of potion effect typ…
Browse files Browse the repository at this point in the history
…e registry
  • Loading branch information
Misat11 committed Dec 7, 2023
1 parent caa1f34 commit 7907c4f
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public class BukkitFeature {
public static final @NotNull PlatformFeature ENTITY_ZOMBIE_PIGLIN_ZOGLIN_EXTENDS_AGEABLE = PlatformFeature.of(() -> org.bukkit.entity.Ageable.class.isAssignableFrom(org.bukkit.entity.Zombie.class));
public static final @NotNull PlatformFeature ENTITY_THROWABLE_PROJECTILE = PlatformFeature.of(() -> Reflect.has("org.bukkit.entity.ThrowableProjectile"));
public static final @NotNull PlatformFeature ENTITY_THROWN_POTION_EXTENDS_THROWABLE_PROJECTILE = ENTITY_THROWABLE_PROJECTILE.and(() -> org.bukkit.entity.ThrowableProjectile.class.isAssignableFrom(org.bukkit.entity.ThrownPotion.class));
public static final @NotNull PlatformFeature ENTITY_BREEZE = PlatformFeature.of(() -> Reflect.has("org.bukkit.entity.Breeze"));
public static final @NotNull PlatformFeature ENTITY_WIND_CHARGE = PlatformFeature.of(() -> Reflect.has("org.bukkit.entity.WindCharge"));

// WORLD
public static final @NotNull PlatformFeature WORLD_MIN_HEIGHT = PlatformFeature.of(() -> Reflect.hasMethod(World.class, "getMinHeight"));
Expand All @@ -221,6 +223,7 @@ public class BukkitFeature {
public static final @NotNull PlatformFeature POTION_API = PlatformFeature.of(() -> Version.isVersion(1, 9));

public static final @NotNull PlatformFeature POTION_EFFECT_TYPE_REGISTRY = PlatformFeature.of(() -> Version.isVersion(1, 18, 2) && Reflect.getField("org.bukkit.Registry", "POTION_EFFECT_TYPE") != null); // exclusive to paper
public static final @NotNull PlatformFeature POTION_EFFECT_TYPE_REGISTRY_SPIGOT = PlatformFeature.of(() -> Reflect.getField("org.bukkit.Registry", "EFFECT") != null);
public static final @NotNull PlatformFeature POTION_EFFECT_KEYED = PlatformFeature.of(() -> Version.isVersion(1, 18));
public static final @NotNull PlatformFeature POTION_EFFECT_CONSTRUCTOR_WITH_ICON = PlatformFeature.of(() -> Reflect.constructor(PotionEffect.class, PotionEffectType.class, int.class, int.class, boolean.class, boolean.class, boolean.class).isPresent());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.screamingsandals.lib.impl.bukkit.entity.hanging.BukkitItemFrame;
import org.screamingsandals.lib.impl.bukkit.entity.hanging.BukkitLeashKnot;
import org.screamingsandals.lib.impl.bukkit.entity.hanging.BukkitPainting;
import org.screamingsandals.lib.impl.bukkit.entity.monster.BukkitBreeze;
import org.screamingsandals.lib.impl.bukkit.entity.monster.BukkitEnderDragon;
import org.screamingsandals.lib.impl.bukkit.entity.monster.BukkitRavager;
import org.screamingsandals.lib.impl.bukkit.entity.monster.BukkitVex;
Expand Down Expand Up @@ -149,6 +150,7 @@
import org.screamingsandals.lib.impl.bukkit.entity.projectile.BukkitThrowableProjectileEntity;
import org.screamingsandals.lib.impl.bukkit.entity.projectile.BukkitThrownPotion;
import org.screamingsandals.lib.impl.bukkit.entity.projectile.BukkitTrident;
import org.screamingsandals.lib.impl.bukkit.entity.projectile.BukkitWindCharge;
import org.screamingsandals.lib.impl.bukkit.entity.projectile.BukkitWitherSkull;
import org.screamingsandals.lib.impl.bukkit.entity.slime.BukkitMagmaCube;
import org.screamingsandals.lib.impl.bukkit.entity.slime.BukkitSlime;
Expand Down Expand Up @@ -619,6 +621,12 @@ public class BukkitEntities extends Entities {
}
}

if (BukkitFeature.ENTITY_BREEZE.isSupported()) {
if (entity instanceof org.bukkit.entity.Breeze) {
return new BukkitBreeze((org.bukkit.entity.Breeze) entity);
}
}

return new BukkitMonster((org.bukkit.entity.Monster) entity);
}

Expand Down Expand Up @@ -777,6 +785,12 @@ public class BukkitEntities extends Entities {
}
}

if (BukkitFeature.ENTITY_WIND_CHARGE.isSupported()) {
if (entity instanceof org.bukkit.entity.WindCharge) {
return new BukkitWindCharge((org.bukkit.entity.WindCharge) entity);
}
}

return new BukkitHurtingProjectileEntity((org.bukkit.entity.Fireball) entity);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 ScreamingSandals
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.screamingsandals.lib.impl.bukkit.entity.monster;

import org.jetbrains.annotations.NotNull;
import org.screamingsandals.lib.entity.monster.Breeze;

public class BukkitBreeze extends BukkitMonster implements Breeze {
public BukkitBreeze(@NotNull org.bukkit.entity.Breeze wrappedObject) {
super(wrappedObject);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 ScreamingSandals
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.screamingsandals.lib.impl.bukkit.entity.projectile;

import org.jetbrains.annotations.NotNull;
import org.screamingsandals.lib.entity.projectile.WindCharge;

public class BukkitWindCharge extends BukkitHurtingProjectileEntity implements WindCharge {
public BukkitWindCharge(@NotNull org.bukkit.entity.WindCharge wrappedObject) {
super(wrappedObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,33 @@ public BukkitPotionEffectTypeRegistry() {

@Override
protected @Nullable PotionEffectType resolveMappingPlatform(@NotNull ResourceLocation location) {
if (BukkitFeature.POTION_EFFECT_TYPE_REGISTRY.isSupported()) {
if (BukkitFeature.POTION_EFFECT_TYPE_REGISTRY_SPIGOT.isSupported()) {
var potionEffectType = Registry.EFFECT.get(new NamespacedKey(location.namespace(), location.path()));
if (potionEffectType != null) {
return new BukkitPotionEffectType(potionEffectType);
}

// try bukkit name (deprecated, TODO: prepare shop/config migration scripts and remove)
if ("minecraft".equalsIgnoreCase(location.namespace())) {
var path = location.path();
switch (path) {
case "slow": path = "slowness"; break;
case "fast_digging": path = "haste"; break;
case "slow_digging": path = "mining_fatigue"; break;
case "increase_damage": path = "strength"; break;
case "heal": path = "instant_health"; break;
case "harm": path = "instant_damage"; break;
case "jump": path = "jump_boost"; break;
case "confusion": path = "nausea"; break;
case "damage_resistance": path = "resistance"; break;
}

potionEffectType = Registry.EFFECT.get(new NamespacedKey("minecraft", path));
if (potionEffectType != null) {
return new BukkitPotionEffectType(potionEffectType);
}
}
} else if (BukkitFeature.POTION_EFFECT_TYPE_REGISTRY.isSupported()) {
var potionEffectType = Registry.POTION_EFFECT_TYPE.get(new NamespacedKey(location.namespace(), location.path()));
if (potionEffectType != null) {
return new BukkitPotionEffectType(potionEffectType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.screamingsandals.lib.entity.monster;

import org.screamingsandals.lib.utils.annotations.ide.LimitedVersionSupport;

/**
* Represents an entity with identifier {@code minecraft:breeze}.
*/
@LimitedVersionSupport(">= 1.20.3")
public interface Breeze extends Monster {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.screamingsandals.lib.entity.ExplosiveEntity;

/**
* An abstract type for such called hurting projectiles (fireballs, dragon fireball and wither skull).
* An abstract type for such called hurting projectiles (fireballs, dragon fireball, wither skull and wind charge ).
*/
public interface HurtingProjectileEntity extends ProjectileEntity, ExplosiveEntity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.screamingsandals.lib.entity.projectile;

import org.screamingsandals.lib.utils.annotations.ide.LimitedVersionSupport;

/**
* Represents an entity with identifier {@code minecraft:wind_charge}.
*/
@LimitedVersionSupport(">= 1.20.3")
public interface WindCharge extends HurtingProjectileEntity {
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# platforms
paper = "1.20.2-R0.1-SNAPSHOT"
paper = "1.20.4-R0.1-SNAPSHOT"
sponge = "8.2.0"
minestom = "master-SNAPSHOT"
waterfall = "1.20-R0.1-SNAPSHOT"
Expand Down

0 comments on commit 7907c4f

Please sign in to comment.