- NodeManipulator: Can manipulate nodes now + still some fx missing

This commit is contained in:
HellFirePvP committed 2015-10-30 20:43:43 +01:00
1 parent 0457e83936
commit b24e75e14f
10 files changed
+527 -49

No files matched your search

@@ -87,6 +87,6 @@ public class RenderEventHandler {
@SubscribeEvent
public void worldRenderEvent(RenderWorldLastEvent event) {
ExtendedTypeDisplayManager.notifyRenderTick();
MultiTickEffectDispatcher.notifyRenderTick(Minecraft.getMinecraft().theWorld);
MultiTickEffectDispatcher.notifyRenderTick(Minecraft.getMinecraft().theWorld, event.partialTicks);
}
}
@@ -1,7 +1,9 @@
package makeo.gadomancy.client.util;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import thaumcraft.client.lib.UtilsFX;
import thaumcraft.common.Thaumcraft;
import java.util.ArrayList;
@@ -21,23 +23,54 @@ public class MultiTickEffectDispatcher {
private static ReentrantLock renderLock = new ReentrantLock();
private static List<VortexDigInfo> vortexDigInfos = new ArrayList<VortexDigInfo>();
private static List<FloatyLineInfo> floatyLineInfos = new ArrayList<FloatyLineInfo>();
public static void notifyRenderTick(World currentRenderWorld) {
public static void notifyRenderTick(World currentRenderWorld, float partialTicks) {
renderLock.lock();
try {
handleVortexDiggingEffects(currentRenderWorld);
handleWispyLineEffects(currentRenderWorld, partialTicks);
} finally {
renderLock.unlock();
}
}
private static void handleWispyLineEffects(World currentRenderWorld, float partialTicks) {
Iterator<FloatyLineInfo> it = floatyLineInfos.iterator();
while(it.hasNext()) {
FloatyLineInfo info = it.next();
if(info.dimId != currentRenderWorld.provider.dimensionId) {
it.remove();
continue;
}
info.renderTicks++;
if(info.renderTicks > info.tickCap) {
it.remove();
continue;
}
if(info.randomOffset == -1) {
info.randomOffset = currentRenderWorld.rand.nextInt(20);
}
float ticks = Minecraft.getMinecraft().renderViewEntity.ticksExisted + info.randomOffset + partialTicks;
UtilsFX.drawFloatyLine(info.pedestalX, info.pedestalY, info.pedestalZ, info.originX, info.originY, info.originZ, partialTicks, info.colorAsInt, "textures/misc/wispy.png", -0.02F, Math.min(ticks, 10.0F) / 10.0F);
}
}
private static void handleVortexDiggingEffects(World currentRenderWorld) {
Iterator<VortexDigInfo> it = vortexDigInfos.iterator();
while(it.hasNext()) {
VortexDigInfo info = it.next();
if(info.dimId != currentRenderWorld.provider.dimensionId) it.remove();
if(info.dimId != currentRenderWorld.provider.dimensionId) {
it.remove();
continue;
}
info.renderTicks++;
if(info.renderTicks > info.tickCap) it.remove();
if(info.renderTicks > info.tickCap) {
it.remove();
continue;
}
Thaumcraft.proxy.boreDigFx(currentRenderWorld, info.tX, info.tY, info.tZ, info.oX, info.oY, info.oZ, info.blockInstance, info.meta);
}
@@ -52,6 +85,38 @@ public class MultiTickEffectDispatcher {
}
}
public static void registerFloatyLine(FloatyLineInfo info) {
renderLock.lock();
try {
floatyLineInfos.add(info);
} finally {
renderLock.unlock();
}
}
public static class FloatyLineInfo {
private int dimId;
private double pedestalX, pedestalY, pedestalZ;
private double originX, originY, originZ;
private int renderTicks = 0;
private int tickCap;
private int colorAsInt;
private int randomOffset = -1;
public FloatyLineInfo(int dimId, double pedestalX, double pedestalY, double pedestalZ, double originX, double originY, double originZ, int tickCap, int colorAsInt) {
this.dimId = dimId;
this.pedestalX = pedestalX;
this.pedestalY = pedestalY;
this.pedestalZ = pedestalZ;
this.originX = originX;
this.originY = originY;
this.originZ = originZ;
this.tickCap = tickCap;
this.colorAsInt = colorAsInt;
}
}
public static class VortexDigInfo {
private int dimId;
@@ -0,0 +1,36 @@
package makeo.gadomancy.client.util;
import net.minecraft.world.World;
import thaumcraft.common.Thaumcraft;
import java.awt.*;
/**
* 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 @ 30.10.2015 20:08
*/
public class UtilsFX {
private static final Color[] runeColors = new Color[] { new Color(0xB60707), new Color(0xEE3782), new Color(0xF37B20), new Color(0xFF6722), new Color(0xFF6D30), new Color(0xFF0000) };
public static void doRuneEffects(World world, int x, int y, int z) {
if(world.isRemote) {
int cnt = 20;
while(cnt > 0) {
cnt--;
Color rand = runeColors[world.rand.nextInt(runeColors.length)];
Thaumcraft.proxy.blockRunes(world, x + randomOffset(world), y + randomOffset(world), z + randomOffset(world),
rand.getRed() / 255F, rand.getGreen() / 255F, rand.getBlue() / 255F, world.rand.nextInt(10) + 30, -0.01F - (world.rand.nextBoolean() ? world.rand.nextBoolean() ? 0.02F : 0.01F : 0F));
}
}
}
private static float randomOffset(World worldObj) {
return (worldObj.rand.nextFloat() * (worldObj.rand.nextBoolean() ? 1 : -1)) / 2F;
}
}
@@ -1,11 +1,7 @@
package makeo.gadomancy.common.blocks.tiles;
import net.minecraft.world.World;
import thaumcraft.common.Thaumcraft;
import thaumcraft.common.tiles.TileInfusionPillar;
import java.awt.*;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
@@ -16,28 +12,9 @@ import java.awt.*;
*/
public class TileManipulatorPillar extends TileInfusionPillar {
private static final Color[] runeColors = new Color[] { new Color(0xB60707), new Color(0xEE3782), new Color(0xF37B20), new Color(0xFF6722), new Color(0xFF6D30), new Color(0xFF0000) };
public static void doRuneEffects(World world, int x, int y, int z) {
if(world.isRemote) {
int cnt = 20;
while(cnt > 0) {
cnt--;
Color rand = runeColors[world.rand.nextInt(runeColors.length)];
Thaumcraft.proxy.blockRunes(world, x + randomOffset(world), y + randomOffset(world), z + randomOffset(world),
rand.getRed() / 255F, rand.getGreen() / 255F, rand.getBlue() / 255F, world.rand.nextInt(10) + 30, -0.01F - (world.rand.nextBoolean() ? world.rand.nextBoolean() ? 0.02F : 0.01F : 0F));
}
}
}
public void setOrientation(byte orientation) {
this.orientation = orientation;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
private static float randomOffset(World worldObj) {
return (worldObj.rand.nextFloat() * (worldObj.rand.nextBoolean() ? 1 : -1)) / 2F;
}
}
@@ -3,6 +3,10 @@ package makeo.gadomancy.common.blocks.tiles;
import cpw.mods.fml.common.network.NetworkRegistry;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
import makeo.gadomancy.common.network.packets.PacketTCNodeBolt;
import makeo.gadomancy.common.network.packets.PacketTCWispyLine;
import makeo.gadomancy.common.node.NodeManipulatorResult;
import makeo.gadomancy.common.node.NodeManipulatorResultHandler;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredMultiblocks;
import makeo.gadomancy.common.utils.MultiblockHelper;
@@ -17,9 +21,14 @@ import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.IAspectContainer;
import thaumcraft.api.wands.IWandable;
import thaumcraft.common.items.wands.ItemWandCasting;
import thaumcraft.common.lib.utils.InventoryUtils;
import thaumcraft.common.tiles.TileWandPedestal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
@@ -30,23 +39,174 @@ import thaumcraft.common.tiles.TileWandPedestal;
*/
public class TileNodeManipulator extends TileWandPedestal implements IAspectContainer, IWandable {
private static final int POSSIBLE_WORK_START = 50;
private static final int WORK_ASPECT_CAP = 250;
private int ticksExisted = 0;
private boolean multiblockStructurePresent = false;
private boolean isMultiblock = false;
private int workPhase = 0;
private AspectList workAspectList = new AspectList();
private boolean isManipulating = true;
private int manipulatorTick = 0;
@Override
public void updateEntity() {
ticksExisted++;
if(isInMultiblock() && ticksExisted % 2 == 0 && !worldObj.isRemote) {
checkMultiblock();
if(!isMultiblockStructurePresent()) {
breakMultiblock();
isMultiblock = false;
}
if(worldObj.isRemote) return;
//TODO multiblock tick.
if(isInMultiblock()) {
checkMultiblockTick();
}
if(isInMultiblock()) { //If multiblock is still present
multiblockTick();
}
}
private void multiblockTick() {
if(!isManipulating) {
doAspectChecks();
} else {
manipulationTick();
}
}
private void manipulationTick() {
manipulatorTick++;
if(manipulatorTick < 300) {
if(manipulatorTick % 16 == 0) {
PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_RUNES, xCoord, yCoord, zCoord);
PacketHandler.INSTANCE.sendToAllAround(packet, getTargetPoint(32));
}
if(worldObj.rand.nextInt(4) == 0) {
Vec3 rel = getRelPillarLoc(worldObj.rand.nextInt(4));
PacketTCNodeBolt bolt = new PacketTCNodeBolt(xCoord + 0.5F, yCoord + 2.5F, zCoord + 0.5F, (float) (xCoord + 0.5F + rel.xCoord), (float) (yCoord + 2.5F + rel.yCoord), (float) (zCoord + 0.5F + rel.zCoord));
PacketHandler.INSTANCE.sendToAllAround(bolt, getTargetPoint(32));
}
} else {
sheduleManipulation();
}
}
private Vec3 getRelPillarLoc(int pillarId) {
switch (pillarId) {
case 0:
return Vec3.createVectorHelper(0.7, -0.6, 0.7);
case 1:
return Vec3.createVectorHelper(-0.7, -0.6, 0.7);
case 2:
return Vec3.createVectorHelper(-0.7, -0.6, -0.7);
case 3:
return Vec3.createVectorHelper(0.7, -0.6, -0.7);
}
return Vec3.createVectorHelper(0, 0, 0);
}
private void sheduleManipulation() {
manipulatorTick = 0;
isManipulating = false;
workAspectList = new AspectList();
TileEntity te = worldObj.getTileEntity(xCoord, yCoord + 2, zCoord);
if(te == null || !(te instanceof TileExtendedNode)) return; //Multiblock broken?
TileExtendedNode node = (TileExtendedNode) te;
NodeManipulatorResult result;
do {
result = NodeManipulatorResultHandler.getRandomResult(node);
} while (!result.affect(node));
//TODO fx
switch (result.getEffectType()) {
case NEGATIVE:
break;
case POSITIVE:
break;
case NEUTRAL:
break;
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord + 2, zCoord);
markDirty();
node.markDirty();
}
private void doAspectChecks() {
if(canDrainFromWand()) {
Aspect a = drainAspectFromWand();
if(a != null) {
playAspectDrainFromWand(a);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
} else {
checkIfEnoughVis();
}
}
private void checkIfEnoughVis() {
boolean enough = true;
for(Aspect a : Aspect.getPrimalAspects()) {
if(workAspectList.getAmount(a) < POSSIBLE_WORK_START) {
enough = false;
break;
}
}
if(enough) {
isManipulating = true;
}
}
private Aspect drainAspectFromWand() {
ItemStack stack = getStackInSlot(0);
if(stack == null || !(stack.getItem() instanceof ItemWandCasting)) return null; //Should never happen..
AspectList aspects = ((ItemWandCasting) stack.getItem()).getAllVis(stack);
for(Aspect a : getRandomlyOrderedPrimalAspectList()) {
if(aspects.getAmount(a) >= 100 && workAspectList.getAmount(a) < WORK_ASPECT_CAP) {
int amt = aspects.getAmount(a);
((ItemWandCasting) stack.getItem()).storeVis(stack, a, amt - 100);
workAspectList.add(a, 1);
return a;
}
}
return null;
}
private List<Aspect> getRandomlyOrderedPrimalAspectList() {
ArrayList<Aspect> primals = (ArrayList<Aspect>) Aspect.getPrimalAspects().clone();
Collections.shuffle(primals);
return primals;
}
private boolean canDrainFromWand() {
ItemStack stack = getStackInSlot(0);
if(stack == null || !(stack.getItem() instanceof ItemWandCasting)) return false;
AspectList aspects = ((ItemWandCasting) stack.getItem()).getAllVis(stack);
for(Aspect a : Aspect.getPrimalAspects()) {
if(aspects.getAmount(a) < 100) continue;
if(workAspectList.getAmount(a) < WORK_ASPECT_CAP) return true;
}
return false;
}
private void checkMultiblockTick() {
checkMultiblock();
if(!isMultiblockStructurePresent()) {
breakMultiblock();
isMultiblock = false;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
}
}
private void playAspectDrainFromWand(Aspect drained) {
if(drained == null) return;
NetworkRegistry.TargetPoint point = getTargetPoint(32);
PacketTCWispyLine line = new PacketTCWispyLine(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 0.8, zCoord + 0.5,
xCoord + 0.5, yCoord + 1.4 + (((double) worldObj.rand.nextInt(4)) / 10D), zCoord + 0.5, 40, drained.getColor());
PacketHandler.INSTANCE.sendToAllAround(line, point);
}
@Override
@@ -54,6 +214,11 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
return super.receiveClientEvent(p_145842_1_, p_145842_2_);
}
private void dropWand() {
if(getStackInSlot(0) != null)
InventoryUtils.dropItems(worldObj, xCoord, yCoord, zCoord);
}
public void breakMultiblock() {
MultiblockHelper.MultiblockPattern compareableCompleteStructure = RegisteredMultiblocks.completeNodeManipulatorMultiblock;
MultiblockHelper.MultiblockPattern toRestore = RegisteredMultiblocks.incompleteNodeManipulatorMultiblock;
@@ -71,8 +236,7 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
}
}
if(getStackInSlot(0) != null)
InventoryUtils.dropItems(worldObj, xCoord, yCoord, zCoord);
dropWand();
}
public void formMultiblock() {
@@ -87,21 +251,22 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
worldObj.setBlock(absX, absY, absZ, info.block, info.meta, 0);
worldObj.markBlockForUpdate(absX, absY, absZ);
}
NetworkRegistry.TargetPoint target = new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32);
NetworkRegistry.TargetPoint target = getTargetPoint(32);
TileManipulatorPillar pillar = (TileManipulatorPillar) worldObj.getTileEntity(xCoord + 1, yCoord, zCoord + 1); //wrong
pillar.setOrientation((byte) 5);
PacketStartAnimation animation = new PacketStartAnimation(PacketStartAnimation.ID_PILLAR_RUNES, pillar.xCoord, pillar.yCoord, pillar.zCoord);
PacketStartAnimation animation = new PacketStartAnimation(PacketStartAnimation.ID_RUNES, pillar.xCoord, pillar.yCoord, pillar.zCoord);
PacketHandler.INSTANCE.sendToAllAround(animation, target);
TileManipulatorPillar pillar2 = (TileManipulatorPillar) worldObj.getTileEntity(xCoord - 1, yCoord, zCoord + 1);
pillar2.setOrientation((byte) 3);
animation = new PacketStartAnimation(PacketStartAnimation.ID_PILLAR_RUNES, pillar2.xCoord, pillar2.yCoord, pillar2.zCoord);
animation = new PacketStartAnimation(PacketStartAnimation.ID_RUNES, pillar2.xCoord, pillar2.yCoord, pillar2.zCoord);
PacketHandler.INSTANCE.sendToAllAround(animation, target);
TileManipulatorPillar pillar3 = (TileManipulatorPillar) worldObj.getTileEntity(xCoord + 1, yCoord, zCoord - 1); //wrong
pillar3.setOrientation((byte) 4);
animation = new PacketStartAnimation(PacketStartAnimation.ID_PILLAR_RUNES, pillar3.xCoord, pillar3.yCoord, pillar3.zCoord);
animation = new PacketStartAnimation(PacketStartAnimation.ID_RUNES, pillar3.xCoord, pillar3.yCoord, pillar3.zCoord);
PacketHandler.INSTANCE.sendToAllAround(animation, target);
animation = new PacketStartAnimation(PacketStartAnimation.ID_PILLAR_RUNES, xCoord - 1, yCoord, zCoord - 1);
animation = new PacketStartAnimation(PacketStartAnimation.ID_RUNES, xCoord - 1, yCoord, zCoord - 1);
PacketHandler.INSTANCE.sendToAllAround(animation, target);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
markDirty();
this.isMultiblock = true;
}
@@ -113,6 +278,10 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
NBTTagCompound tag = compound.getCompoundTag("Gadomancy");
this.multiblockStructurePresent = tag.getBoolean("mBlockPresent");
this.isMultiblock = tag.getBoolean("mBlockState");
this.isManipulating = tag.getBoolean("manipulating");
this.manipulatorTick = tag.getInteger("manipulatorTick");
this.workPhase = tag.getInteger("workPhase");
workAspectList.readFromNBT(tag, "workAspectList");
}
@Override
@@ -122,6 +291,10 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
NBTTagCompound tag = new NBTTagCompound();
tag.setBoolean("mBlockPresent", this.multiblockStructurePresent);
tag.setBoolean("mBlockState", this.isMultiblock);
tag.setBoolean("manipulating", this.isManipulating);
tag.setInteger("manipulatorTick", this.manipulatorTick);
tag.setInteger("workPhase", this.workPhase);
workAspectList.writeToNBT(tag, "workAspectList");
compound.setTag("Gadomancy", tag);
}
@@ -155,9 +328,13 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
return isInMultiblock() && super.canInsertItem(par1, par2ItemStack, par3);
}
public NetworkRegistry.TargetPoint getTargetPoint(double radius) {
return new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, radius);
}
@Override
public AspectList getAspects() {
return new AspectList();
return workAspectList;
}
@Override
@@ -7,6 +7,7 @@ import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.network.packets.PacketAnimationAbsorb;
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
import makeo.gadomancy.common.network.packets.PacketTCNodeBolt;
import makeo.gadomancy.common.network.packets.PacketTCWispyLine;
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
/**
@@ -27,5 +28,6 @@ public class PacketHandler {
INSTANCE.registerMessage(PacketStartAnimation.class, PacketStartAnimation.class, id++, Side.CLIENT);
INSTANCE.registerMessage(PacketAnimationAbsorb.class, PacketAnimationAbsorb.class, id++, Side.CLIENT);
INSTANCE.registerMessage(PacketTCNodeBolt.class, PacketTCNodeBolt.class, id++, Side.CLIENT);
INSTANCE.registerMessage(PacketTCWispyLine.class, PacketTCWispyLine.class, id++, Side.CLIENT);
}
}
@@ -6,10 +6,9 @@ import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import makeo.gadomancy.client.util.UtilsFX;
import makeo.gadomancy.common.blocks.tiles.TileExtendedNode;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import makeo.gadomancy.common.blocks.tiles.TileManipulatorPillar;
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
import makeo.gadomancy.common.utils.ExplosionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntity;
@@ -28,7 +27,7 @@ public class PacketStartAnimation implements IMessage, IMessageHandler<PacketSta
public static final byte ID_INFUSIONCLAW = 0;
public static final byte ID_EX_VORTEX = 1;
public static final byte ID_BURST = 2;
public static final byte ID_PILLAR_RUNES = 3;
public static final byte ID_RUNES = 3;
private byte annimationId;
private int x;
@@ -78,8 +77,8 @@ public class PacketStartAnimation implements IMessage, IMessageHandler<PacketSta
case ID_BURST:
Thaumcraft.proxy.burst(Minecraft.getMinecraft().theWorld, message.x + 0.5F, message.y + 0.5F, message.z + 0.5F, Minecraft.getMinecraft().theWorld.rand.nextInt(3) + 1);
break;
case ID_PILLAR_RUNES:
TileManipulatorPillar.doRuneEffects(Minecraft.getMinecraft().theWorld, message.x, message.y, message.z);
case ID_RUNES:
UtilsFX.doRuneEffects(Minecraft.getMinecraft().theWorld, message.x, message.y, message.z);
break;
}
return null;
@@ -0,0 +1,73 @@
package makeo.gadomancy.common.network.packets;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import makeo.gadomancy.client.util.MultiTickEffectDispatcher;
/**
* 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 HellFirePvP @ 28.10.2015 23:28
*/
public class PacketTCWispyLine implements IMessage, IMessageHandler<PacketTCWispyLine, IMessage> {
private int dimId;
private double pedestalX, pedestalY, pedestalZ;
private double originX, originY, originZ;
private int tickCap;
private int colorAsInt;
public PacketTCWispyLine() {}
public PacketTCWispyLine(int dimId, double pedestalX, double pedestalY, double pedestalZ, double originX, double originY, double originZ, int tickCap, int colorAsInt) {
this.dimId = dimId;
this.pedestalX = pedestalX;
this.pedestalY = pedestalY;
this.pedestalZ = pedestalZ;
this.originX = originX;
this.originY = originY;
this.originZ = originZ;
this.tickCap = tickCap;
this.colorAsInt = colorAsInt;
}
@Override
public void fromBytes(ByteBuf buf) {
dimId = buf.readInt();
pedestalX = buf.readDouble();
pedestalY = buf.readDouble();
pedestalZ = buf.readDouble();
originX = buf.readDouble();
originY = buf.readDouble();
originZ = buf.readDouble();
tickCap = buf.readInt();
colorAsInt = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(dimId);
buf.writeDouble(pedestalX);
buf.writeDouble(pedestalY);
buf.writeDouble(pedestalZ);
buf.writeDouble(originX);
buf.writeDouble(originY);
buf.writeDouble(originZ);
buf.writeInt(tickCap);
buf.writeInt(colorAsInt);
}
@Override
public IMessage onMessage(PacketTCWispyLine p, MessageContext ctx) {
MultiTickEffectDispatcher.FloatyLineInfo info =
new MultiTickEffectDispatcher.FloatyLineInfo(p.dimId, p.pedestalX, p.pedestalY, p.pedestalZ,
p.originX, p.originY, p.originZ, p.tickCap, p.colorAsInt);
MultiTickEffectDispatcher.registerFloatyLine(info);
return null;
}
}
@@ -3,6 +3,9 @@ package makeo.gadomancy.common.node;
import makeo.gadomancy.common.blocks.tiles.TileExtendedNode;
import makeo.gadomancy.common.registration.RegisteredManipulations;
import net.minecraft.util.WeightedRandom;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.lib.research.ResearchManager;
import java.util.ArrayList;
import java.util.List;
@@ -13,7 +16,7 @@ import java.util.Random;
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
*
* Created by HellFirePvP @ 28.10.2015 11:43
*/
public class NodeManipulatorResultHandler {
@@ -22,6 +25,10 @@ public class NodeManipulatorResultHandler {
private NodeManipulatorResultHandler() {}
public static NodeManipulatorResult getRandomResult(TileExtendedNode affectedNode) {
return getRandomResult(affectedNode.getWorldObj().rand, affectedNode);
}
public static NodeManipulatorResult getRandomResult(Random random, TileExtendedNode affectedNode) {
List<NodeManipulatorResult> localResults = new ArrayList<NodeManipulatorResult>();
for(NodeManipulatorResult result : possibleResults) {
@@ -31,8 +38,43 @@ public class NodeManipulatorResultHandler {
return (NodeManipulatorResult) WeightedRandom.getRandomItem(random, localResults);
}
public static void combine(AspectList containingList, Aspect a, Aspect b) {
if(!canCombine(a, b)) return;
Aspect combination = NodeManipulatorResultHandler.getCombination(a, b);
int lowerAmount;
if(containingList.getAmount(a) < containingList.getAmount(b)) {
lowerAmount = containingList.getAmount(a);
} else {
lowerAmount = containingList.getAmount(b);
}
containingList.remove(a, lowerAmount);
containingList.remove(b, lowerAmount);
containingList.add(combination, lowerAmount);
}
public static boolean canCombine(Aspect a, Aspect b) {
return getCombination(a, b) != null;
}
public static Aspect getCombination(Aspect a, Aspect b) {
for(Aspect aspect : Aspect.getCompoundAspects()) {
Aspect[] components = aspect.getComponents();
if((components[0] == a && components[1] == b) ||
components[0] == b && components[1] == a) {
return aspect;
}
}
return null;
}
static {
//Aspect combination pair
possibleResults.add(RegisteredManipulations.resultBreakCompounds);
possibleResults.add(RegisteredManipulations.resultCombineAspects);
//Modifier pair
possibleResults.add(RegisteredManipulations.resultIncreaseModifier);
possibleResults.add(RegisteredManipulations.resultDecreaseModifier);
}
}
@@ -2,8 +2,10 @@ package makeo.gadomancy.common.registration;
import makeo.gadomancy.common.blocks.tiles.TileExtendedNode;
import makeo.gadomancy.common.node.NodeManipulatorResult;
import makeo.gadomancy.common.node.NodeManipulatorResultHandler;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.nodes.NodeModifier;
/**
* This class is part of the Gadomancy Mod
@@ -15,7 +17,7 @@ import thaumcraft.api.aspects.AspectList;
*/
public class RegisteredManipulations {
public static NodeManipulatorResult resultBreakCompounds = new NodeManipulatorResult(1, NodeManipulatorResult.ResultType.NEUTRAL) {
public static NodeManipulatorResult resultBreakCompounds = new NodeManipulatorResult(4, NodeManipulatorResult.ResultType.NEUTRAL) {
@Override
public boolean affect(TileExtendedNode node) {
AspectList baseList = node.getAspectsBase();
@@ -28,8 +30,113 @@ public class RegisteredManipulations {
baseList.remove(a);
baseList.add(subComponents[0], initialValue);
list.add(subComponents[0], initialValue);
baseList.add(subComponents[1], initialValue);
list.add(subComponents[1], initialValue);
return true;
}
}
return false;
}
};
public static NodeManipulatorResult resultCombineAspects = new NodeManipulatorResult(4, NodeManipulatorResult.ResultType.NEUTRAL) {
@Override
public boolean affect(TileExtendedNode node) {
AspectList base = node.getAspectsBase();
if(base.getAspects().length < 2)
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]);
return true;
}
if(base.getAspects().length > 2) {
int actuallyCombined = 0;
int combineCount = node.getWorldObj().rand.nextInt(1) + 1;
doLabel:
do {
if(base.getAspects().length < 2) break;
int randIndexForA = node.getWorldObj().rand.nextInt(base.getAspects().length);
for (int i = 0; i < base.getAspects().length; i++) {
int indexA = (i + randIndexForA) % base.getAspects().length;
Aspect a = base.getAspects()[indexA];
int randIndexForB = node.getWorldObj().rand.nextInt(base.getAspects().length);
for (int j = 0; j < base.getAspects().length; j++) {
int indexB = (j + randIndexForB) % base.getAspects().length;
Aspect b = base.getAspects()[indexB];
if(NodeManipulatorResultHandler.canCombine(a, b)) {
NodeManipulatorResultHandler.combine(base, a, b);
NodeManipulatorResultHandler.combine(node.getAspects(), a, b);
combineCount--;
actuallyCombined++;
continue doLabel;
} else if(base.getAspects().length <= 2) {
break doLabel;
}
}
}
combineCount--;
} while (combineCount > 0);
if(actuallyCombined > 0) return true;
}
return false;
}
};
public static NodeManipulatorResult resultIncreaseModifier = new NodeManipulatorResult(1, NodeManipulatorResult.ResultType.POSITIVE) {
@Override
public boolean canAffect(TileExtendedNode node) {
return node.getNodeModifier() != NodeModifier.BRIGHT;
}
@Override
public boolean affect(TileExtendedNode node) {
if(node.getNodeModifier() == null) {
node.setNodeModifier(NodeModifier.BRIGHT);
return true;
}
switch (node.getNodeModifier()) {
case BRIGHT:
return false;
case PALE:
node.setNodeModifier(null);
break;
case FADING:
node.setNodeModifier(NodeModifier.PALE);
break;
}
return true;
}
};
public static NodeManipulatorResult resultDecreaseModifier = new NodeManipulatorResult(1, NodeManipulatorResult.ResultType.NEGATIVE) {
@Override
public boolean canAffect(TileExtendedNode node) {
return node.getNodeModifier() != NodeModifier.FADING;
}
@Override
public boolean affect(TileExtendedNode node) {
if(node.getNodeModifier() == null) {
node.setNodeModifier(NodeModifier.PALE);
return true;
}
switch (node.getNodeModifier()) {
case BRIGHT:
node.setNodeModifier(null);
break;
case PALE:
node.setNodeModifier(NodeModifier.FADING);
break;
case FADING:
return false;
}
return true;
}
};