From dd137c68f64e4acadb73365ac67cf3fcb54827e5 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Thu, 21 May 2020 20:55:10 +0100 Subject: [PATCH] Make remnants spawn from obelisk spawners (bye bye mobelisks o/) --- .../wizardry/entity/living/EntityRemnant.java | 14 ++++++- .../wizardry/worldgen/WorldGenObelisk.java | 37 +++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/main/java/electroblob/wizardry/entity/living/EntityRemnant.java b/src/main/java/electroblob/wizardry/entity/living/EntityRemnant.java index 35efc0ee..2a63089d 100644 --- a/src/main/java/electroblob/wizardry/entity/living/EntityRemnant.java +++ b/src/main/java/electroblob/wizardry/entity/living/EntityRemnant.java @@ -43,7 +43,6 @@ public class EntityRemnant extends EntityMob { public EntityRemnant(World world){ super(world); this.setSize(0.8f, 0.8f); - this.isImmuneToFire = true; this.moveHelper = new EntityRemnant.AIMoveControl(this); this.experienceValue = 8; } @@ -113,6 +112,19 @@ public class EntityRemnant extends EntityMob { return true; } + @Override + public float getBlockPathWeight(BlockPos pos){ + // Goddamnit Minecraft, stop imposing obscure spawning restrictions + return 1; // This won't affect pathfinding since remnants are flying mobs anyway + } + + @Override + protected float applyPotionDamageCalculations(DamageSource source, float damage){ + damage = super.applyPotionDamageCalculations(source, damage); + if(source.isMagicDamage()) damage *= 0.25f; // Remnants are 75% resistant to magic damage + return damage; + } + @Override public void onUpdate(){ diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java index e8d6d1d2..7408baee 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java @@ -3,12 +3,15 @@ package electroblob.wizardry.worldgen; import electroblob.wizardry.Wizardry; import electroblob.wizardry.block.BlockRunestone; import electroblob.wizardry.constants.Element; +import electroblob.wizardry.entity.living.EntityRemnant; import electroblob.wizardry.integration.antiqueatlas.WizardryAntiqueAtlasIntegration; import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.util.Mirror; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.WeightedSpawnerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.gen.structure.template.ITemplateProcessor; @@ -16,7 +19,6 @@ import net.minecraft.world.gen.structure.template.PlacementSettings; import net.minecraft.world.gen.structure.template.Template; import org.apache.commons.lang3.ArrayUtils; -import java.util.EnumMap; import java.util.Map; import java.util.Random; @@ -24,17 +26,7 @@ public class WorldGenObelisk extends WorldGenSurfaceStructure { private static final String SPAWNER_DATA_BLOCK_TAG = "spawner"; - private static final EnumMap MOB_TYPES = new EnumMap<>(Element.class); - - static { - MOB_TYPES.put(Element.FIRE, new ResourceLocation(Wizardry.MODID, "blaze_minion")); - MOB_TYPES.put(Element.ICE, new ResourceLocation(Wizardry.MODID, "ice_wraith")); - MOB_TYPES.put(Element.LIGHTNING, new ResourceLocation(Wizardry.MODID, "lightning_wraith")); - MOB_TYPES.put(Element.NECROMANCY, new ResourceLocation(Wizardry.MODID, "wither_skeleton_minion")); - MOB_TYPES.put(Element.EARTH, new ResourceLocation(Wizardry.MODID, "spider_minion")); - MOB_TYPES.put(Element.SORCERY, new ResourceLocation(Wizardry.MODID, "vex_minion")); - MOB_TYPES.put(Element.HEALING, new ResourceLocation(Wizardry.MODID, "husk_minion")); - } + private static final ResourceLocation REMNANT_ID = new ResourceLocation(Wizardry.MODID, "remnant"); @Override public String getStructureName(){ @@ -81,12 +73,25 @@ public class WorldGenObelisk extends WorldGenSurfaceStructure { if(entry.getValue().equals(SPAWNER_DATA_BLOCK_TAG)){ - world.setBlockState(entry.getKey(), Blocks.MOB_SPAWNER.getDefaultState()); + BlockPos pos = entry.getKey(); - if(world.getTileEntity(entry.getKey()) instanceof TileEntityMobSpawner){ + world.setBlockState(pos, Blocks.MOB_SPAWNER.getDefaultState()); - MobSpawnerBaseLogic spawnerLogic = ((TileEntityMobSpawner)world.getTileEntity(entry.getKey())).getSpawnerBaseLogic(); - spawnerLogic.setEntityId(MOB_TYPES.get(element)); + if(world.getTileEntity(pos) instanceof TileEntityMobSpawner){ + + MobSpawnerBaseLogic spawnerLogic = ((TileEntityMobSpawner)world.getTileEntity(pos)).getSpawnerBaseLogic(); + + EntityRemnant remant = new EntityRemnant(world); + remant.setElement(element); + remant.setBoundOrigin(pos); + + NBTTagCompound entityTag = new NBTTagCompound(); + entityTag.setString("id", REMNANT_ID.toString()); + remant.writeEntityToNBT(entityTag); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setTag("Entity", entityTag); + + spawnerLogic.setNextSpawnData(new WeightedSpawnerEntity(nbt)); }else{ Wizardry.logger.info("Tried to set the mob spawned by an obelisk, but the expected TileEntityMobSpawner was not present");