Skip to content

Commit

Permalink
Merge pull request #28 from Pokecube-Development/1.14
Browse files Browse the repository at this point in the history
Update Files
  • Loading branch information
NelkGames authored Feb 28, 2020
2 parents 020bd3b + f8930e7 commit 6556f18
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 53 deletions.
6 changes: 2 additions & 4 deletions src/main/java/pokecube/adventures/ai/tasks/AIBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import pokecube.adventures.Config;
import pokecube.adventures.capabilities.CapabilityNPCAIStates.IHasNPCAIStates;
Expand Down Expand Up @@ -232,9 +231,6 @@ private void setMostDamagingMove()
public void tick()
{
super.tick();
ItemStack cube = this.trainer.getNextPokemob();
if (this.trainer.getCooldown() > 0) cube = ItemStack.EMPTY;
this.entity.setHeldItem(Hand.MAIN_HAND, cube);
if (this.trainer.getTarget() != null) this.updateTask();
else if (this.trainer.getOutID() != null) this.resetTask();
this.trainer.lowerCooldowns();
Expand All @@ -258,6 +254,8 @@ public void updateTask()
if (this.battleLoc == null) this.battleLoc = this.entity.getPosition();
((MobEntity) this.entity).getNavigator().setPath(((MobEntity) this.entity).getNavigator().getPathToPos(
this.battleLoc, 0), 0.75);
if (this.entity.getPosition().distanceSq(this.battleLoc) < 4) ((MobEntity) this.entity).getNavigator()
.clearPath();
}

this.entity.lookAt(Type.EYES, this.trainer.getTarget().getEyePosition(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void updateTask()
look.scalarMultBy(sight);
look.addTo(here);
final List<LivingEntity> targets = MovesUtils.targetsHit(this.entity, look);

if (!targets.isEmpty()) for (final Object o : targets)
{
final LivingEntity e = (LivingEntity) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,13 @@ public void setTarget(LivingEntity target)
}
if (!valid) target = null;
}
// No next pokemob, so we shouldn't have a target in this case.
if (this.getPokemob(0).isEmpty())
{
target = null;
// Notify the watchers that a target was actually set.
for (final ITargetWatcher watcher : watchers)
watcher.onSet(null);
this.aiStates.setAIState(IHasNPCAIStates.THROWING, false);
this.aiStates.setAIState(IHasNPCAIStates.INBATTLE, false);
return;
Expand All @@ -566,6 +570,9 @@ public void setTarget(LivingEntity target)
this.aiStates.setAIState(IHasNPCAIStates.INBATTLE, false);
}
this.target = target;
// Notify the watchers that a target was actually set.
for (final ITargetWatcher watcher : watchers)
watcher.onSet(target);
}

@Override
Expand Down Expand Up @@ -836,6 +843,11 @@ default void onRemoved(final IHasPokemobs pokemobs)
}

boolean validTargetSet(LivingEntity target);

default void onSet(final LivingEntity target)
{

}
}

public static class Storage implements Capability.IStorage<IHasPokemobs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import pokecube.adventures.capabilities.CapabilityHasPokemobs;
import pokecube.adventures.capabilities.CapabilityHasPokemobs.IHasPokemobs;
import pokecube.adventures.entity.trainer.TrainerBase;
import pokecube.adventures.entity.trainer.TrainerNpc;
import pokecube.core.PokecubeCore;
import pokecube.core.PokecubeItems;
import pokecube.core.database.Database;
Expand Down Expand Up @@ -140,15 +139,15 @@ else if (mob instanceof VillagerEntity && Config.instance.npcsAreTrainers)
{
final List<IAIRunnable> ais = Lists.newArrayList();
// All can battle, but only trainers will path during battle.
ais.add(new AIBattle(npc, !(npc instanceof TrainerNpc)).setPriority(0));
ais.add(new AIBattle(npc, !(npc instanceof TrainerBase)).setPriority(0));

// All attack zombies.
ais.add(new AIFindTarget(npc, ZombieEntity.class).setPriority(20));
// Only trainers specifically target players.
if (npc instanceof TrainerNpc)
if (npc instanceof TrainerBase)
{
ais.add(new AIFindTarget(npc, PlayerEntity.class).setPriority(10));
ais.add(new AIMate(npc, ((TrainerNpc) npc).getClass()));
ais.add(new AIMate(npc, ((TrainerBase) npc).getClass()));
}

// 5% chance of battling a random nearby pokemob if they see it.
Expand Down Expand Up @@ -226,22 +225,15 @@ public static void addTrainer(final String name, final TypeTrainer type)
TypeTrainer.typeMap.put(name, type);
}

