Skip to content

Commit

Permalink
adjustments to trainer target forgetting
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed May 24, 2020
1 parent d08fdf5 commit 74abdcb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pokecube/adventures/ai/tasks/Tasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Tasks
{
public static final SensorType<DummySensor> DUMMY = new SensorType<>(DummySensor::new);

static
public static void init()
{
Tasks.DUMMY.setRegistryName(PokecubeAdv.MODID, "dummy_sensor");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.brain.Brain;
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
import net.minecraft.entity.ai.brain.schedule.Activity;
Expand Down Expand Up @@ -646,6 +645,10 @@ public void onSetTarget(final LivingEntity target, final boolean ignoreCanBattle
final Set<ITargetWatcher> watchers = this.getTargetWatchers();
// No next pokemob, so we shouldn't have a target in this case.

// Set this here, before trying to validate other's target below.
this.getTrainer().getBrain().removeMemory(MemoryTypes.BATTLETARGET);
if (target != null) this.getTrainer().getBrain().setMemory(MemoryTypes.BATTLETARGET, target);

final IHasPokemobs oldOther = TrainerCaps.getHasPokemobs(old);
if (oldOther != null) oldOther.onSetTarget(null);

Expand Down Expand Up @@ -698,14 +701,9 @@ public void onSetTarget(final LivingEntity target, final boolean ignoreCanBattle
{
BrainUtils.deagro(this.getTrainer());
this.resetPokemob();
this.getTrainer().getBrain().removeMemory(MemoryTypes.BATTLETARGET);
this.getTrainer().getBrain().switchTo(Activity.IDLE);
}
else if (this.getTrainer() instanceof MobEntity)
{
this.getTrainer().getBrain().setMemory(MemoryTypes.BATTLETARGET, target);
this.getTrainer().getBrain().switchTo(Activities.BATTLE);
}
else this.getTrainer().getBrain().switchTo(Activities.BATTLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import pokecube.adventures.capabilities.CapabilityHasPokemobs.DefaultPokemobs;
import pokecube.adventures.capabilities.CapabilityHasPokemobs.IHasPokemobs;
Expand Down Expand Up @@ -47,6 +48,8 @@ public static void register(final AttachCapabilitiesEvent<Entity> event)
PlayerEntity player;
LivingEntity target = null;

long setTargetTime = 0;

public PlayerPokemobs(final PlayerEntity player)
{
this.player = player;
Expand Down Expand Up @@ -122,6 +125,8 @@ public void deserializeNBT(final CompoundNBT nbt)
@Override
public void onSetTarget(final LivingEntity target)
{
if (target != null && target.getServer() != null) this.setTargetTime = target.getServer().getWorld(
DimensionType.OVERWORLD).getGameTime();
if (target == this.target) return;
final Set<ITargetWatcher> watchers = this.getTargetWatchers();
this.target = target;
Expand All @@ -139,6 +144,8 @@ public void onSetTarget(final LivingEntity target, final boolean ignoreCanBattle
@Override
public LivingEntity getTarget()
{
if (this.target != null && this.target.getServer() != null) if (this.target.getServer().getWorld(
DimensionType.OVERWORLD).getGameTime() - this.setTargetTime > 50) this.target = null;
return this.target;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/pokecube/adventures/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import pokecube.adventures.PokecubeAdv;
import pokecube.adventures.ai.tasks.Tasks;
import pokecube.adventures.blocks.afa.AfaTile;
import pokecube.adventures.blocks.warppad.WarppadTile;
import pokecube.adventures.capabilities.CapabilityHasPokemobs;
Expand Down Expand Up @@ -97,6 +98,7 @@ public void setup(final FMLCommonSetupEvent event)
OwnableCaps.TILES.add(WarppadTile.class);

PacketTrainer.register();
Tasks.init();
}

@Override
Expand Down

0 comments on commit 74abdcb

Please sign in to comment.