Added golem core: bodyguard

This commit is contained in:
makeo committed 2015-11-01 01:58:15 +01:00
1 parent 7a71dc0d95
commit 575a55e1b3
13 files changed
+476 -15

No files matched your search

@@ -70,6 +70,8 @@ public class CommonProxy implements IGuiHandler {
RegisteredRecipes.init();
ModSubstitutions.init();
RegisteredPotions.init();
}
public void postInitalize() {
@@ -0,0 +1,41 @@
package makeo.gadomancy.common.entities.ai;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.passive.EntityTameable;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 31.10.2015 15:55
*/
public class AIFollowOwner extends EntityAIFollowOwner {
EntityTameable entity;
public AIFollowOwner(EntityTameable entity, float minDist, float maxDist) {
super(entity, 0, minDist, maxDist);
this.entity = entity;
}
@Override
public void startExecuting() {
boolean avoidWater = entity.getNavigator().getAvoidsWater();
super.startExecuting();
entity.getNavigator().setAvoidsWater(avoidWater);
}
@Override
public void resetTask() {
boolean avoidWater = entity.getNavigator().getAvoidsWater();
super.resetTask();
entity.getNavigator().setAvoidsWater(avoidWater);
}
@Override
public void updateTask() {
super.field_75336_f = entity.getAIMoveSpeed();
super.updateTask();
}
}
@@ -0,0 +1,43 @@
package makeo.gadomancy.common.entities.ai;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
import net.minecraft.entity.ai.EntityAIBase;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 31.10.2015 20:15
*/
public class AISit extends EntityAIBase {
private EntityGolemBase golem;
private ExtendedGolemProperties properties;
public AISit(EntityGolemBase golem) {
this.golem = golem;
this.properties = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
setMutexBits(7);
}
@Override
public boolean shouldExecute() {
return properties.isSitting();
}
@Override
public void startExecuting() {
golem.getNavigator().clearPathEntity();
}
@Override
public boolean continueExecuting() {
golem.setTarget(null);
golem.getLookHelper().setLookPosition(0, 0, 0, 0, -45);
return properties.isSitting();
}
}
@@ -0,0 +1,43 @@
package makeo.gadomancy.common.entities.ai;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.pathfinding.PathEntity;
import thaumcraft.common.entities.ai.combat.AIGolemAttackOnCollide;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 31.10.2015 19:11
*/
public class AIUncheckedAttackOnCollide extends AIGolemAttackOnCollide {
private static final Injector INJECTOR = new Injector(AIGolemAttackOnCollide.class);
private EntityGolemBase golem;
public AIUncheckedAttackOnCollide(EntityGolemBase golem) {
super(golem);
this.golem = golem;
}
@Override
public boolean shouldExecute() {
EntityLivingBase target = golem.getAttackTarget();
if (target == null) {
return false;
}
PathEntity pathEntity = golem.getNavigator().getPathToEntityLiving(target);
if(pathEntity != null) {
INJECTOR.setObject(this);
INJECTOR.setField("entityPathEntity", pathEntity);
INJECTOR.setField("entityTarget", target);
return true;
}
return false;
}
}
@@ -0,0 +1,43 @@
package makeo.gadomancy.common.entities.ai;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.entity.EntityLivingBase;
import thaumcraft.common.entities.ai.combat.AIDartAttack;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 31.10.2015 20:03
*/
public class AIUncheckedDartAttack extends AIDartAttack {
private static final Injector INJECTOR = new Injector(AIDartAttack.class);
private EntityGolemBase golem;
public AIUncheckedDartAttack(EntityGolemBase golem) {
super(golem);
this.golem = golem;
}
@Override
public boolean shouldExecute() {
EntityLivingBase target = golem.getAttackTarget();
if (target == null) {
return false;
}
double ra = golem.getDistanceSq(target.posX, target.boundingBox.minY, target.posZ);
if (ra < 9.0D) {
return false;
}
INJECTOR.setObject(this);
INJECTOR.setField("attackTarget", target);
return true;
}
}
@@ -0,0 +1,187 @@
package makeo.gadomancy.common.entities.golems.cores;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.entities.ai.AIFollowOwner;
import makeo.gadomancy.common.entities.ai.AISit;
import makeo.gadomancy.common.entities.ai.AIUncheckedAttackOnCollide;
import makeo.gadomancy.common.entities.ai.AIUncheckedDartAttack;
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.pathfinding.PathNavigate;
import thaumcraft.common.entities.ai.combat.AIDartAttack;
import thaumcraft.common.entities.ai.misc.AIOpenDoor;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.Random;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 31.10.2015 15:35
*/
public class BodyguardCore extends AdditionalGolemCore {
@Override
public void setupGolem(EntityGolemBase golem) {
WrappedGolem wrapped = new WrappedGolem(golem);
golem.setHomeArea(0, 300000000, 0, 300000000);
golem.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(wrapped));
golem.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(wrapped));
golem.targetTasks.addTask(3, new EntityAIHurtByTarget(golem, true));
golem.tasks.addTask(1, new AISit(golem));
if (golem.decoration.contains("R")) {
golem.tasks.addTask(2, new AIUncheckedDartAttack(golem));
}
golem.tasks.addTask(3, new AIUncheckedAttackOnCollide(golem));
golem.tasks.addTask(4, new AIFollowOwner(wrapped, 5, 2));
golem.tasks.addTask(5, new AIOpenDoor(golem, true));
golem.tasks.addTask(7, new EntityAIWatchClosest(golem, EntityPlayer.class, 6.0F));
golem.tasks.addTask(8, new EntityAILookIdle(golem));
}
private static class WrappedGolem extends EntityTameable {
private EntityGolemBase golem;
public WrappedGolem(EntityGolemBase golem) {
super(golem.worldObj);
this.golem = golem;
}
@Override
public boolean isWithinHomeDistance(int p_110176_1_, int p_110176_2_, int p_110176_3_) {
return true;
}
@Override
public float getAIMoveSpeed() {
return golem.getAIMoveSpeed();
}
@Override
public Random getRNG() {
return golem.getRNG();
}
@Override
public EntityLivingBase getAttackTarget() {
return golem.getAttackTarget();
}
@Override
public boolean canAttackClass(Class p_70686_1_) {
return golem.canAttackClass(p_70686_1_);
}
@Override
public EntitySenses getEntitySenses() {
return golem.getEntitySenses();
}
@Override
public IAttributeInstance getEntityAttribute(IAttribute p_110148_1_) {
if(golem != null) {
return golem.getEntityAttribute(p_110148_1_);
}
return super.getEntityAttribute(p_110148_1_);
}
@Override
public void setAttackTarget(EntityLivingBase p_70624_1_) {
golem.setAttackTarget(p_70624_1_);
}
@Override
public boolean isTamed() {
return true;
}
@Override
public PathNavigate getNavigator() {
return golem.getNavigator();
}
@Override
public EntityAgeable createChild(EntityAgeable entity) {
return null;
}
@Override
public EntityLivingBase getOwner() {
return golem.getOwner();
}
@Override
public EntityLookHelper getLookHelper() {
return golem.getLookHelper();
}
@Override
public double getDistanceSqToEntity(Entity entity) {
return golem.getDistanceSqToEntity(entity);
}
@Override
public boolean getLeashed() {
return golem.getLeashed();
}
@Override
public int getVerticalFaceSpeed() {
return golem.getVerticalFaceSpeed();
}
@Override
public void setLocationAndAngles(double x, double y, double z, float rotationYaw, float rotationPitch) {
rotationYaw = golem.rotationYaw;
rotationPitch = golem.rotationPitch;
golem.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
this.worldObj.playSoundEffect(x, y, z, "mob.endermen.portal", 0.5F, 1.0F);
}
}
@Override
public boolean hasGui() {
return true;
}
@Override
public boolean openGui(EntityPlayer player, EntityGolemBase golem) {
ExtendedGolemProperties props = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
props.setSitting(!props.isSitting());
return true;
}
@Override
public byte getBaseCore() {
return 4;
}
@Override
public String getUnlocalizedName() {
return "gadomancy.golem.bodyguardcore";
}
@Override
public ItemStack getItem() {
return new ItemStack(RegisteredItems.itemGolemCoreBreak, 1, 1);
}
}
@@ -1,6 +1,8 @@
package makeo.gadomancy.common.entities.golems.cores;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAITasks;
import thaumcraft.common.entities.golems.EntityGolemBase;
@@ -21,14 +23,18 @@ public class EntityAITasksWrapper extends EntityAITasks {
private final EntityAITasks original;
private boolean locked = true;
public EntityAITasksWrapper(EntityGolemBase golem) {
super(golem.targetTasks.theProfiler);
private boolean scheduleUpdate;
public EntityAITasksWrapper(EntityGolemBase golem, EntityAITasks tasks, boolean scheduleUpdate) {
super(tasks.theProfiler);
this.golem = golem;
this.original = golem.targetTasks;
this.original = tasks;
this.taskEntries = new WrapperList(original.taskEntries);
this.original.taskEntries = this.taskEntries;
this.scheduleUpdate = scheduleUpdate;
}
private class WrapperList extends ArrayList {
@@ -40,6 +46,8 @@ public class EntityAITasksWrapper extends EntityAITasks {
public void clear() {
if(!isLocked()) {
super.clear();
} else if(scheduleUpdate) {
((ExtendedGolemProperties)golem.getExtendedProperties(Gadomancy.MODID)).updateGolem();
}
}
}
@@ -30,7 +30,10 @@ public class ExtendedGolemProperties implements IExtendedEntityProperties {
private boolean updateHealth = false;
private float health;
private EntityAITasksWrapper wrapper = null;
private boolean isSitting = false;
private EntityAITasksWrapper taskWrapper = null;
private EntityAITasksWrapper targetWrapper = null;
public ExtendedGolemProperties(EntityGolemBase golem) {
this.golem = golem;
@@ -48,6 +51,14 @@ public class ExtendedGolemProperties implements IExtendedEntityProperties {
return health;
}
public boolean isSitting() {
return isSitting;
}
public void setSitting(boolean isSitting) {
this.isSitting = isSitting;
}
@Override
public void saveNBTData(NBTTagCompound compound) {
AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(golem.getGolemType());
@@ -63,6 +74,8 @@ public class ExtendedGolemProperties implements IExtendedEntityProperties {
writeAdvancedGolemType(entityData, type);
golem.ridingEntity = new OverrideRidingEntity(golem, compound, golem.ridingEntity);
}
compound.setBoolean(Gadomancy.MODID + ":sitting", isSitting);
}
private static void writeAdvancedGolemType(NBTTagCompound base, AdditionalGolemType type) {
@@ -89,6 +102,8 @@ public class ExtendedGolemProperties implements IExtendedEntityProperties {
}
}
isSitting = compound.getBoolean(Gadomancy.MODID + ":sitting");
updateGolemCore();
}
@@ -109,27 +124,42 @@ public class ExtendedGolemProperties implements IExtendedEntityProperties {
}
public void setWrapperIfNeeded() {
if(wrapper == null) {
wrapper = new EntityAITasksWrapper(golem);
golem.tasks = wrapper;
boolean needsUpdate = false;
if(taskWrapper == null) {
taskWrapper = new EntityAITasksWrapper(golem, golem.tasks, true);
golem.tasks = taskWrapper;
needsUpdate = true;
}
if(targetWrapper == null) {
targetWrapper = new EntityAITasksWrapper(golem, golem.targetTasks, false);
golem.targetTasks = targetWrapper;
needsUpdate = true;
}
if(needsUpdate) {
updateGolem();
}
}
public void updateGolem() {
wrapper.unlock();
taskWrapper.unlock();
targetWrapper.unlock();
golem.setupGolem();
golem.setupGolemInventory();
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
if(core != null) {
wrapper.taskEntries.clear();
golem.targetTasks.taskEntries.clear();
taskWrapper.taskEntries.clear();
targetWrapper.taskEntries.clear();
core.setupGolem(golem);
wrapper.lock();
taskWrapper.lock();
targetWrapper.lock();
}
}
@@ -2,10 +2,13 @@ package makeo.gadomancy.common.items;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import java.util.List;
@@ -23,9 +26,30 @@ public class ItemGolemCoreBreak extends Item {
setCreativeTab(RegisteredItems.creativeTab);
}
private IIcon breakIcon;
private IIcon bodyguardIcon;
@Override
protected String getIconString() {
return Gadomancy.MODID + ":golem_core_break";
public void registerIcons(IIconRegister ir) {
breakIcon = ir.registerIcon(Gadomancy.MODID + ":golem_core_break");
bodyguardIcon = ir.registerIcon("thaumcraft:golem_core_bodyguard");
}
@Override
public IIcon getIconFromDamage(int damage) {
if(damage == 0) {
return breakIcon;
} else if(damage == 1) {
return bodyguardIcon;
}
return super.getIconFromDamage(damage);
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
list.add(new ItemStack(item, 1, 0));
list.add(new ItemStack(item, 1, 1));
}
@Override
@@ -40,7 +64,12 @@ public class ItemGolemCoreBreak extends Item {
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean showAdvanced) {
list.add(StatCollector.translateToLocal("gadomancy.golem.breakcore"));
int damage = stack.getItemDamage();
if(damage == 0) {
list.add(StatCollector.translateToLocal("gadomancy.golem.breakcore"));
} else if(damage == 1) {
list.add(StatCollector.translateToLocal("gadomancy.golem.bodyguardcore"));
}
}
@Override
@@ -4,6 +4,7 @@ import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.entities.golems.cores.BodyguardCore;
import makeo.gadomancy.common.entities.golems.cores.BreakGolemCore;
import makeo.gadomancy.common.entities.golems.types.SilverwoodGolemType;
import makeo.gadomancy.common.entities.golems.upgrades.GolemUpgrade;
@@ -29,11 +30,13 @@ public class RegisteredGolemStuff {
public static SilverwoodGolemType typeSilverwood;
public static AdditionalGolemCore breakCore;
public static AdditionalGolemCore bodyguardCore;
public static void init() {
typeSilverwood = registerGolemType("SILVERWOOD", new SilverwoodGolemType());
breakCore = registerGolemCore("breakCore", new BreakGolemCore());
bodyguardCore = registerGolemCore("bodyguardCore", new BodyguardCore());
upgradeRunicShield = registerGolemUpgrade(new GolemUpgradeRunicShield());
}
@@ -0,0 +1,26 @@
package makeo.gadomancy.common.registration;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.potion.Potion;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 31.10.2015 23:09
*/
public class RegisteredPotions {
public static void init() {
}
private static <T extends Potion> T registerPotion(Class<T> potionClass) {
int id = Potion.potionTypes.length;
Potion[] potions = new Potion[Potion.potionTypes.length + 1];
System.arraycopy(Potion.potionTypes, 0, potions, 0, Potion.potionTypes.length);
Potion.potionTypes = potions;
return new Injector(potionClass).invokeConstructor(int.class, id);
}
}