From f50b9c7fd466807f907ceeff615411b707009bfe Mon Sep 17 00:00:00 2001 From: Thutmose Date: Thu, 27 Feb 2020 23:21:02 -0500 Subject: [PATCH 1/2] More adjustments to village stuff --- .../events/TrainerSpawnHandler.java | 7 --- src/main/java/pokecube/core/PokecubeCore.java | 5 +- .../database/worldgen/WorldgenHandler.java | 30 +++++++++- .../scattered/jigsaw/JigsawPieces.java | 54 +++++++++++++----- .../world/gen/template/FillerProcessor.java | 49 ++++++++++++++++ .../village/common/houses/house_big_1.nbt | Bin 3022 -> 3021 bytes .../village/common/trainers/trainer_1.nbt | Bin 446 -> 459 bytes .../data/pokecube/structures/worldgen.json | 8 +-- .../data/pokecube_mobs/database/trainers.json | 2 +- 9 files changed, 124 insertions(+), 31 deletions(-) create mode 100644 src/main/java/pokecube/core/world/gen/template/FillerProcessor.java diff --git a/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java b/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java index ac50c80d7f..6c651e0928 100644 --- a/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java +++ b/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java @@ -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; @@ -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; @@ -272,8 +269,6 @@ public static void tickEvent(final WorldTickEvent evt) } } - private static final Set placedMobs = Sets.newHashSet(); - @SubscribeEvent /** * This takes care of randomization for trainer teams when spawned in @@ -284,7 +279,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. @@ -311,7 +305,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); diff --git a/src/main/java/pokecube/core/PokecubeCore.java b/src/main/java/pokecube/core/PokecubeCore.java index 555584341c..bcb71ab032 100644 --- a/src/main/java/pokecube/core/PokecubeCore.java +++ b/src/main/java/pokecube/core/PokecubeCore.java @@ -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; @@ -130,9 +131,11 @@ public static void registerFeatures(final RegistryEvent.Register> 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); diff --git a/src/main/java/pokecube/core/database/worldgen/WorldgenHandler.java b/src/main/java/pokecube/core/database/worldgen/WorldgenHandler.java index ed2465c32c..59bc7fc4c1 100644 --- a/src/main/java/pokecube/core/database/worldgen/WorldgenHandler.java +++ b/src/main/java/pokecube/core/database/worldgen/WorldgenHandler.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.lang.reflect.Field; import java.util.List; import java.util.Locale; @@ -22,9 +23,11 @@ import net.minecraft.world.gen.GenerationStage; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.IFeatureConfig; +import net.minecraft.world.gen.feature.structure.Structure; import net.minecraft.world.gen.placement.IPlacementConfig; import net.minecraft.world.gen.placement.Placement; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.registries.ForgeRegistries; import pokecube.core.PokecubeCore; import pokecube.core.database.Database; @@ -115,10 +118,12 @@ public static class JigSawConfig public static class JigSawPart { public String name; - public String target = "empty"; + public String target = "empty"; public List options; - public boolean rigid = true; - public boolean ignoreAir = true; + public boolean rigid = true; + public boolean ignoreAir = true; + public boolean filler = false; + public boolean base_under = false; } public String name; @@ -221,6 +226,7 @@ public void processStructures(final RegistryEvent.Register> event) final JigsawConfig config = new JigsawConfig(struct); final GenerationStage.Decoration stage = struct.surface ? GenerationStage.Decoration.SURFACE_STRUCTURES : GenerationStage.Decoration.UNDERGROUND_STRUCTURES; + if (struct.biomeType.equals("village")) this.forceVillageFeature(toAdd); for (final Biome b : ForgeRegistries.BIOMES.getValues()) { if (!matcher.checkBiome(b)) continue; @@ -232,4 +238,22 @@ public void processStructures(final RegistryEvent.Register> event) } PokecubeMod.LOGGER.debug("Loaded configurable worldgen"); } + + private Field illagers = null; + + private void forceVillageFeature(final Structure feature) + { + if (this.illagers == null) this.illagers = ObfuscationReflectionHelper.findField(Feature.class, + "field_214488_aQ"); + final List> list = Lists.newArrayList(Feature.ILLAGER_STRUCTURES); + list.add(feature); + try + { + this.illagers.set(null, list); + } + catch (final Exception e) + { + e.printStackTrace(); + } + } } diff --git a/src/main/java/pokecube/core/world/gen/feature/scattered/jigsaw/JigsawPieces.java b/src/main/java/pokecube/core/world/gen/feature/scattered/jigsaw/JigsawPieces.java index b182eb0d78..9ed41c0a1d 100644 --- a/src/main/java/pokecube/core/world/gen/feature/scattered/jigsaw/JigsawPieces.java +++ b/src/main/java/pokecube/core/world/gen/feature/scattered/jigsaw/JigsawPieces.java @@ -8,6 +8,7 @@ import com.google.gson.JsonObject; import com.mojang.datafixers.util.Pair; +import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.StructureMode; @@ -43,21 +44,24 @@ import pokecube.core.database.worldgen.WorldgenHandler.JigSawConfig; import pokecube.core.database.worldgen.WorldgenHandler.JigSawConfig.JigSawPart; import pokecube.core.events.StructureEvent; +import pokecube.core.world.gen.template.FillerProcessor; import pokecube.core.world.gen.template.PokecubeStructureProcessor; +import thut.api.maths.Vector3; public class JigsawPieces { public static final IStructurePieceType CSP = CustomJigsawPiece::new; - public static final RuleEntry PATHTOOAK = new RuleEntry(new BlockMatchRuleTest(Blocks.GRASS_PATH), + public static final RuleEntry PATHTOOAK = new RuleEntry(new BlockMatchRuleTest(Blocks.GRASS_PATH), new BlockMatchRuleTest(Blocks.WATER), Blocks.OAK_PLANKS.getDefaultState()); - public static final RuleEntry PATHTOGRASS = new RuleEntry(new RandomBlockMatchRuleTest( - Blocks.GRASS_PATH, 0.05F), AlwaysTrueRuleTest.INSTANCE, Blocks.GRASS_BLOCK.getDefaultState()); - public static final RuleEntry GRASSTOWATER = new RuleEntry(new BlockMatchRuleTest(Blocks.GRASS_BLOCK), + public static final RuleEntry PATHTOGRASS = new RuleEntry(new RandomBlockMatchRuleTest(Blocks.GRASS_PATH, 0.05F), + AlwaysTrueRuleTest.INSTANCE, Blocks.GRASS_BLOCK.getDefaultState()); + public static final RuleEntry GRASSTOWATER = new RuleEntry(new BlockMatchRuleTest(Blocks.GRASS_BLOCK), new BlockMatchRuleTest(Blocks.WATER), Blocks.WATER.getDefaultState()); - public static final RuleEntry DIRTTOWATER = new RuleEntry(new BlockMatchRuleTest(Blocks.DIRT), + public static final RuleEntry DIRTTOWATER = new RuleEntry(new BlockMatchRuleTest(Blocks.DIRT), new BlockMatchRuleTest(Blocks.WATER), Blocks.WATER.getDefaultState()); - public static final RuleStructureProcessor RULES = new RuleStructureProcessor(ImmutableList.of( + + public static final RuleStructureProcessor RULES = new RuleStructureProcessor(ImmutableList.of( JigsawPieces.PATHTOOAK, JigsawPieces.PATHTOGRASS, JigsawPieces.GRASSTOWATER, JigsawPieces.DIRTTOWATER)); public static void initStructure(final ChunkGenerator chunk_gen, final TemplateManager templateManagerIn, @@ -97,7 +101,7 @@ private static void registerPart(final JigSawConfig jigsaw, final JigSawPart par } option = args[0]; if (option.equals("empty")) parts.add(Pair.of(EmptyJigsawPiece.INSTANCE, second)); - else parts.add(Pair.of(new SingleOffsetPiece(jigsaw, option, ImmutableList.of( + else parts.add(Pair.of(new SingleOffsetPiece(part, option, ImmutableList.of( PokecubeStructureProcessor.PROCESSOR, JigsawPieces.RULES), place, offset, ignoreAir, subbiome), second)); @@ -117,12 +121,12 @@ public static void registerJigsaw(final JigSawConfig jigsaw) public static class SingleOffsetPiece extends SingleJigsawPiece { - protected final JigSawConfig config; - private final int offset; - private final String subbiome; - private final boolean ignoreAir; + protected final JigSawPart part; + private final int offset; + private final String subbiome; + private final boolean ignoreAir; - public SingleOffsetPiece(final JigSawConfig config, final String location, + public SingleOffsetPiece(final JigSawPart part, final String location, final List processors, final PlacementBehaviour type, final int offset, final boolean ignoreAir, final String subbiome) { @@ -130,10 +134,10 @@ public SingleOffsetPiece(final JigSawConfig config, final String location, this.offset = offset; this.ignoreAir = ignoreAir; this.subbiome = subbiome; - this.config = config; + this.part = part; } - public SingleOffsetPiece(final JigSawConfig config, final String location, + public SingleOffsetPiece(final JigSawPart part, final String location, final List processors, final PlacementBehaviour type, final boolean ignoreAir, final String subbiome) { @@ -141,7 +145,7 @@ public SingleOffsetPiece(final JigSawConfig config, final String location, this.offset = 0; this.ignoreAir = ignoreAir; this.subbiome = subbiome; - this.config = config; + this.part = part; } @Override @@ -160,6 +164,7 @@ protected PlacementSettings createPlacementSettings(final Rotation p_214860_1_, placementsettings.setRotation(p_214860_1_); placementsettings.func_215223_c(true); placementsettings.setIgnoreEntities(false); + if (this.part.filler) placementsettings.addProcessor(FillerProcessor.PROCESSOR); if (this.ignoreAir) placementsettings.addProcessor(BlockIgnoreStructureProcessor.AIR_AND_STRUCTURE_BLOCK); else placementsettings.addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK); placementsettings.addProcessor(JigsawReplacementStructureProcessor.INSTANCE); @@ -200,6 +205,25 @@ public boolean place(final TemplateManager manager, final IWorld worldIn, final for (final Template.BlockInfo template$blockinfo : Template.processBlockInfos(template, worldIn, pos, placementsettings, this.func_214857_a(manager, pos, rotation, false))) this.func_214846_a(worldIn, template$blockinfo, pos, rotation, rand, box); + if (this.part.base_under) + { + final MutableBoundingBox box2 = template.getMutableBoundingBox(placementsettings, pos); + final Vector3 v = Vector3.getNewVector(); + for (int x = box2.minX; x <= box2.maxX; x++) + for (int z = box2.minZ; z <= box2.maxZ; z++) + { + v.set(x, box2.minY, z); + final BlockState toFill = v.getBlockState(worldIn); + for (int y = box2.minY - 1; y > box2.minY - 32; y--) + { + v.set(x, y, z); + if (!box.isVecInside(v.getPos())) continue; + final BlockState check = v.getBlockState(worldIn); + if (check.isAir(worldIn, v.getPos())) worldIn.setBlockState(v.getPos(), toFill, 2); + else break; + } + } + } return true; } } diff --git a/src/main/java/pokecube/core/world/gen/template/FillerProcessor.java b/src/main/java/pokecube/core/world/gen/template/FillerProcessor.java new file mode 100644 index 0000000000..db77522705 --- /dev/null +++ b/src/main/java/pokecube/core/world/gen/template/FillerProcessor.java @@ -0,0 +1,49 @@ +package pokecube.core.world.gen.template; + +import javax.annotation.Nullable; + +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorldReader; +import net.minecraft.world.gen.feature.template.IStructureProcessorType; +import net.minecraft.world.gen.feature.template.PlacementSettings; +import net.minecraft.world.gen.feature.template.StructureProcessor; +import net.minecraft.world.gen.feature.template.Template; + +public class FillerProcessor extends StructureProcessor +{ + public static IStructureProcessorType TYPE; + public static final StructureProcessor PROCESSOR = new FillerProcessor(); + + public FillerProcessor() + { + } + + public FillerProcessor(final Dynamic p_deserialize_1_) + { + } + + @Override + @Nullable + public Template.BlockInfo process(final IWorldReader worldReaderIn, final BlockPos pos, + final Template.BlockInfo old, final Template.BlockInfo blockInfo, + final PlacementSettings placementSettingsIn) + { + return worldReaderIn.getBlockState(pos).isAir(worldReaderIn, pos) ? blockInfo : null; + } + + @Override + protected IStructureProcessorType getType() + { + return FillerProcessor.TYPE; + } + + @Override + protected Dynamic serialize0(final DynamicOps ops) + { + return new Dynamic<>(ops, ops.emptyMap()); + } + +} diff --git a/src/main/resources/data/pokecube/structures/village/common/houses/house_big_1.nbt b/src/main/resources/data/pokecube/structures/village/common/houses/house_big_1.nbt index e2a7dcf8377294d4f752eee5cd345c361e6a2324..2f6c6705e27667a83ddaa8a60ebdc8a52c7e8036 100644 GIT binary patch delta 29 lcmX>nepYreolPC8ZN^_I+u=5%;d6szHzGnH^;rOy;=r!3=9C#Qw%-; diff --git a/src/main/resources/data/pokecube/structures/village/common/trainers/trainer_1.nbt b/src/main/resources/data/pokecube/structures/village/common/trainers/trainer_1.nbt index e501014f8fbff460dbee95376b468849e7f39d90..f28514c3a234809da2c6dbbcdf3293796a1e8ccf 100644 GIT binary patch literal 459 zcmV;+0W|&}iwFP!000000CiHaZrd;rJy}XDJ7|+JT{U;;tf57KWOX|PMbbr}q_f1v z{t{Vi%XZ7=Xw5&LA-2(&>D~fijPdYE^hvjBvR>_U!tKdxym%={kjp zuHj;T{8Kkxty8#A%&Kb9h?0Ug9liyX#7stX#U1%k{%gf>GTa(!RGS)PRV!BTxuXZH z`VtFOKMK1@@i{vs?CvRRdgbaYf67=J%<|0YrseEo=17?=|MdKv!l}{Dk%MIMb#W8H zd)-)ac(ZdXieTE&8XeYo#A>nwUkr)NbT_~gLp4Hj zeRX>^?B9oY!h90j-7ss|{t=cZFw>T?ahf+@UP7Ex-_lxX7nrOv7$}3?AC9H5O?XFr zKiVkkEq4Uxfvcq6*4j2D{fdsbA04=V3^O^vOawFS)C!q#_q^uc9Che|nc~<|RdORF zHLYzJWDy4W=fS{1+s?Ud;A7MO$9{#p+e3nHF`Qis!*_H(1O(GR@E5$0Q=m5k006ZS B;>`d6 literal 446 zcmV;v0YUyBiwFP!000000CkeVZrd;nhUvy_oD^Go-PPwEcJ^UIf%cm1Pz>!ZhHNvo z)<`rYdRbN!*kkqaM#j!EbejM{f<*rM`B6)N1*Fmbz!?DOOk|$ux_}HlTecWM#{$l( z4b=~EsS!(<`HC|*XA@fFvM1WWg|i;(VAfoq>v<>FYwOLXjBFU;)$!Wckim&<;PQC( z)wa=WGq^O&rtZ+m^CjAxq{yk=JIzFZ2U@>#ZrZH^beNPWq4;7ZC z`6lW^z*ulFq8=Xeb}*sIi^rU;!@S77Z9C52=7EgMi+4{?8JsyA0tHA{A6GXCytb{U zfHxDSB!PKPTMXDhDpXO{X-KLWxRccEwj0<{L@^df%v$oJ-V9Qy>23^99W@B)_0{dw zcz&-v(fXuUcVn%3{6)8?u&|!74VHHwergZrv7@a(RwZv7s-)t6b0ir#47DOC_ide| z?++Mdzt>LSLbWOyd}DoE(f8yZ^ph9#HD=zM4Km~OUzVQ&^%xYC&{&&V)F5qW>(%5+ oP5$*6;6>U*W#7z0(*H{mL+95L`WZu1$}oS1UmZ-O;PC Date: Fri, 28 Feb 2020 00:02:44 -0500 Subject: [PATCH 2/2] More adjustments to trainers --- .../adventures/ai/tasks/AIBattle.java | 6 ++-- .../adventures/ai/tasks/AIFindTarget.java | 1 + .../capabilities/CapabilityHasPokemobs.java | 12 ++++++++ .../capabilities/utils/TypeTrainer.java | 28 +++++++++-------- .../adventures/entity/trainer/LeaderNpc.java | 30 +++++++++++++++++++ .../entity/trainer/TrainerBase.java | 15 +++++++++- .../adventures/entity/trainer/TrainerNpc.java | 10 +++++-- .../events/TrainerEventHandler.java | 3 +- .../events/TrainerSpawnHandler.java | 3 +- 9 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/main/java/pokecube/adventures/ai/tasks/AIBattle.java b/src/main/java/pokecube/adventures/ai/tasks/AIBattle.java index 170a696f5c..3002a9d8e3 100644 --- a/src/main/java/pokecube/adventures/ai/tasks/AIBattle.java +++ b/src/main/java/pokecube/adventures/ai/tasks/AIBattle.java @@ -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; @@ -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(); @@ -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)); diff --git a/src/main/java/pokecube/adventures/ai/tasks/AIFindTarget.java b/src/main/java/pokecube/adventures/ai/tasks/AIFindTarget.java index 4a81cd0d80..b3797a4dee 100644 --- a/src/main/java/pokecube/adventures/ai/tasks/AIFindTarget.java +++ b/src/main/java/pokecube/adventures/ai/tasks/AIFindTarget.java @@ -132,6 +132,7 @@ public void updateTask() look.scalarMultBy(sight); look.addTo(here); final List targets = MovesUtils.targetsHit(this.entity, look); + if (!targets.isEmpty()) for (final Object o : targets) { final LivingEntity e = (LivingEntity) o; diff --git a/src/main/java/pokecube/adventures/capabilities/CapabilityHasPokemobs.java b/src/main/java/pokecube/adventures/capabilities/CapabilityHasPokemobs.java index 355e673e02..fa8fb51d9c 100644 --- a/src/main/java/pokecube/adventures/capabilities/CapabilityHasPokemobs.java +++ b/src/main/java/pokecube/adventures/capabilities/CapabilityHasPokemobs.java @@ -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; @@ -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 @@ -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 diff --git a/src/main/java/pokecube/adventures/capabilities/utils/TypeTrainer.java b/src/main/java/pokecube/adventures/capabilities/utils/TypeTrainer.java index 516d1ee0f3..72d46b68a3 100644 --- a/src/main/java/pokecube/adventures/capabilities/utils/TypeTrainer.java +++ b/src/main/java/pokecube/adventures/capabilities/utils/TypeTrainer.java @@ -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; @@ -140,15 +139,15 @@ else if (mob instanceof VillagerEntity && Config.instance.npcsAreTrainers) { final List 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. @@ -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 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 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); @@ -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 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); diff --git a/src/main/java/pokecube/adventures/entity/trainer/LeaderNpc.java b/src/main/java/pokecube/adventures/entity/trainer/LeaderNpc.java index c373edd1db..f9088fe5f7 100644 --- a/src/main/java/pokecube/adventures/entity/trainer/LeaderNpc.java +++ b/src/main/java/pokecube/adventures/entity/trainer/LeaderNpc.java @@ -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 { @@ -23,6 +36,23 @@ public LeaderNpc(final EntityType 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 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) { diff --git a/src/main/java/pokecube/adventures/entity/trainer/TrainerBase.java b/src/main/java/pokecube/adventures/entity/trainer/TrainerBase.java index 8eb3a3d3b7..61b2c9983a 100644 --- a/src/main/java/pokecube/adventures/entity/trainer/TrainerBase.java +++ b/src/main/java/pokecube/adventures/entity/trainer/TrainerBase.java @@ -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)) { @@ -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) @@ -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); diff --git a/src/main/java/pokecube/adventures/entity/trainer/TrainerNpc.java b/src/main/java/pokecube/adventures/entity/trainer/TrainerNpc.java index 0f32e893c0..19ca2fb4a8 100644 --- a/src/main/java/pokecube/adventures/entity/trainer/TrainerNpc.java +++ b/src/main/java/pokecube/adventures/entity/trainer/TrainerNpc.java @@ -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; } @@ -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()) { diff --git a/src/main/java/pokecube/adventures/events/TrainerEventHandler.java b/src/main/java/pokecube/adventures/events/TrainerEventHandler.java index 2ba4dee89b..de3b57d05a 100644 --- a/src/main/java/pokecube/adventures/events/TrainerEventHandler.java +++ b/src/main/java/pokecube/adventures/events/TrainerEventHandler.java @@ -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); } diff --git a/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java b/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java index 6c651e0928..c9577e82b7 100644 --- a/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java +++ b/src/main/java/pokecube/adventures/events/TrainerSpawnHandler.java @@ -248,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); } @@ -338,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); } }