diff --git a/src/main/java/makeo/gadomancy/client/renderers/item/ItemRenderTileEntity.java b/src/main/java/makeo/gadomancy/client/renderers/item/ItemRenderTileEntity.java index 0ad9076..230fd2a 100644 --- a/src/main/java/makeo/gadomancy/client/renderers/item/ItemRenderTileEntity.java +++ b/src/main/java/makeo/gadomancy/client/renderers/item/ItemRenderTileEntity.java @@ -1,5 +1,6 @@ package makeo.gadomancy.client.renderers.item; +import makeo.gadomancy.common.blocks.tiles.TileManipulationFocus; import makeo.gadomancy.common.utils.world.fake.FakeWorld; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.ItemStack; @@ -46,11 +47,13 @@ public class ItemRenderTileEntity implements IItemRenderer @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { if(type == IItemRenderer.ItemRenderType.ENTITY) - GL11.glTranslatef(-0.5f, -0.5f, -0.5f); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - if(type == ItemRenderType.INVENTORY) { - GL11.glTranslatef(0, -0.1f, 0); - } + if(type == ItemRenderType.INVENTORY) + GL11.glTranslatef(0, -0.1F, 0); + + if(type == ItemRenderType.EQUIPPED_FIRST_PERSON && tile instanceof TileManipulationFocus) + GL11.glTranslatef(0, 0.6F, 0); this.renderer.renderTileEntityAt(tile, 0.0D, 0.0D, 0.0D, 0.0F); } diff --git a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileAuraPylon.java b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileAuraPylon.java new file mode 100644 index 0000000..f99f274 --- /dev/null +++ b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileAuraPylon.java @@ -0,0 +1,486 @@ +package makeo.gadomancy.common.blocks.tiles; + +import net.minecraft.command.IEntitySelector; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraftforge.common.util.ForgeDirection; +import thaumcraft.api.ThaumcraftApiHelper; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.aspects.IAspectContainer; +import thaumcraft.api.aspects.IEssentiaTransport; +import thaumcraft.common.entities.EntityPermanentItem; +import thaumcraft.common.entities.EntitySpecialItem; +import thaumcraft.common.items.ItemCrystalEssence; + +import java.util.List; + +/** + * 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 + *

+ * Created by HellFirePvP @ 11.11.2015 14:30 + */ +public class TileAuraPylon extends SynchronizedTileEntity implements IAspectContainer, IEssentiaTransport { + + //This TileEntity is designed to be used stacked with others of its kind - without limits. + //The aspects the tiles contain are all provided in the top tile of the structure + //The actual work is done in the top tile of the structure + + //The inner aspect type is defined by a piece of crystallized Essentia being checked by the master-tile + //The master tile informs all the other tiles what aspect currently is in use. + + //All tiles check each 8 ticks if the structure is still complete/contains an IO- and a master-tile + //Master tile updates its state and the state of all tiles every 4 ticks so Aspect information and item information are still valid. + //Master tile updates effects all 8 ticks if there is an internal aspect present. + //Input tile handles Essentia IO all 8 ticks and thus provides needed amount information. + + private EntityPermanentItem tcPermItem; + private int ticksExisted = 0; + private Aspect holdingAspect; + private int amount = 0; + private int maxAmount = 16; + private boolean isMasterTile; + private boolean isInputTile; + + //Individual. + @Override + public void updateEntity() { + ticksExisted++; + + if ((ticksExisted & 7) == 0) { + if (checkComponents()) return; + } + + if (isInputTile()) { + handleIO(); + } + if (isMasterTile()) { + handleCrystal(); + if (holdingAspect != null) { + handleEffectDistribution(); + } + } + } + + //Special to masterTile only! + private void handleEffectDistribution() { + int count = 1; + TileEntity iter = worldObj.getTileEntity(xCoord, yCoord - count, zCoord); + while(iter != null && iter instanceof TileAuraPylon) { + ((TileAuraPylon) iter).holdingAspect = holdingAspect; + count++; + worldObj.markBlockForUpdate(xCoord, yCoord - count, zCoord); + iter.markDirty(); + } + } + + //Special to masterTile only! + private void handleCrystal() { + if ((ticksExisted & 3) != 0) return; + + tcPermItem = searchForPermItem(); + + if (holdingAspect == null) { + if(tcPermItem == null) return; + holdingAspect = ((ItemCrystalEssence) tcPermItem.getEntityItem().getItem()).getAspects(tcPermItem.getEntityItem()).getAspects()[0]; + } else { + if(tcPermItem == null) { + holdingAspect = null; + } + } + } + + //Special to masterTile only! + private EntityPermanentItem searchForPermItem() { + if(tcPermItem != null) return tcPermItem; + EntityPermanentItem tcPermItem = tryFindPermItem(); + if (tcPermItem == null) { + tcPermItem = tryVortexPossibleItems(); + } + return tcPermItem; + } + + //Special to masterTile only! + private EntityPermanentItem tryVortexPossibleItems() { + TileAuraPylon io = getInputTile(); + if (io == null) return null; + ChunkCoordinates rel = new ChunkCoordinates(xCoord, yCoord - (yCoord - io.yCoord), zCoord); + List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class, + AxisAlignedBB.getBoundingBox(rel.posX - 0.5, rel.posY - 0.5, rel.posZ - 0.5, rel.posX + 0.5, rel.posY + 0.5, rel.posZ + 0.5).expand(8, 8, 8), new IEntitySelector() { + @Override + public boolean isEntityApplicable(Entity e) { + return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) && + e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null && + ((EntityItem) e).getEntityItem().getItem() instanceof ItemCrystalEssence; + } + }); + Entity dummy = new EntityItem(worldObj); + dummy.posX = rel.posX + 0.5; + dummy.posY = rel.posY + 0.5; + dummy.posZ = rel.posZ + 0.5; + + //MC code. + EntityItem entity = null; + double d0 = Double.MAX_VALUE; + for (Object entityItem : entityItems) { + EntityItem entityIt = (EntityItem) entityItem; + if (entityIt != dummy) { + double d1 = dummy.getDistanceSqToEntity(entityIt); + if (d1 <= d0) { + entity = entityIt; + d0 = d1; + } + } + } + if(entity == null) return null; + if(dummy.getDistanceSqToEntity(entity) < 0.2) { + EntityPermanentItem item = new EntityPermanentItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, entity.getEntityItem()); + entity.worldObj.spawnEntityInWorld(item); + item.setVelocity(0, 0, 0); + item.hoverStart = entity.hoverStart; + item.age = entity.age; + entity.setDead(); + return item; + } else { + applyMovementVectors(entity); + } + return null; + } + + //Special to masterTile only! + private void applyMovementVectors(EntityItem entity) { + double var3 = (this.xCoord + 0.5D - entity.posX) / 15.0D; + double var5 = (this.yCoord + 0.5D - entity.posY) / 15.0D; + double var7 = (this.zCoord + 0.5D - entity.posZ) / 15.0D; + double var9 = Math.sqrt(var3 * var3 + var5 * var5 + var7 * var7); + double var11 = 1.0D - var9; + if (var11 > 0.0D) { + var11 *= var11; + entity.motionX += var3 / var9 * var11 * 0.15D; + entity.motionY += var5 / var9 * var11 * 0.25D; + entity.motionZ += var7 / var9 * var11 * 0.15D; + } + } + + //Special to masterTile only! + private EntityPermanentItem tryFindPermItem() { + TileAuraPylon io = getInputTile(); + if (io == null) return null; + ChunkCoordinates rel = new ChunkCoordinates(xCoord, yCoord - (yCoord - io.yCoord), zCoord); + Entity dummy = new EntityItem(worldObj); + dummy.posX = rel.posX + 0.5; + dummy.posY = rel.posY + 0.5; + dummy.posZ = rel.posZ + 0.5; + Entity permItem = worldObj.findNearestEntityWithinAABB(EntityPermanentItem.class, + AxisAlignedBB.getBoundingBox(rel.posX - 0.5, rel.posY - 0.5, rel.posZ - 0.5, rel.posX + 0.5, rel.posY + 0.5, rel.posZ + 0.5), dummy); + if (permItem == null) return null; + if (((EntityPermanentItem) permItem).getEntityItem() != null && ((EntityPermanentItem) permItem).getEntityItem().getItem() instanceof ItemCrystalEssence) { + return (EntityPermanentItem) permItem; + } + return null; + } + + //Special to inputTile only! + private void handleIO() { + if ((!worldObj.isRemote) && ((ticksExisted & 7) == 0) && (getEssentiaAmount() < getMaxAmount())) { + TileEntity te = ThaumcraftApiHelper.getConnectableTile(this.worldObj, this.xCoord, this.yCoord, this.zCoord, ForgeDirection.DOWN); + if (te != null) { + IEssentiaTransport ic = (IEssentiaTransport) te; + if (!ic.canOutputTo(ForgeDirection.UP)) { + return; + } + + if ((holdingAspect != null) && (ic.getSuctionAmount(ForgeDirection.UP) < getSuctionAmount(ForgeDirection.DOWN))) { + addToContainer(holdingAspect, ic.takeEssentia(holdingAspect, 1, ForgeDirection.UP)); + } + } + } + } + + //Individual. + //Returns true, if state has changed, false if still complete state. + private boolean checkComponents() { + TileAuraPylon te = getMasterTile(); + if (te == null) { + breakTile(); + return true; + } + te = getInputTile(); + if (te == null) { + breakTile(); + return true; + } + return false; + } + + //Individual. + private void breakTile() { + //TODO break... ? + } + + //Individual. + @Override + public boolean canUpdate() { + return true; + } + + //Individual. + public void setTileInformation(boolean isMaster, boolean isInput) { + this.isMasterTile = isMaster; + this.isInputTile = isInput; + } + + //Individual. + public boolean isInputTile() { + return isInputTile; + } + + //Individual. + public TileAuraPylon getInputTile() { + if (isInputTile()) return this; + TileEntity superTile = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord); + if (superTile == null || !(superTile instanceof TileAuraPylon)) return null; + return ((TileAuraPylon) superTile).getInputTile(); + } + + //Individual. + public boolean isMasterTile() { + return isMasterTile; + } + + //Individual. + public TileAuraPylon getMasterTile() { + if (isMasterTile()) return this; + TileEntity superTile = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord); + if (superTile == null || !(superTile instanceof TileAuraPylon)) return null; + return ((TileAuraPylon) superTile).getMasterTile(); + } + + //Dynamic. + public int getEssentiaAmount() { + TileAuraPylon io = getInputTile(); + if (io == null) return 0; + return io.amount; + } + + //Dynamic. + public Aspect getAspectType() { + TileAuraPylon io = getInputTile(); + if (io == null) return null; + return io.holdingAspect; + } + + //Dynamic. + public int getMaxAmount() { + TileAuraPylon io = getInputTile(); + if (io == null) return 0; + int max = io.maxAmount; + int counter = 1; + TileEntity superTile = worldObj.getTileEntity(xCoord, yCoord + counter, zCoord); + while (superTile != null && superTile instanceof TileAuraPylon) { + max += ((TileAuraPylon) superTile).maxAmount; + counter++; + superTile = worldObj.getTileEntity(xCoord, yCoord + counter, zCoord); + } + return max; + } + + @Override + public void readCustomNBT(NBTTagCompound compound) { + this.isInputTile = compound.getBoolean("input"); + this.isMasterTile = compound.getBoolean("master"); + + String tag = compound.getString("aspect"); + if (tag != null && !tag.equals("")) { + this.holdingAspect = Aspect.getAspect(tag); + } + this.amount = compound.getInteger("amount"); + this.maxAmount = compound.getInteger("maxAmount"); + } + + @Override + public void writeCustomNBT(NBTTagCompound compound) { + compound.setBoolean("input", isInputTile); + compound.setBoolean("master", isMasterTile); + if (holdingAspect != null) { + compound.setString("aspect", holdingAspect.getTag()); + } + compound.setInteger("amount", amount); + compound.setInteger("maxAmount", maxAmount); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // IAspectContainer + /////////////////////////////////////////////////////////////////////////////////////////////// + + //Dynamic. + @Override + public AspectList getAspects() { + TileAuraPylon io = getInputTile(); + AspectList al = new AspectList(); + if (io != null && io.holdingAspect != null && io.amount > 0) { + al.add(io.holdingAspect, io.amount); + } + return al; + } + + //NO-OP + @Override + public void setAspects(AspectList aspectList) { + } + + //Individual. + @Override + public boolean doesContainerAccept(Aspect aspect) { + return isInputTile() && holdingAspect != null && holdingAspect.equals(aspect); + } + + //Individual. + @Override + public int addToContainer(Aspect aspect, int amount) { + if (amount == 0) { + return amount; + } + + if (!isInputTile()) return 0; + if (aspect == null) return 0; + + if (holdingAspect != null && this.amount < maxAmount && aspect == holdingAspect) { + int added = Math.min(amount, this.maxAmount - this.amount); + this.amount += added; + amount -= added; + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + markDirty(); + } + return amount; + } + + //Individual. + @Override + public boolean takeFromContainer(Aspect aspect, int i) { + if (!isInputTile()) return false; + if (aspect == null || holdingAspect == null) return false; + + if (this.amount >= i && holdingAspect.equals(aspect)) { + this.amount -= i; + if (this.amount <= 0) { + this.holdingAspect = null; + this.amount = 0; + } + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + markDirty(); + return true; + } + return false; + } + + //Individual. + //You may only extract 1 at a time. + @Override + public boolean takeFromContainer(AspectList aspectList) { + return false; + } + + //Individual. + @Override + public boolean doesContainerContainAmount(Aspect aspect, int i) { + return isInputTile() && holdingAspect != null && this.amount >= i && aspect == holdingAspect; + } + + //Individual. + @Override + public boolean doesContainerContain(AspectList list) { + if (!isInputTile()) return false; + if (holdingAspect == null) return false; + + for (Aspect a : list.getAspects()) if ((this.amount > 0) && (a == holdingAspect)) return true; + return false; + } + + //Individual. + @Override + public int containerContains(Aspect aspect) { + return 0; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // IEssentiaTransport + /////////////////////////////////////////////////////////////////////////////////////////////// + + //Individual. + @Override + public boolean isConnectable(ForgeDirection face) { + return isInputTile() && face == ForgeDirection.DOWN; + } + + //Individual. + @Override + public boolean canInputFrom(ForgeDirection face) { + return isInputTile() && face == ForgeDirection.DOWN; + } + + //Individual. + @Override + public boolean canOutputTo(ForgeDirection face) { + return false; + } + + //NO-OP + @Override + public void setSuction(Aspect aspect, int i) { + } + + //Individual. + @Override + public Aspect getSuctionType(ForgeDirection forgeDirection) { + return isInputTile() ? holdingAspect : null; + } + + @Override + public int getSuctionAmount(ForgeDirection forgeDirection) { + if (!isInputTile()) return 0; + if (holdingAspect == null) return 0; + return getMinimumSuction(); + } + + @Override + public int takeEssentia(Aspect aspect, int amt, ForgeDirection direction) { + return 0; + } + + @Override + public int addEssentia(Aspect aspect, int amt, ForgeDirection direction) { + if (!isInputTile()) return 0; + return canInputFrom(direction) ? amount - addToContainer(aspect, amount) : 0; + } + + //Individual. + @Override + public Aspect getEssentiaType(ForgeDirection forgeDirection) { + return isInputTile() ? holdingAspect : null; + } + + //Individual. + @Override + public int getEssentiaAmount(ForgeDirection forgeDirection) { + return isInputTile() ? amount : 0; + } + + @Override + public int getMinimumSuction() { + return 128; + } + + //Individual. + @Override + public boolean renderExtendedTube() { + return false; + } +} diff --git a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileNodeManipulator.java b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileNodeManipulator.java index 353126f..2d94000 100644 --- a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileNodeManipulator.java +++ b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileNodeManipulator.java @@ -48,7 +48,7 @@ import java.util.Map; public class TileNodeManipulator extends TileWandPedestal implements IAspectContainer, IWandable { private static final int NODE_MANIPULATION_POSSIBLE_WORK_START = 70; - private static final int NODE_MANIPULATION_WORK_ASPECT_CAP = 150; + private static final int NODE_MANIPULATION_WORK_ASPECT_CAP = 120; private static final int ELDRITCH_PORTAL_CREATOR_WORK_START = 120; private static final int ELDRITCH_PORTAL_CREATOR_ASPECT_CAP = 150; @@ -268,6 +268,8 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont } private void scheduleManipulation() { + float overSized = calcOversize(NODE_MANIPULATION_POSSIBLE_WORK_START); + workTick = 0; isWorking = false; workAspectList = new AspectList(); @@ -275,9 +277,14 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont TileEntity te = worldObj.getTileEntity(xCoord, yCoord + 2, zCoord); if(te == null || !(te instanceof TileExtendedNode)) return; TileExtendedNode node = (TileExtendedNode) te; + int areaRange = NODE_MANIPULATION_WORK_ASPECT_CAP - NODE_MANIPULATION_POSSIBLE_WORK_START; + int percChanceForBetter = 0; + if(areaRange > 0) { + percChanceForBetter = (int) ((overSized / ((float) areaRange)) * 100); + } NodeManipulatorResult result; do { - result = NodeManipulatorResultHandler.getRandomResult(node); + result = NodeManipulatorResultHandler.getRandomResult(node, percChanceForBetter); } while (!result.affect(node)); PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, xCoord, yCoord + 2, zCoord); PacketHandler.INSTANCE.sendToAllAround(packet, getTargetPoint(32)); @@ -287,6 +294,14 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont node.markDirty(); } + private float calcOversize(int neededAspects) { + int overall = 0; + for(Aspect a : Aspect.getPrimalAspects()) { + overall += workAspectList.getAmount(a) - neededAspects; + } + return ((float) overall) / 6F; + } + private void doAspectChecks(int aspectCap, int possibleWorkStart) { if(canDrainFromWand(aspectCap)) { Aspect a = drainAspectFromWand(aspectCap); diff --git a/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java b/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java index 4a2d3a3..260e411 100644 --- a/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java +++ b/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java @@ -2,6 +2,7 @@ package makeo.gadomancy.common.events; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import makeo.gadomancy.common.blocks.tiles.TileAuraPylon; import makeo.gadomancy.common.data.ModConfig; import makeo.gadomancy.common.familiar.FamiliarAIController; import makeo.gadomancy.common.utils.world.TCMazeHandler; @@ -13,6 +14,8 @@ import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; +import net.minecraftforge.event.entity.player.EntityItemPickupEvent; +import thaumcraft.common.entities.EntityPermanentItem; import thaumcraft.common.items.armor.Hover; /** @@ -46,6 +49,15 @@ public class EventHandlerEntity { } } + @SubscribeEvent + public void on(EntityItemPickupEvent event) { + if(!event.entityPlayer.worldObj.isRemote) { + if(event.item != null && event.item instanceof EntityPermanentItem) { + //TODO inform TileAuraPylon... + } + } + } + @SubscribeEvent public void on(LivingEvent.LivingUpdateEvent event) { if(event.entityLiving == null || !(event.entityLiving instanceof EntityPlayer)) return; diff --git a/src/main/java/makeo/gadomancy/common/node/GrowingNodeBehavior.java b/src/main/java/makeo/gadomancy/common/node/GrowingNodeBehavior.java index 865cb52..de0818b 100644 --- a/src/main/java/makeo/gadomancy/common/node/GrowingNodeBehavior.java +++ b/src/main/java/makeo/gadomancy/common/node/GrowingNodeBehavior.java @@ -31,7 +31,7 @@ import java.util.Map; public class GrowingNodeBehavior { public static final double SATURATION_DIFFICULTY = 15D; - public static final double SATURATION_CAP = 90D; + public static final double SATURATION_CAP = 110D; public static final int HAPPINESS_CAP = 400; //The node the growing node attacks. diff --git a/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResult.java b/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResult.java index 0d57eca..5b55d31 100644 --- a/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResult.java +++ b/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResult.java @@ -13,8 +13,15 @@ import net.minecraft.util.WeightedRandom; */ public abstract class NodeManipulatorResult extends WeightedRandom.Item { - public NodeManipulatorResult(int chanceToRoll) { + private NodeManipulatorResultHandler.ResultType resultType; + + public NodeManipulatorResult(int chanceToRoll, NodeManipulatorResultHandler.ResultType resultType) { super(chanceToRoll); + this.resultType = resultType; + } + + public NodeManipulatorResultHandler.ResultType getResultType() { + return resultType; } public boolean canAffect(TileExtendedNode node) { diff --git a/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResultHandler.java b/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResultHandler.java index 5f5d702..96b99de 100644 --- a/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResultHandler.java +++ b/src/main/java/makeo/gadomancy/common/node/NodeManipulatorResultHandler.java @@ -24,20 +24,28 @@ public class NodeManipulatorResultHandler { private NodeManipulatorResultHandler() {} - public static NodeManipulatorResult getRandomResult(TileExtendedNode affectedNode) { - return getRandomResult(affectedNode.getWorldObj().rand, affectedNode); + public static NodeManipulatorResult getRandomResult(TileExtendedNode affectedNode, int percChance) { + return getRandomResult(affectedNode.getWorldObj().rand, affectedNode, percChance); } - public static NodeManipulatorResult getRandomResult(Random random, TileExtendedNode affectedNode) { + public static NodeManipulatorResult getRandomResult(Random random, TileExtendedNode affectedNode, int percChance) { + int resultPositiveChance = Math.round(((float) percChance) / 5F); List localResults = new ArrayList(); for(NodeManipulatorResult result : possibleResults) { - if(result.canAffect(affectedNode)) localResults.add(result); + if(result.canAffect(affectedNode)) { + ResultType type = result.getResultType(); + if(type == ResultType.NEGATIVE) { + if(random.nextInt(100) < resultPositiveChance) continue; + } + + localResults.add(result); + } } if(localResults.isEmpty()) return null; return (NodeManipulatorResult) WeightedRandom.getRandomItem(random, localResults); } - public static void combine(AspectList containingList, Aspect a, Aspect b) { + public static void combine(AspectList containingList, Aspect a, Aspect b, int addition) { if(!canCombine(a, b)) return; Aspect combination = NodeManipulatorResultHandler.getCombination(a, b); int lowerAmount; @@ -48,7 +56,7 @@ public class NodeManipulatorResultHandler { } containingList.remove(a, lowerAmount); containingList.remove(b, lowerAmount); - containingList.add(combination, lowerAmount); + containingList.add(combination, lowerAmount + addition); } public static boolean canCombine(Aspect a, Aspect b) { @@ -85,4 +93,12 @@ public class NodeManipulatorResultHandler { possibleResults.add(RegisteredManipulations.resultGainPrimal); } + public static enum ResultType { + + POSITIVE, + NEGATIVE, + NEUTRAL + + } + } diff --git a/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java b/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java index c47760e..7a6d23f 100644 --- a/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java +++ b/src/main/java/makeo/gadomancy/common/registration/RegisteredBlocks.java @@ -13,6 +13,7 @@ import makeo.gadomancy.common.blocks.BlockStickyJar; import makeo.gadomancy.common.blocks.BlockStoneMachine; import makeo.gadomancy.common.blocks.tiles.TileAdditionalEldritchPortal; import makeo.gadomancy.common.blocks.tiles.TileArcaneDropper; +import makeo.gadomancy.common.blocks.tiles.TileAuraPylon; import makeo.gadomancy.common.blocks.tiles.TileBlockProtector; import makeo.gadomancy.common.blocks.tiles.TileExtendedNode; import makeo.gadomancy.common.blocks.tiles.TileExtendedNodeJar; @@ -119,6 +120,7 @@ public class RegisteredBlocks { registerTile(TileManipulationFocus.class); registerTile(TileAdditionalEldritchPortal.class); registerTile(TileBlockProtector.class); + //registerTile(TileAuraPylon.class); } private static void registerTile(Class tile, String name) { diff --git a/src/main/java/makeo/gadomancy/common/registration/RegisteredFamiliarAI.java b/src/main/java/makeo/gadomancy/common/registration/RegisteredFamiliarAI.java index 527019f..42fb6a1 100644 --- a/src/main/java/makeo/gadomancy/common/registration/RegisteredFamiliarAI.java +++ b/src/main/java/makeo/gadomancy/common/registration/RegisteredFamiliarAI.java @@ -15,6 +15,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.world.World; import java.util.ArrayList; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -56,7 +57,7 @@ public class RegisteredFamiliarAI { int rangeInc = ((ItemFamiliar) itemStack.getItem()).getAttackRangeIncrease(itemStack); List lastTargetters = getPotentialTargets(world, parent, rangeInc); - if(lastTargetters.size() < 1) { + if(lastTargetters.size() == 0) { FamiliarAIController.cleanTargetterList(parent); return; } @@ -77,13 +78,17 @@ public class RegisteredFamiliarAI { private List getPotentialTargets(World world, EntityPlayer player, int rangeInc) { List validTargets = getCloseEnoughTargetters(world, player, rangeInc); - int range = 5 + rangeInc; - List mobs = world.getEntitiesWithinAABB(IMob.class, AxisAlignedBB.getBoundingBox(player.posX - 0.5, player.posY - 0.5, player.posZ - 0.5, player.posX + 0.5, player.posY + 0.5, player.posZ + 0.5).expand(range, range, range)); - for(Object mobObj : mobs) { - if(!(mobObj instanceof EntityLivingBase)) continue; - EntityLivingBase mob = (EntityLivingBase) mobObj; - if(mob.isDead) continue; - if(!validTargets.contains(mob)) validTargets.add(mob); + + EntityLivingBase attacker = player.getLastAttacker(); + int range = 8 + rangeInc; + if(attacker != null && !validTargets.contains(attacker) && !attacker.isDead && attacker.getDistanceSq(player.posX, player.posY, player.posZ) <= range * range) { + validTargets.add(attacker); + } + + Iterator it = validTargets.iterator(); + while(it.hasNext()) { + EntityLivingBase e = it.next(); + if(e.isDead || e instanceof EntityPlayer) it.remove(); } return validTargets; } diff --git a/src/main/java/makeo/gadomancy/common/registration/RegisteredManipulations.java b/src/main/java/makeo/gadomancy/common/registration/RegisteredManipulations.java index b120fe4..23ee174 100644 --- a/src/main/java/makeo/gadomancy/common/registration/RegisteredManipulations.java +++ b/src/main/java/makeo/gadomancy/common/registration/RegisteredManipulations.java @@ -23,7 +23,7 @@ import java.util.List; */ public class RegisteredManipulations { - public static NodeManipulatorResult resultBreakCompounds = new NodeManipulatorResult(4) { + public static NodeManipulatorResult resultBreakCompounds = new NodeManipulatorResult(4, NodeManipulatorResultHandler.ResultType.NEGATIVE) { @Override public boolean affect(TileExtendedNode node) { AspectList baseList = node.getAspectsBase(); @@ -45,7 +45,7 @@ public class RegisteredManipulations { } }; - public static NodeManipulatorResult resultCombineAspects = new NodeManipulatorResult(5) { + public static NodeManipulatorResult resultCombineAspects = new NodeManipulatorResult(5, NodeManipulatorResultHandler.ResultType.POSITIVE) { @Override public boolean affect(TileExtendedNode node) { AspectList base = node.getAspectsBase(); @@ -53,8 +53,9 @@ public class RegisteredManipulations { return false; if(base.getAspects().length == 2) { if(!NodeManipulatorResultHandler.canCombine(base.getAspects()[0], base.getAspects()[1])) return false; - NodeManipulatorResultHandler.combine(base, base.getAspects()[0], base.getAspects()[1]); - NodeManipulatorResultHandler.combine(node.getAspects(), base.getAspects()[0], base.getAspects()[1]); + int addition = node.getWorldObj().rand.nextInt(4); + NodeManipulatorResultHandler.combine(base, base.getAspects()[0], base.getAspects()[1], addition); + NodeManipulatorResultHandler.combine(node.getAspects(), base.getAspects()[0], base.getAspects()[1], addition); return true; } if(base.getAspects().length > 2) { @@ -74,8 +75,9 @@ public class RegisteredManipulations { Aspect b = base.getAspects()[indexB]; if(NodeManipulatorResultHandler.canCombine(a, b)) { - NodeManipulatorResultHandler.combine(base, a, b); - NodeManipulatorResultHandler.combine(node.getAspects(), a, b); + int addition = node.getWorldObj().rand.nextInt(4); + NodeManipulatorResultHandler.combine(base, a, b, addition); + NodeManipulatorResultHandler.combine(node.getAspects(), a, b, addition); combineCount--; actuallyCombined++; continue doLabel; @@ -93,7 +95,7 @@ public class RegisteredManipulations { } }; - public static NodeManipulatorResult resultIncreaseModifier = new NodeManipulatorResult(4) { + public static NodeManipulatorResult resultIncreaseModifier = new NodeManipulatorResult(4, NodeManipulatorResultHandler.ResultType.POSITIVE) { @Override public boolean canAffect(TileExtendedNode node) { @@ -120,7 +122,7 @@ public class RegisteredManipulations { } }; - public static NodeManipulatorResult resultDecreaseModifier = new NodeManipulatorResult(5) { + public static NodeManipulatorResult resultDecreaseModifier = new NodeManipulatorResult(5, NodeManipulatorResultHandler.ResultType.NEGATIVE) { @Override public boolean canAffect(TileExtendedNode node) { @@ -147,27 +149,32 @@ public class RegisteredManipulations { } }; - public static NodeManipulatorResult resultGainPrimal = new NodeManipulatorResult(3) { + public static NodeManipulatorResult resultGainPrimal = new NodeManipulatorResult(3, NodeManipulatorResultHandler.ResultType.POSITIVE) { @Override public boolean affect(TileExtendedNode node) { List primals = Aspect.getPrimalAspects(); + int visSize = node.getAspectsBase().visSize(); + int size = node.getAspectsBase().size(); int modulo = primals.size(); int index = node.getWorldObj().rand.nextInt(primals.size()); for (int i = 0; i < primals.size(); i++) { int get = (index + i) % modulo; Aspect rand = primals.get(get); if(node.getAspectsBase().getAmount(rand) <= 0) { - int randGain = node.getWorldObj().rand.nextInt(8) + 3; - node.getAspectsBase().add(rand, randGain); - node.getAspects().add(rand, randGain); - return true; + int randGain = visSize / (size * 2); + if(randGain > 0) { + node.getAspectsBase().add(rand, randGain); + node.getAspects().add(rand, randGain); + return true; + } + return false; } } return false; } }; - public static NodeManipulatorResult resultSwitchType = new NodeManipulatorResult(2) { + public static NodeManipulatorResult resultSwitchType = new NodeManipulatorResult(2, NodeManipulatorResultHandler.ResultType.NEUTRAL) { @Override public boolean affect(TileExtendedNode node) { NodeType newType = node.getNodeType(); @@ -192,7 +199,7 @@ public class RegisteredManipulations { } }; - public static NodeManipulatorResult resultApplyGrowing = new NodeManipulatorResult(1) { + public static NodeManipulatorResult resultApplyGrowing = new NodeManipulatorResult(1, NodeManipulatorResultHandler.ResultType.POSITIVE) { @Override public boolean affect(TileExtendedNode node) { boolean isGrowingAlready = node.getExtendedNodeType() != null && node.getExtendedNodeType().equals(ExtendedNodeType.GROWING);