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

Update to 1.21.4 #62

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
/build/
/build/classes/java/main/
/build/classes/java/test/
.settings/
.project
.classpath
bin/

# Minestom
/.minestom_tmp/
/.mixin.out/
/minecraft_data/
/minecraft_data/
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ java {
}

dependencies {
compileOnly 'net.minestom:minestom-snapshots:7ce047b22e'
testImplementation 'net.minestom:minestom-snapshots:7ce047b22e'
compileOnly 'net.minestom:minestom-snapshots:1_21_4-4da5831880'
testImplementation 'net.minestom:minestom-snapshots:1_21_4-4da5831880'
//testImplementation 'com.github.TogAr2:MinestomFluids:b237b13a4b'
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/togar2/pvp/MinestomPvP.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static EventNode<EntityInstanceEvent> legacyEvents() {
* @param legacyAttack {@code true} if legacy attack should be enabled
*/
public static void setLegacyAttack(Player player, boolean legacyAttack) {
AttributeInstance speed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
AttributeInstance speed = player.getAttribute(Attribute.ATTACK_SPEED);
if (legacyAttack) {
speed.setBaseValue(100);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static DamageTypeInfo of(DynamicRegistry.Key<DamageType> type) {

//TODO check source and add missing
public static final Map<DynamicRegistry.Key<DamageType>, DamageTypeInfo> INFO_MAP = new HashMap<>() {
private static final long serialVersionUID = -1415972772651275647L;
{
put(DamageType.IN_FIRE, new DamageTypeInfo().bypassesArmor(true).fire(true));
put(DamageType.ON_FIRE, new DamageTypeInfo().bypassesArmor(true).fire(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,10 @@ public Component getEntityName() {
return EntityUtil.getName(player);
}

@SuppressWarnings("UnstableApiUsage")
private void onEnterCombat() {
player.getPlayerConnection().sendPacket(new EnterCombatEventPacket());
}

@SuppressWarnings("UnstableApiUsage")
private void onLeaveCombat() {
int duration = (int) (getCombatDuration() / MinecraftServer.TICK_MS);
player.getPlayerConnection().sendPacket(new EndCombatEventPacket(duration));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.github.togar2.pvp.entity.explosion;

import org.jetbrains.annotations.NotNull;

import io.github.togar2.pvp.damage.DamageTypeInfo;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.LivingEntity;
import net.minestom.server.entity.damage.Damage;
import net.minestom.server.entity.metadata.other.EndCrystalMeta;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.InstanceContainer;
import net.minestom.server.instance.block.Block;
import net.minestom.server.tag.Tag;
import org.jetbrains.annotations.NotNull;

public class CrystalEntity extends LivingEntity {
private final boolean fire;
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/io/github/togar2/pvp/entity/projectile/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.LivingEntity;
import net.minestom.server.entity.metadata.projectile.ArrowMeta;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
Expand Down Expand Up @@ -49,39 +48,19 @@ protected ItemStack getPickupItem() {

public void setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
updateColor();
}

@Override
protected void onHurt(LivingEntity entity) {
effectFeature.addArrowEffects(entity, this);
}

private void updateColor() {
PotionContents potionContents = itemStack.get(ItemComponent.POTION_CONTENTS);
if (potionContents == null || potionContents.equals(PotionContents.EMPTY)) {
setColor(-1);
return;
}

setColor(effectFeature.getPotionColor(potionContents));
}

private void setColor(int color) {
((ArrowMeta) getEntityMeta()).setColor(color);
}

private int getColor() {
return ((ArrowMeta) getEntityMeta()).getColor();
}

public @NotNull PotionContents getPotion() {
return itemStack.get(ItemComponent.POTION_CONTENTS, PotionContents.EMPTY);
}

public void setPotion(@NotNull PotionContents potion) {
this.itemStack = ItemStack.of(Material.TIPPED_ARROW).with(ItemComponent.POTION_CONTENTS, potion);
updateColor();
}

public void addArrowEffect(CustomPotionEffect effect) {
Expand All @@ -90,6 +69,5 @@ public void addArrowEffect(CustomPotionEffect effect) {
list.add(effect);
return new PotionContents(potionContents.potion(), potionContents.customColor(), list);
});
updateColor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ protected void movementTick() {
setNoGravity(true);
this.collisionDirection = collisionDirection;
shouldRemove.set(onStuck());
scheduler().scheduleNextProcess(() -> {
this.setVelocity(Vec.ZERO);
});
});

if (shouldRemove.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void teleportOwner() {

for (int i = 0; i < 32; i++) {
sendPacketToViewersAndSelf(new ParticlePacket(
Particle.PORTAL, false,
Particle.PORTAL, false, true,
position.x(), position.y() + random.nextDouble() * 2, position.z(),
(float) random.nextGaussian(), 0.0F, (float) random.nextGaussian(),
0, 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import io.github.togar2.pvp.utils.EffectUtil;
import net.minestom.server.collision.BoundingBox;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.effects.Effects;
import net.minestom.server.entity.*;
import net.minestom.server.entity.metadata.item.ThrownPotionMeta;
import net.minestom.server.item.ItemComponent;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.item.component.PotionContents;
import net.minestom.server.potion.Potion;
import net.minestom.server.worldevent.WorldEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -66,7 +66,7 @@ public void splash(@Nullable Entity entity) {
}
}

Effects effect = instantEffect ? Effects.INSTANT_SPLASH : Effects.SPLASH_POTION;
WorldEvent effect = instantEffect ? WorldEvent.PARTICLES_INSTANT_POTION_SPLASH : WorldEvent.PARTICLES_SPELL_POTION_SPLASH;
EffectUtil.sendNearby(
Objects.requireNonNull(getInstance()), effect, position.blockX(),
position.blockY(), position.blockZ(), effectFeature.getPotionColor(potionContents),
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/github/togar2/pvp/enums/ArmorMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ public static void updateEquipmentAttributes(LivingEntity entity, ItemStack oldS
// Remove attributes from previous armor
if (oldMaterial != null && hasDefaultAttributes(oldStack)) {
if (slot == getRequiredSlot(oldStack.material())) {
entity.getAttribute(Attribute.GENERIC_ARMOR).removeModifier(modifierId);
entity.getAttribute(Attribute.GENERIC_ARMOR_TOUGHNESS).removeModifier(modifierId);
entity.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).removeModifier(modifierId);
entity.getAttribute(Attribute.ARMOR).removeModifier(modifierId);
entity.getAttribute(Attribute.ARMOR_TOUGHNESS).removeModifier(modifierId);
entity.getAttribute(Attribute.KNOCKBACK_RESISTANCE).removeModifier(modifierId);
}
}

// Add attributes from new armor
if (newMaterial != null && hasDefaultAttributes(newStack)) {
if (slot == getRequiredSlot(newStack.material())) {
entity.getAttribute(Attribute.GENERIC_ARMOR).addModifier(new AttributeModifier(modifierId, newMaterial.getProtectionAmount(slot, version), AttributeOperation.ADD_VALUE));
entity.getAttribute(Attribute.GENERIC_ARMOR_TOUGHNESS).addModifier(new AttributeModifier(modifierId, newMaterial.getToughness(), AttributeOperation.ADD_VALUE));
entity.getAttribute(Attribute.ARMOR).addModifier(new AttributeModifier(modifierId, newMaterial.getProtectionAmount(slot, version), AttributeOperation.ADD_VALUE));
entity.getAttribute(Attribute.ARMOR_TOUGHNESS).addModifier(new AttributeModifier(modifierId, newMaterial.getToughness(), AttributeOperation.ADD_VALUE));
if (newMaterial.getKnockbackResistance() > 0) {
entity.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).addModifier(new AttributeModifier(modifierId, newMaterial.getKnockbackResistance(), AttributeOperation.ADD_VALUE));
entity.getAttribute(Attribute.KNOCKBACK_RESISTANCE).addModifier(new AttributeModifier(modifierId, newMaterial.getKnockbackResistance(), AttributeOperation.ADD_VALUE));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/github/togar2/pvp/enums/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public enum Tool {
float finalLegacyAttackDamage = legacyAttackDamage + (toolMaterial == null ? 0 : toolMaterial.getAttackDamage());
this.material = Material.fromNamespaceId(this.name().toLowerCase());

this.attributeModifiers.put(Attribute.GENERIC_ATTACK_DAMAGE, new AttributeModifier(ModifierId.ATTACK_DAMAGE_MODIFIER_ID, finalAttackDamage, AttributeOperation.ADD_VALUE));
this.attributeModifiers.put(Attribute.GENERIC_ATTACK_SPEED, new AttributeModifier(ModifierId.ATTACK_SPEED_MODIFIER_ID, attackSpeed, AttributeOperation.ADD_VALUE));
this.attributeModifiers.put(Attribute.ATTACK_DAMAGE, new AttributeModifier(ModifierId.ATTACK_DAMAGE_MODIFIER_ID, finalAttackDamage, AttributeOperation.ADD_VALUE));
this.attributeModifiers.put(Attribute.ATTACK_SPEED, new AttributeModifier(ModifierId.ATTACK_SPEED_MODIFIER_ID, attackSpeed, AttributeOperation.ADD_VALUE));

this.legacyAttributeModifiers.put(Attribute.GENERIC_ATTACK_DAMAGE, new AttributeModifier(ModifierId.ATTACK_DAMAGE_MODIFIER_ID, finalLegacyAttackDamage, AttributeOperation.ADD_VALUE));
this.legacyAttributeModifiers.put(Attribute.ATTACK_DAMAGE, new AttributeModifier(ModifierId.ATTACK_DAMAGE_MODIFIER_ID, finalLegacyAttackDamage, AttributeOperation.ADD_VALUE));
}

Tool(@Nullable ToolMaterial toolMaterial, float attackDamage, float legacyAttackDamage, float attackSpeed, boolean isAxe, boolean isSword) {
Expand All @@ -90,8 +90,8 @@ public static void updateEquipmentAttributes(LivingEntity entity, ItemStack oldS

// Remove attributes from previous tool
if (oldTool != null && hasDefaultAttributes(oldStack)) {
entity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).removeModifier(ModifierId.ATTACK_DAMAGE_MODIFIER_ID);
entity.getAttribute(Attribute.GENERIC_ATTACK_SPEED).removeModifier(ModifierId.ATTACK_SPEED_MODIFIER_ID);
entity.getAttribute(Attribute.ATTACK_DAMAGE).removeModifier(ModifierId.ATTACK_DAMAGE_MODIFIER_ID);
entity.getAttribute(Attribute.ATTACK_SPEED).removeModifier(ModifierId.ATTACK_SPEED_MODIFIER_ID);
}

// Add attributes from new tool
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/io/github/togar2/pvp/events/TotemUseEvent.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package io.github.togar2.pvp.events;

import org.jetbrains.annotations.NotNull;

import net.minestom.server.entity.LivingEntity;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.PlayerHand;
import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.EntityInstanceEvent;
import org.jetbrains.annotations.NotNull;

/**
* Called when a totem prevents an entity from dying.
*/
public class TotemUseEvent implements EntityInstanceEvent, CancellableEvent {

private final LivingEntity entity;
private final Player.Hand hand;
private final PlayerHand hand;

private boolean cancelled;

public TotemUseEvent(@NotNull LivingEntity entity, @NotNull Player.Hand hand) {
public TotemUseEvent(@NotNull LivingEntity entity, @NotNull PlayerHand hand) {
this.entity = entity;
this.hand = hand;
}
Expand All @@ -28,7 +29,7 @@ public LivingEntity getEntity() {
}

@NotNull
public Player.Hand getHand() {
public PlayerHand getHand() {
return hand;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.togar2.pvp.feature.armor;

import io.github.togar2.pvp.damage.DamageTypeInfo;
import io.github.togar2.pvp.feature.CombatFeature;
import io.github.togar2.pvp.feature.FeatureType;
import io.github.togar2.pvp.feature.config.DefinedFeature;
import io.github.togar2.pvp.feature.config.FeatureConfiguration;
Expand All @@ -18,7 +17,7 @@
/**
* Vanilla implementation of {@link ArmorFeature}
*/
public class VanillaArmorFeature implements ArmorFeature, CombatFeature {
public class VanillaArmorFeature implements ArmorFeature {
public static final DefinedFeature<VanillaArmorFeature> DEFINED = new DefinedFeature<>(
FeatureType.ARMOR, VanillaArmorFeature::new,
FeatureType.ENCHANTMENT, FeatureType.VERSION
Expand Down Expand Up @@ -48,14 +47,14 @@ public float getDamageWithProtection(LivingEntity entity, DamageType type, float
protected float getDamageWithArmor(LivingEntity entity, DamageTypeInfo typeInfo, float amount) {
if (typeInfo.bypassesArmor()) return amount;

double armorValue = entity.getAttributeValue(Attribute.GENERIC_ARMOR);
double armorValue = entity.getAttributeValue(Attribute.ARMOR);
if (version.legacy()) {
int armorMultiplier = 25 - (int) armorValue;
return (amount * (float) armorMultiplier) / 25;
} else {
return getDamageLeft(
amount, (float) Math.floor(armorValue),
(float) entity.getAttributeValue(Attribute.GENERIC_ARMOR_TOUGHNESS)
(float) entity.getAttributeValue(Attribute.ARMOR_TOUGHNESS)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public boolean performAttack(LivingEntity attacker, Entity target) {
int particleCount = (int) (damageDone * 0.5);
Pos targetPosition = target.getPosition();
target.sendPacketToViewersAndSelf(new ParticlePacket(
Particle.DAMAGE_INDICATOR, false,
Particle.DAMAGE_INDICATOR, false, false,
targetPosition.x(), targetPosition.y() + target.getBoundingBox().height() * 0.5, targetPosition.z(),
0.1f, 0, 0.1f,
0.2F, particleCount
Expand All @@ -200,7 +200,7 @@ public boolean performAttack(LivingEntity attacker, Entity target) {
}

protected @Nullable AttackValues.Final prepareAttack(LivingEntity attacker, Entity target) {
float damage = (float) attacker.getAttributeValue(Attribute.GENERIC_ATTACK_DAMAGE);
float damage = (float) attacker.getAttributeValue(Attribute.ATTACK_DAMAGE);
float magicalDamage = enchantmentFeature.getAttackDamage(
attacker.getItemInMainHand(),
target instanceof LivingEntity living ? EntityGroup.ofEntity(living) : EntityGroup.DEFAULT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.togar2.pvp.feature.attack;

import io.github.togar2.pvp.feature.CombatFeature;
import io.github.togar2.pvp.feature.FeatureType;
import io.github.togar2.pvp.feature.config.DefinedFeature;
import io.github.togar2.pvp.feature.config.FeatureConfiguration;
Expand All @@ -14,7 +13,7 @@
/**
* Vanilla implementation of {@link CriticalFeature}
*/
public class VanillaCriticalFeature implements CriticalFeature, CombatFeature {
public class VanillaCriticalFeature implements CriticalFeature {
public static final DefinedFeature<VanillaCriticalFeature> DEFINED = new DefinedFeature<>(
FeatureType.CRITICAL, VanillaCriticalFeature::new,
FeatureType.PLAYER_STATE, FeatureType.VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean shouldSweep(LivingEntity attacker, AttackValues.PreSweeping value
if (!values.strong() || values.critical() || values.sprint() || !attacker.isOnGround()) return false;

double lastMoveDistance = attacker.getPreviousPosition().distance(attacker.getPosition()) * 0.6;
if (lastMoveDistance >= attacker.getAttributeValue(Attribute.GENERIC_MOVEMENT_SPEED)) return false;
if (lastMoveDistance >= attacker.getAttributeValue(Attribute.MOVEMENT_SPEED)) return false;

Tool tool = Tool.fromMaterial(attacker.getItemInMainHand().material());
return tool != null && tool.isSword();
Expand Down Expand Up @@ -92,7 +92,7 @@ public void applySweeping(LivingEntity attacker, LivingEntity target, float dama
double z = Math.cos(Math.toRadians(pos.yaw()));

attacker.sendPacketToViewersAndSelf(new ParticlePacket(
Particle.SWEEP_ATTACK, false,
Particle.SWEEP_ATTACK, false,false,
pos.x() + x, pos.y() + attacker.getBoundingBox().height() * 0.5, pos.z() + z,
(float) x, 0, (float) z,
0, 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import io.github.togar2.pvp.feature.config.FeatureConfiguration;
import io.github.togar2.pvp.utils.CombatVersion;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.PlayerHand;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.item.ItemUpdateStateEvent;
import net.minestom.server.event.item.PlayerFinishItemUseEvent;
import net.minestom.server.event.player.PlayerChangeHeldSlotEvent;
import net.minestom.server.event.player.PlayerHandAnimationEvent;
import net.minestom.server.event.player.PlayerSwapItemEvent;
Expand Down Expand Up @@ -47,12 +48,12 @@ public static void initPlayer(Player player, boolean firstInit) {
@Override
public void init(EventNode<EntityInstanceEvent> node) {
node.addListener(PlayerUseItemEvent.class, this::handleUseItem);
node.addListener(ItemUpdateStateEvent.class, this::handleUpdateState);
node.addListener(PlayerFinishItemUseEvent.class, this::handleUpdateState);
node.addListener(PlayerSwapItemEvent.class, this::handleSwapItem);
node.addListener(PlayerChangeHeldSlotEvent.class, this::handleChangeSlot);

node.addListener(PlayerHandAnimationEvent.class, event -> {
if (event.getHand() == Player.Hand.MAIN)
if (event.getHand() == PlayerHand.MAIN)
event.getPlayer().setTag(LAST_SWING_TIME, System.currentTimeMillis());
});
}
Expand Down Expand Up @@ -86,7 +87,7 @@ public void unblock(Player player) {
private void handleUseItem(PlayerUseItemEvent event) {
Player player = event.getPlayer();

if (event.getHand() == Player.Hand.MAIN && !isBlocking(player) && canBlockWith(player, event.getItemStack())) {
if (event.getHand() == PlayerHand.MAIN && !isBlocking(player) && canBlockWith(player, event.getItemStack())) {
long elapsedSwingTime = System.currentTimeMillis() - player.getTag(LAST_SWING_TIME);
if (elapsedSwingTime < 50) {
return;
Expand All @@ -96,8 +97,8 @@ private void handleUseItem(PlayerUseItemEvent event) {
}
}

protected void handleUpdateState(ItemUpdateStateEvent event) {
if (event.getHand() == Player.Hand.OFF && event.getItemStack().isSimilar(blockingItem))
protected void handleUpdateState(PlayerFinishItemUseEvent event) {
if (event.getHand() == PlayerHand.OFF && event.getItemStack().isSimilar(blockingItem))
unblock(event.getPlayer());
}

Expand Down
Loading