public boolean doesAccept(Aspect aspect) { if (isSaturated) { handleOverfeed(); return false; } if (aspectSaturation.containsKey(aspect)) { double percentageToSaturation = aspectSaturation.get(aspect) / SATURATION_CAP; // 0.0 - 1.0 boolean mayAdd = owningNode.getWorldObj().rand.nextFloat() > percentageToSaturation; if (mayAdd) { double inc = 1D / (1D - percentageToSaturation); if (lastFedAspect != null) { if (aspect.equals(lastFedAspect)) { inc *= evaluateFeedingDenialFunc((lastFedRow > 0 ? lastFedRow : 1)); } else { inc *= -10; lastFedRow = 0; } } this.overallHappiness += inc; // The node doesn't like to be forced to eat the same every time. if (this.overallHappiness < 0) this.overallHappiness = 0; } return mayAdd; } else { // The node does not know that aspect yet/hasn't created an immunity to it yet. // The node gets to know a new aspect, thus the happiness increases. this.overallHappiness = overallHappiness / SATURATION_DIFFICULTY; return true; } }
public void addAspect(AspectType type, Aspect aspect, int value) { if (isSaturated) return; double increasedSaturation = getSaturation(type, aspect); addSaturation(aspect, increasedSaturation); owningNode.getAspectsBase().add(aspect, value); ResearchHelper.distributeResearch( Gadomancy.MODID.toUpperCase() + ".GROWING_GROWTH", owningNode.getWorldObj(), owningNode.xCoord, owningNode.yCoord, owningNode.zCoord, 6); computeOverallSaturation(); }
private float randOffset() { return owningNode.getWorldObj().rand.nextFloat() / 3; }
private void removeFixedNode(int x, int y, int z) { owningNode.getWorldObj().setBlockToAir(x, y, z); owningNode.getWorldObj().removeTileEntity(x, y, z); owningNode.getWorldObj().markBlockForUpdate(x, y, z); this.fixedNode = null; }
public boolean updateBehavior(boolean needUpdate) { if (fixedNode != null && owningNode.ticksExisted % 3 == 0) { if (owningNode.getWorldObj().getBlock(fixedNode.xCoord, fixedNode.yCoord, fixedNode.zCoord) != RegisteredBlocks.blockNode || owningNode .getWorldObj() .getTileEntity(fixedNode.xCoord, fixedNode.yCoord, fixedNode.zCoord) == null || fixedNode.isInvalid()) { fixedNode = null; return needUpdate; } AspectList currentAspects = fixedNode.getAspects(); AspectList baseAspects = fixedNode.getAspectsBase(); if (baseAspects.getAspects().length == 0) { int x = fixedNode.xCoord; int y = fixedNode.yCoord; int z = fixedNode.zCoord; removeFixedNode(x, y, z); return needUpdate; } Aspect a = baseAspects .getAspects()[owningNode.getWorldObj().rand.nextInt(baseAspects.getAspects().length)]; if (baseAspects.getAmount(a) > 0) { if (baseAspects.reduce(a, 1)) { World world = owningNode.getWorldObj(); int fx = fixedNode.xCoord; int fy = fixedNode.yCoord; int fz = fixedNode.zCoord; int ox = owningNode.xCoord; int oy = owningNode.yCoord; int oz = owningNode.zCoord; currentAspects.reduce(a, 1); ResearchHelper.distributeResearch( Gadomancy.MODID.toUpperCase() + ".GROWING_ATTACK", owningNode.getWorldObj(), owningNode.xCoord, owningNode.yCoord, owningNode.zCoord, 16); EntityAspectOrb aspectOrb = new EntityAspectOrb(world, fx + 0.5D, fy + 0.5D, fz + 0.5D, a, 1); Vec3 dir = Vec3.createVectorHelper(fx + 0.5D, fy + 0.5D, fz + 0.5D) .subtract(Vec3.createVectorHelper(ox + 0.5D, oy + 0.5D, oz + 0.5D)) .normalize(); dir.addVector(randOffset(), randOffset(), randOffset()).normalize(); aspectOrb.setVelocity(dir.xCoord, dir.yCoord, dir.zCoord); fixedNode.getWorldObj().spawnEntityInWorld(aspectOrb); NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint( world.provider.dimensionId, ox + 0.5F, oy + 0.5F, oz + 0.5F, 32); PacketTCNodeBolt bolt = new PacketTCNodeBolt( ox + 0.5F, oy + 0.5F, oz + 0.5F, fx + 0.5F, fy + 0.5F, fz + 0.5F, 0, false); PacketHandler.INSTANCE.sendToAllAround(bolt, point); PacketAnimationAbsorb packet = new PacketAnimationAbsorb(ox, oy, oz, fx, fy, fz, 7); PacketHandler.INSTANCE.sendToAllAround(packet, point); world.markBlockForUpdate(fx, fy, fz); fixedNode.markDirty(); needUpdate = true; } else { if (baseAspects.size() <= 1) { int x = fixedNode.xCoord; int y = fixedNode.yCoord; int z = fixedNode.zCoord; removeFixedNode(x, y, z); needUpdate = true; } baseAspects.remove(a); currentAspects.remove(a); return needUpdate; } } else { if (baseAspects.size() <= 1) { int x = fixedNode.xCoord; int y = fixedNode.yCoord; int z = fixedNode.zCoord; removeFixedNode(x, y, z); needUpdate = true; } baseAspects.remove(a); currentAspects.remove(a); return needUpdate; } } return needUpdate; }
public boolean mayZapNow() { return overallHappiness > owningNode.getWorldObj().rand.nextInt(HAPPINESS_CAP * HAPPINESS_CAP); }