Skip to content

Commit

Permalink
fixes some issues with advancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed Aug 21, 2022
1 parent 9f2ea88 commit cee6f0f
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.adventures.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -64,8 +66,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final TrainerBase defeated)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, defeated)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, defeated)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.adventures.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -64,8 +66,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final TrainerBase defeated)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, defeated)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, defeated)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -86,8 +88,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob first, final IPokemob second)
{
for (final var listener : this.listeners)
if (listener.getTriggerInstance().test(player, first, second)) listener.run(this.playerAdvancements);
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, first, second)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -91,9 +93,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob pokemob)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, pokemob)) listener.run(this.playerAdvancements);

if (listener.getTriggerInstance().test(player, pokemob)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -67,8 +69,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob pokemob)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, pokemob)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, pokemob)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -60,8 +62,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test()) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test()) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -67,8 +69,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob pokemob)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, pokemob)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, pokemob)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -67,9 +69,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob pokemob)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, pokemob)) listener.run(this.playerAdvancements);

if (listener.getTriggerInstance().test(player, pokemob)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -66,8 +68,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob pokemob)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, pokemob)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, pokemob)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -67,8 +69,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final IPokemob pokemob)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, pokemob)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, pokemob)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokecube.core.handlers.playerdata.advancements.triggers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -70,8 +72,10 @@ public void remove(final CriterionTrigger.Listener<Instance> listener)

public void trigger(final ServerPlayer player, final MovePacket packet)
{
List<Listener<Instance>> toTrigger = new ArrayList<>();
for (var listener : this.listeners)
if (listener.getTriggerInstance().test(player, packet)) listener.run(this.playerAdvancements);
if (listener.getTriggerInstance().test(player, packet)) toTrigger.add(listener);
toTrigger.forEach(l -> l.run(playerAdvancements));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import pokecube.api.data.PokedexEntry;
import pokecube.api.entity.pokemob.Nature;
import pokecube.api.entity.pokemob.ai.CombatStates;
import pokecube.api.entity.pokemob.ai.GeneralStates;
Expand Down Expand Up @@ -104,12 +105,20 @@ public int getHungerTime()
return this.dataSync().get(this.params.HUNGERDW);
}

private float _last_size = 0;

@Override
public Vector3 getMobSizes()
{
return this.sizes
.set(this.getPokedexEntry().width, this.getPokedexEntry().height, this.getPokedexEntry().length)
.scalarMult(this.getSize());
float size = this.getSize();
if (size != _last_size)
{
_last_size = size;
PokedexEntry entry = this.getPokedexEntry();
this.sizes.set(entry.width, entry.height, entry.length);
this.sizes.scalarMultBy(size);
}
return this.sizes;
}

/** @return does this pokemon hunt for food */
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pokecube/core/moves/Battle.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ private void addToSide(final Map<UUID, LivingEntity> side, final Set<String> tea
if (this.valid)
{
final IPokemob poke = PokemobCaps.getPokemobFor(mob);
if (!(mob instanceof Mob)) return;
BrainUtils.initiateCombat((Mob) mob, target);
if (!(mob instanceof Mob mob2)) return;
BrainUtils.initiateCombat(mob2, target);
if (poke != null && poke.getAbility() != null) poke.getAbility().startCombat(poke);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/pokecube/core/moves/templates/Move_Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public static void silkHarvest(final BlockState state, final BlockPos pos, final
worldIn.destroyBlock(pos, false);
}

Vector3 v = new Vector3();

Vector3 v1 = new Vector3();

/**
* Constructor for a Pokemob move. <br/>
* The attack category defines the way the mob will move in order to make
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/pokecube/core/moves/templates/Move_Explode.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,20 @@ public void attack(final IPokemob attacker, final Entity attacked)
if (!evt.isCanceled())
{
final boolean explodeDamage = mob.getLevel() instanceof ServerLevel level && Config.Rules.doBoom(level);
final boolean damagePerms = MoveEventsHandler.canAffectBlock(pokemob, this.v.set(mob), this.getName());
final boolean damagePerms = MoveEventsHandler.canAffectBlock(pokemob, new Vector3().set(mob),
this.getName());
// If these, we let the explosion handle the damage.
if (explodeDamage && damagePerms) boom.doExplosion();
else
{
// Otherwise spawn in some effects
mob.getLevel().playSound((Player) null, mob.getX(), mob.getY(), mob.getZ(),
SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F,
(1.0F + (mob.getLevel().random.nextFloat()
- mob.getLevel().random.nextFloat()) * 0.2F) * 0.7F);
if (this.getPWR() > 200) mob.getLevel().addParticle(ParticleTypes.EXPLOSION, mob.getX(),
mob.getY(), mob.getZ(), 1.0D, 0.0D, 0.0D);
else mob.getLevel().addParticle(ParticleTypes.EXPLOSION, mob.getX(), mob.getY(),
mob.getLevel().playSound((Player) null, mob.getX(), mob.getY(), mob.getZ(), SoundEvents.GENERIC_EXPLODE,
SoundSource.BLOCKS, 4.0F,
(1.0F + (mob.getLevel().random.nextFloat() - mob.getLevel().random.nextFloat()) * 0.2F) * 0.7F);
if (this.getPWR() > 200) mob.getLevel().addParticle(ParticleTypes.EXPLOSION, mob.getX(), mob.getY(),
mob.getZ(), 1.0D, 0.0D, 0.0D);
else mob.getLevel().addParticle(ParticleTypes.EXPLOSION, mob.getX(), mob.getY(), mob.getZ(), 1.0D, 0.0D,
0.0D);
// and hit nearby targets normally.
this.actualAttack(pokemob, new Vector3().set(pokemob.getEntity()).add(0,
pokemob.getSize() * pokemob.getPokedexEntry().height / 2, 0));
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/thut/api/entity/animation/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.google.common.collect.Ordering;

import thut.api.maths.Vector3;
import thut.core.client.render.animation.AnimationXML.Phase;

public class Animation
Expand All @@ -28,20 +29,22 @@ public static interface IPartRenamer

public UUID _uuid = UUID.randomUUID();

public String name = "";
public String name = "";
public String identifier = "";
public int length = -1;
public int length = -1;
/**
* This is used for sorting animations for determining which components
* should take priority when multiple animations are specified for a single
* part.
*/
public int priority = 10;
public int priority = 10;

public boolean loops = true;

public boolean hasLimbBased = false;

public Vector3 _shift = new Vector3();

public TreeMap<String, ArrayList<AnimationComponent>> sets = new TreeMap<>(Ordering.natural());

public ArrayList<AnimationComponent> getComponents(final String key)
Expand Down Expand Up @@ -76,10 +79,10 @@ public void initLength()
this.hasLimbBased = false;
for (final Entry<String, ArrayList<AnimationComponent>> entry : this.sets.entrySet())
for (final AnimationComponent component : entry.getValue())
{
this.length = Math.max(this.length, component.startKey + component.length);
this.hasLimbBased = this.hasLimbBased || component.limbBased;
}
{
this.length = Math.max(this.length, component.startKey + component.length);
this.hasLimbBased = this.hasLimbBased || component.limbBased;
}
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/thut/api/maths/Vector4.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public Vector4(final Quaternion quat)
this.quat = quat;
}

@OnlyIn(value = Dist.CLIENT)
public Vector4 set(final Quaternion quat)
{
this.set(quat.i(), quat.j(), quat.k(), quat.r());
this.quat = quat;
return this;
}

public Vector4(final CompoundTag nbt)
{
this();
Expand Down
Loading

0 comments on commit cee6f0f

Please sign in to comment.