public static void getRandomTeam(final IHasPokemobs trainer, final LivingEntity owner, int level, final World world)
public static void getRandomTeam(final IHasPokemobs trainer, final LivingEntity owner, int level, final World world,
final List<PokedexEntry> values)
{
final TypeTrainer type = trainer.getType();

for (int i = 0; i < 6; i++)
trainer.setPokemob(i, ItemStack.EMPTY);

if (level == 0) level = 5;
final Variance variance = SpawnHandler.DEFAULT_VARIANCE;
int number = 1 + new Random().nextInt(6);
number = Math.min(number, trainer.getMaxPokemobCount());

final List<PokedexEntry> values = Lists.newArrayList();
if (type.pokemon != null) values.addAll(type.pokemon);
else PokecubeCore.LOGGER.warn("No mobs for " + type);

for (int i = 0; i < number; i++)
{
Collections.shuffle(values);
Expand All @@ -255,6 +247,16 @@ public static void getRandomTeam(final IHasPokemobs trainer, final LivingEntity
}
}

public static void getRandomTeam(final IHasPokemobs trainer, final LivingEntity owner, final int level,
final World world)
{
final TypeTrainer type = trainer.getType();
final List<PokedexEntry> values = Lists.newArrayList();
if (type.pokemon != null) values.addAll(type.pokemon);
else PokecubeCore.LOGGER.warn("No mobs for " + type);
TypeTrainer.getRandomTeam(trainer, owner, level, world, values);
}

public static TypeTrainer getTrainer(final String name)
{
final TypeTrainer ret = TypeTrainer.typeMap.get(name);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/pokecube/adventures/entity/trainer/LeaderNpc.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package pokecube.adventures.entity.trainer;

import java.util.List;
import java.util.Random;

import com.google.common.collect.Lists;

import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import pokecube.adventures.PokecubeAdv;
import pokecube.adventures.capabilities.CapabilityHasRewards.Reward;
import pokecube.adventures.capabilities.CapabilityNPCAIStates.IHasNPCAIStates;
import pokecube.adventures.capabilities.utils.TypeTrainer;
import pokecube.core.database.Database;
import pokecube.core.database.PokedexEntry;
import pokecube.core.utils.PokeType;

public class LeaderNpc extends TrainerNpc
{
Expand All @@ -23,6 +36,23 @@ public LeaderNpc(final EntityType<? extends TrainerBase> type, final World world
this.pokemobsCap.resetTime = 0;
}

@Override
public void initTeam(final int level)
{
PokeType type;
if (this.rewardsCap != null && this.rewardsCap.getRewards().isEmpty() || (type = PokecubeAdv.BADGEINV.get(
this.rewardsCap.getRewards().get(0).stack.getItem())) == null)
{
type = PokeType.values()[new Random().nextInt(PokeType.values().length)];
final Item badge = PokecubeAdv.BADGES.get(type);
this.rewardsCap.getRewards().add(0, new Reward(new ItemStack(badge)));
}
final List<PokedexEntry> options = Lists.newArrayList();
for (final PokedexEntry e : Database.spawnables)
if (e.isType(type)) options.add(e);
TypeTrainer.getRandomTeam(this.pokemobsCap, this, level, this.world, options);
}

@Override
public void setRandomName(final String name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ public void livingTick()
if (this.pokemobsCap.getOutMob() == null) this.pokemobsCap.setOutID(null);
}

ItemStack cube = this.pokemobsCap.getNextPokemob();
ItemStack reward = this.rewardsCap.getRewards().isEmpty() ? ItemStack.EMPTY
: this.rewardsCap.getRewards().get(0).stack;
if (this.pokemobsCap.getCooldown() > 0)
{
cube = ItemStack.EMPTY;
reward = ItemStack.EMPTY;
}
this.setHeldItem(Hand.MAIN_HAND, cube);
this.setHeldItem(Hand.OFF_HAND, reward);

if (this.pokemobsCap.countPokemon() == 0 && !this.aiStates.getAIState(IHasNPCAIStates.STATIONARY)
&& !this.aiStates.getAIState(IHasNPCAIStates.PERMFRIENDLY))
{
Expand All @@ -145,7 +156,7 @@ public void livingTick()

final int level = SpawnHandler.getSpawnLevel(this.getEntityWorld(), Vector3.getNewVector().set(this),
type.pokemon.get(0));
TypeTrainer.getRandomTeam(this.pokemobsCap, this, level, this.getEntityWorld());
this.initTeam(level);
type.initTrainerItems(this);
}
if (PokecubeAdv.config.cullNoMobs)
Expand Down Expand Up @@ -189,6 +200,8 @@ public void setCustomer(final PlayerEntity player)
super.setCustomer(player);
}

public abstract void initTeam(int level);

protected abstract void addMobTrades(final PlayerEntity player, final ItemStack stack);

public abstract void setRandomName(String name);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/pokecube/adventures/entity/trainer/TrainerNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void readAdditional(final CompoundNBT nbt)

public TrainerNpc setLevel(final int level)
{
TypeTrainer.getRandomTeam(this.pokemobsCap, this, level, this.getEntityWorld());
this.initTeam(level);
return this;
}

Expand All @@ -190,12 +190,18 @@ public TrainerNpc setType(final TypeTrainer type)
return this;
}

@Override
public void initTeam(final int level)
{
TypeTrainer.getRandomTeam(this.pokemobsCap, this, level, this.world);
}

public void setTypes()
{
if (this.pokemobsCap.getType() == null)
{
this.setType(TypeTrainer.get(this, false));
TypeTrainer.getRandomTeam(this.pokemobsCap, this, 5, this.world);
this.initTeam(5);
}
if (this.name.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ private static void initTrainer(final LivingEntity npc, final SpawnReason reason
mobs.setType(newType);
final int level = SpawnHandler.getSpawnLevel(npc.getEntityWorld(), Vector3.getNewVector().set(npc), Database
.getEntry(1));
TypeTrainer.getRandomTeam(mobs, npc, level, npc.getEntityWorld());
if (npc instanceof TrainerBase) ((TrainerBase) npc).initTeam(level);
else TypeTrainer.getRandomTeam(mobs, npc, level, npc.getEntityWorld());
EntityUpdate.sendEntityUpdate(npc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.UUID;

import org.nfunk.jep.JEP;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.JsonObject;

import net.minecraft.block.Blocks;
Expand All @@ -29,7 +27,6 @@
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.Heightmap.Type;
import net.minecraft.world.server.ServerWorld;
Expand Down Expand Up @@ -251,6 +248,7 @@ public static void tick(final ServerWorld w)
(int) t.posZ))
{
w.addEntity(t);
TrainerSpawnHandler.randomizeTrainerTeam(t, cap);
PokecubeCore.LOGGER.debug("Spawned Trainer: " + t + " " + count);
TrainerSpawnHandler.addTrainerCoord(t);
}
Expand All @@ -272,8 +270,6 @@ public static void tickEvent(final WorldTickEvent evt)
}
}

private static final Set<BlockPos> placedMobs = Sets.newHashSet();

@SubscribeEvent
/**
* This takes care of randomization for trainer teams when spawned in
Expand All @@ -284,7 +280,6 @@ public static void tickEvent(final WorldTickEvent evt)
public static void StructureSpawn(final StructureEvent.ReadTag event)
{
if (!event.function.startsWith("pokecube_adventures:")) return;
if (TrainerSpawnHandler.placedMobs.contains(event.pos.toImmutable())) return;
String function = event.function.replaceFirst("pokecube_adventures:", "");
boolean leader = false;
// Here we process custom options for trainers or leaders in structures.
Expand All @@ -311,7 +306,6 @@ public static void StructureSpawn(final StructureEvent.ReadTag event)
}
// We apply it regardless, as this initializes defaults.
TrainerSpawnHandler.applyFunction(mob, thing, leader);
TrainerSpawnHandler.placedMobs.add(event.pos.toImmutable());
PokecubeCore.LOGGER.debug("Adding trainer: " + mob);
if (!MinecraftForge.EVENT_BUS.post(new NpcSpawn(mob, event.pos, event.world, SpawnReason.STRUCTURE)))
event.world.addEntity(mob);
Expand Down Expand Up @@ -345,6 +339,6 @@ private static void applyFunction(final TrainerNpc npc, final JsonObject thing,
break;
}
}
TypeTrainer.getRandomTeam(npc.pokemobsCap, npc, level, npc.getEntityWorld());
npc.initTeam(level);
}
}
5 changes: 4 additions & 1 deletion src/main/java/pokecube/core/PokecubeCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import pokecube.core.world.dimension.SecretBaseDimension.SecretBiome;
import pokecube.core.world.gen.feature.scattered.jigsaw.JigsawPieces;
import pokecube.core.world.gen.feature.scattered.testa.ConfigStructurePiece;
import pokecube.core.world.gen.template.FillerProcessor;
import pokecube.core.world.gen.template.PokecubeStructureProcessor;
import pokecube.mobloader.MobLoader;
import thut.api.maths.Vector3;
Expand Down Expand Up @@ -130,9 +131,11 @@ public static void registerFeatures(final RegistryEvent.Register<Feature<?>> eve
Registry.register(Registry.STRUCTURE_PIECE, "pokecube:struct_piece", ConfigStructurePiece.CONFIGTYPE);
Registry.register(Registry.STRUCTURE_PIECE, "pokecube:jigsaw_piece", JigsawPieces.CSP);

// Register structure processor type
// Register structure processor types
PokecubeStructureProcessor.TYPE = IStructureProcessorType.register("pokecube:struct_process",
PokecubeStructureProcessor::new);
FillerProcessor.TYPE = IStructureProcessorType.register("pokecube:struct_process_filler",
FillerProcessor::new);

// Register the configurable worldgen things from datapack
new WorldgenHandler().processStructures(event);
Expand Down
Loading

0 comments on commit 6556f18

Please sign in to comment.