summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-04-28 21:16:36 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-04-28 21:16:36 +0100
commit1210d2561884e9039137443fd9fcca788ac63efc (patch)
tree6da82e8945c3ec15459f5f3deeae861651bff10c
parent6317f416d37f08160fb261447aba6cb84dd9886e (diff)
downloadkinniutils-1210d2561884e9039137443fd9fcca788ac63efc.tar.bz2
Basic filter functional
-rw-r--r--src/main/java/net/flarn/kinniutils/KinniUtils.java3
-rw-r--r--src/main/java/net/flarn/kinniutils/block/BlockParticleFilter.java30
-rw-r--r--src/main/java/net/flarn/kinniutils/handlers/ParticleFilter.java64
-rw-r--r--src/main/java/net/flarn/kinniutils/init/ModBlocks.java16
-rw-r--r--src/main/java/net/flarn/kinniutils/proxy/ClientProxy.java7
-rw-r--r--src/main/java/net/flarn/kinniutils/proxy/CommonProxy.java2
-rw-r--r--src/main/java/net/flarn/kinniutils/proxy/IProxy.java1
-rw-r--r--src/main/java/net/flarn/kinniutils/proxy/ServerProxy.java1
-rw-r--r--src/main/java/net/flarn/kinniutils/refs/Names.java10
-rw-r--r--src/main/java/net/flarn/kinniutils/tileentity/TileParticleFilter.java17
10 files changed, 150 insertions, 1 deletions
diff --git a/src/main/java/net/flarn/kinniutils/KinniUtils.java b/src/main/java/net/flarn/kinniutils/KinniUtils.java
index 63793f5..92eb875 100644
--- a/src/main/java/net/flarn/kinniutils/KinniUtils.java
+++ b/src/main/java/net/flarn/kinniutils/KinniUtils.java
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import net.flarn.kinniutils.init.ModBlocks;
import net.flarn.kinniutils.proxy.IProxy;
import net.flarn.kinniutils.refs.Core;
@@ -21,6 +22,8 @@ public class KinniUtils {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
// Network, mod config, items, blocks
+ proxy.registerParticleFilters();
+ ModBlocks.init();
}
@Mod.EventHandler
diff --git a/src/main/java/net/flarn/kinniutils/block/BlockParticleFilter.java b/src/main/java/net/flarn/kinniutils/block/BlockParticleFilter.java
new file mode 100644
index 0000000..1b3ecbc
--- /dev/null
+++ b/src/main/java/net/flarn/kinniutils/block/BlockParticleFilter.java
@@ -0,0 +1,30 @@
+package net.flarn.kinniutils.block;
+
+import net.flarn.kinniutils.refs.Names;
+import net.flarn.kinniutils.tileentity.TileParticleFilter;
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.block.material.Material;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+
+/**
+ * Created by dsilvers on 28/04/15.
+ */
+public class BlockParticleFilter extends Block implements ITileEntityProvider {
+ public BlockParticleFilter() {
+ super(Material.iron);
+ setHardness(10F);
+ setResistance(50F);
+ setStepSound(soundTypeStone);
+ setCreativeTab(CreativeTabs.tabDecorations);
+ setBlockName(Names.Blocks.PARTICLE_FILTER);
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World world, int metadata) {
+ return new TileParticleFilter();
+ }
+
+}
diff --git a/src/main/java/net/flarn/kinniutils/handlers/ParticleFilter.java b/src/main/java/net/flarn/kinniutils/handlers/ParticleFilter.java
new file mode 100644
index 0000000..5097bd0
--- /dev/null
+++ b/src/main/java/net/flarn/kinniutils/handlers/ParticleFilter.java
@@ -0,0 +1,64 @@
+package net.flarn.kinniutils.handlers;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.common.gameevent.TickEvent;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.particle.EffectRenderer;
+import net.minecraft.client.particle.EntityFX;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Created by dsilvers on 28/04/15.
+ */
+public class ParticleFilter {
+ public static class FilterEntry {
+ double x;
+ double y;
+ double z;
+ double range_sq;
+ public FilterEntry(double x, double y, double z, double range) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.range_sq = range * range;
+ }
+ }
+
+ private static List<FilterEntry> filters = new LinkedList<FilterEntry>();
+
+ public static void addFilterAt(double x, double y, double z, double range) {
+ filters.add(new FilterEntry(x, y, z, range));
+ }
+
+ @SubscribeEvent
+ public void onRenderTick(TickEvent.RenderTickEvent event) {
+ Minecraft mc = Minecraft.getMinecraft();
+ if (event.phase == TickEvent.Phase.START && filters.size() != 0) {
+ EffectRenderer er = mc.effectRenderer;
+ List<EntityFX> layers[] = er.fxLayers;
+ for (int i = 0; i < layers.length; ++i) {
+ for (int j = 0; j < layers[i].size(); ++j) {
+ EntityFX e = layers[i].get(j);
+ if (e != null) {
+ layers[i].set(j, filterFX(e));
+ }
+ }
+ }
+ }
+ filters.clear();
+ }
+
+ private EntityFX filterFX(EntityFX entity) {
+ for (FilterEntry filter : filters) {
+ double dist_x = filter.x - entity.posX;
+ double dist_y = filter.y - entity.posY;
+ double dist_z = filter.z - entity.posZ;
+ double dist = (dist_x * dist_x) + (dist_y * dist_y) + (dist_z * dist_z);
+ if (dist < filter.range_sq) { return null; }
+ }
+ return entity;
+ }
+}
diff --git a/src/main/java/net/flarn/kinniutils/init/ModBlocks.java b/src/main/java/net/flarn/kinniutils/init/ModBlocks.java
new file mode 100644
index 0000000..ecb2bde
--- /dev/null
+++ b/src/main/java/net/flarn/kinniutils/init/ModBlocks.java
@@ -0,0 +1,16 @@
+package net.flarn.kinniutils.init;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+import net.flarn.kinniutils.block.BlockParticleFilter;
+import net.flarn.kinniutils.refs.Names;
+
+/**
+ * Created by dsilvers on 28/04/15.
+ */
+public class ModBlocks {
+ public static final BlockParticleFilter blockParticleFilter = new BlockParticleFilter();
+
+ public static void init() {
+ GameRegistry.registerBlock(blockParticleFilter, Names.Blocks.PARTICLE_FILTER);
+ }
+}
diff --git a/src/main/java/net/flarn/kinniutils/proxy/ClientProxy.java b/src/main/java/net/flarn/kinniutils/proxy/ClientProxy.java
index 187b177..f3d3826 100644
--- a/src/main/java/net/flarn/kinniutils/proxy/ClientProxy.java
+++ b/src/main/java/net/flarn/kinniutils/proxy/ClientProxy.java
@@ -1,7 +1,14 @@
package net.flarn.kinniutils.proxy;
+import cpw.mods.fml.client.FMLClientHandler;
+import cpw.mods.fml.common.FMLCommonHandler;
+import net.flarn.kinniutils.handlers.ParticleFilter;
+
/**
* Created by dsilvers on 28/04/15.
*/
public class ClientProxy extends CommonProxy {
+ public void registerParticleFilters() {
+ FMLCommonHandler.instance().bus().register(new ParticleFilter());
+ }
}
diff --git a/src/main/java/net/flarn/kinniutils/proxy/CommonProxy.java b/src/main/java/net/flarn/kinniutils/proxy/CommonProxy.java
index e406d43..a831c8e 100644
--- a/src/main/java/net/flarn/kinniutils/proxy/CommonProxy.java
+++ b/src/main/java/net/flarn/kinniutils/proxy/CommonProxy.java
@@ -3,5 +3,5 @@ package net.flarn.kinniutils.proxy;
/**
* Created by dsilvers on 28/04/15.
*/
-public class CommonProxy implements IProxy {
+public abstract class CommonProxy implements IProxy {
}
diff --git a/src/main/java/net/flarn/kinniutils/proxy/IProxy.java b/src/main/java/net/flarn/kinniutils/proxy/IProxy.java
index 8522cee..1480aa7 100644
--- a/src/main/java/net/flarn/kinniutils/proxy/IProxy.java
+++ b/src/main/java/net/flarn/kinniutils/proxy/IProxy.java
@@ -4,4 +4,5 @@ package net.flarn.kinniutils.proxy;
* Created by dsilvers on 28/04/15.
*/
public interface IProxy {
+ public abstract void registerParticleFilters();
}
diff --git a/src/main/java/net/flarn/kinniutils/proxy/ServerProxy.java b/src/main/java/net/flarn/kinniutils/proxy/ServerProxy.java
index 2d9c170..7f927ef 100644
--- a/src/main/java/net/flarn/kinniutils/proxy/ServerProxy.java
+++ b/src/main/java/net/flarn/kinniutils/proxy/ServerProxy.java
@@ -4,4 +4,5 @@ package net.flarn.kinniutils.proxy;
* Created by dsilvers on 28/04/15.
*/
public class ServerProxy extends CommonProxy {
+ public void registerParticleFilters() { }
}
diff --git a/src/main/java/net/flarn/kinniutils/refs/Names.java b/src/main/java/net/flarn/kinniutils/refs/Names.java
new file mode 100644
index 0000000..1c49ad7
--- /dev/null
+++ b/src/main/java/net/flarn/kinniutils/refs/Names.java
@@ -0,0 +1,10 @@
+package net.flarn.kinniutils.refs;
+
+/**
+ * Created by dsilvers on 28/04/15.
+ */
+public class Names {
+ public static final class Blocks {
+ public static final String PARTICLE_FILTER = "particlefilter";
+ }
+}
diff --git a/src/main/java/net/flarn/kinniutils/tileentity/TileParticleFilter.java b/src/main/java/net/flarn/kinniutils/tileentity/TileParticleFilter.java
new file mode 100644
index 0000000..eb16453
--- /dev/null
+++ b/src/main/java/net/flarn/kinniutils/tileentity/TileParticleFilter.java
@@ -0,0 +1,17 @@
+package net.flarn.kinniutils.tileentity;
+
+import net.flarn.kinniutils.handlers.ParticleFilter;
+import net.minecraft.tileentity.TileEntity;
+
+/**
+ * Created by dsilvers on 28/04/15.
+ */
+public class TileParticleFilter extends TileEntity {
+ @Override
+ public void updateEntity() {
+ if (worldObj.isRemote) {
+ // Client only
+ ParticleFilter.addFilterAt(this.xCoord, this.yCoord, this.zCoord, 5);
+ }
+ }
+}