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 all 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-bb14804d42'
testImplementation 'net.minestom:minestom-snapshots:1_21_4-bb14804d42'
//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
34 changes: 17 additions & 17 deletions src/main/java/io/github/togar2/pvp/damage/DamageTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public record DamageTypeInfo(boolean damagesHelmet, boolean bypassesArmor, boole
boolean magic, boolean explosive, boolean fall, boolean thorns, boolean projectile,
boolean freeze) {
private static final DamageTypeInfo DEFAULT = new DamageTypeInfo();

public DamageTypeInfo() {
this(
false, false, false,
false, false, ScaleWithDifficulty.NEVER,
false, false, false, false, false, false
);
}

public static DamageTypeInfo of(DynamicRegistry.Key<DamageType> type) {
return INFO_MAP.getOrDefault(type, DEFAULT);
}

//TODO check source and add missing
public static final Map<DynamicRegistry.Key<DamageType>, DamageTypeInfo> INFO_MAP = new HashMap<>() {
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public static DamageTypeInfo of(DynamicRegistry.Key<DamageType> type) {
put(DamageType.OUTSIDE_BORDER, new DamageTypeInfo().bypassesArmor(true));
}
};

public DamageTypeInfo damagesHelmet(boolean damagesHelmet) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -80,7 +80,7 @@ public DamageTypeInfo damagesHelmet(boolean damagesHelmet) {
freeze
);
}

public DamageTypeInfo bypassesArmor(boolean bypassesArmor) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -89,7 +89,7 @@ public DamageTypeInfo bypassesArmor(boolean bypassesArmor) {
freeze
);
}

public DamageTypeInfo outOfWorld(boolean outOfWorld) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -98,7 +98,7 @@ public DamageTypeInfo outOfWorld(boolean outOfWorld) {
freeze
);
}

public DamageTypeInfo unblockable(boolean unblockable) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -107,7 +107,7 @@ public DamageTypeInfo unblockable(boolean unblockable) {
freeze
);
}

public DamageTypeInfo fire(boolean fire) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -116,7 +116,7 @@ public DamageTypeInfo fire(boolean fire) {
freeze
);
}

public DamageTypeInfo scale(ScaleWithDifficulty scale) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -125,7 +125,7 @@ public DamageTypeInfo scale(ScaleWithDifficulty scale) {
freeze
);
}

public DamageTypeInfo magic(boolean magic) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -134,7 +134,7 @@ public DamageTypeInfo magic(boolean magic) {
freeze
);
}

public DamageTypeInfo explosive(boolean explosive) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -143,7 +143,7 @@ public DamageTypeInfo explosive(boolean explosive) {
freeze
);
}

public DamageTypeInfo fall(boolean fall) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -152,7 +152,7 @@ public DamageTypeInfo fall(boolean fall) {
freeze
);
}

public DamageTypeInfo thorns(boolean thorns) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -161,7 +161,7 @@ public DamageTypeInfo thorns(boolean thorns) {
freeze
);
}

public DamageTypeInfo projectile(boolean projectile) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -170,7 +170,7 @@ public DamageTypeInfo projectile(boolean projectile) {
freeze
);
}

public DamageTypeInfo freeze(boolean freeze) {
return new DamageTypeInfo(
damagesHelmet, bypassesArmor, outOfWorld,
Expand All @@ -179,13 +179,13 @@ public DamageTypeInfo freeze(boolean freeze) {
freeze
);
}

public enum ScaleWithDifficulty {
ALWAYS,
WHEN_CAUSED_BY_LIVING_NON_PLAYER,
NEVER
}

public boolean shouldScaleWithDifficulty(Damage damage) {
return switch (scaleWithDifficulty) {
case ALWAYS -> 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, false,
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
Loading