Skip to content

Commit

Permalink
Split out client-side events into their own dispatcher, to avoid Error
Browse files Browse the repository at this point in the history
if running server-side
  • Loading branch information
planetguy32 committed Oct 4, 2015
1 parent a52319f commit eb12caa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.eventhandler.EventPriority;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
Expand All @@ -19,8 +18,6 @@
import me.planetguy.remaininmotion.api.event.CancelableOnBlockAddedEvent;
import me.planetguy.remaininmotion.api.event.IBlockPos;
import me.planetguy.remaininmotion.api.event.MotionFinalizeEvent;
import me.planetguy.remaininmotion.api.event.PostRenderDuringMovementEvent;
import me.planetguy.remaininmotion.api.event.PreRenderDuringMovementEvent;
import me.planetguy.remaininmotion.api.event.RotatingTEPreUnpackEvent;
import me.planetguy.remaininmotion.api.event.TEPostPlaceEvent;
import me.planetguy.remaininmotion.api.event.TEPrePlaceEvent;
Expand All @@ -33,8 +30,6 @@ public class EventPool {
private static BlockPreMoveEvent theBlockPreMoveEvent=new BlockPreMoveEvent();
private static BlockSelectForMoveEvent theBlockSelectForMoveEvent=new BlockSelectForMoveEvent();
private static BlockSelectForRotateEvent theBlockSelectForRotateEvent=new BlockSelectForRotateEvent();
private static PreRenderDuringMovementEvent thePreRenderDuringMovementEvent=new PreRenderDuringMovementEvent();
private static PostRenderDuringMovementEvent thePostRenderDuringMovementEvent=new PostRenderDuringMovementEvent();
private static CancelableOnBlockAddedEvent theCancelableOnBlockAddedEvent=new CancelableOnBlockAddedEvent();
private static MotionFinalizeEvent theMotionFinalizeEvent=new MotionFinalizeEvent();
private static BlocksReplacedEvent theBlocksReplacedEvent=new BlocksReplacedEvent();
Expand Down Expand Up @@ -89,27 +84,6 @@ public static String postBlockSelectForMoveEvent(CarriagePackage poster, boolean
}
}

public static boolean postPreRenderDuringMovementEvent(RenderBlocks blockRenderer, int x, int y, int z, TileEntity entity, int pass) {
thePreRenderDuringMovementEvent.renderBlocks=blockRenderer;
thePreRenderDuringMovementEvent.x=x;
thePreRenderDuringMovementEvent.y=y;
thePreRenderDuringMovementEvent.z=z;
thePreRenderDuringMovementEvent.tile=entity;
thePreRenderDuringMovementEvent.pass=pass;
postEvent(thePreRenderDuringMovementEvent);
return thePreRenderDuringMovementEvent.isCanceled();
}

public static void postPostRenderDuringMovementEvent(RenderBlocks blockRenderer, int x, int y, int z, TileEntity entity, int pass) {
thePostRenderDuringMovementEvent.renderBlocks=blockRenderer;
thePostRenderDuringMovementEvent.x=x;
thePostRenderDuringMovementEvent.y=y;
thePostRenderDuringMovementEvent.z=z;
thePostRenderDuringMovementEvent.tile=entity;
thePostRenderDuringMovementEvent.pass=pass;
postEvent(thePostRenderDuringMovementEvent);
}

public static boolean postCancelableOnBlockAddedEvent(World worldObj, int x, int y, int z) {
theCancelableOnBlockAddedEvent.worldObj=worldObj;
theCancelableOnBlockAddedEvent.xCoord=x;
Expand Down Expand Up @@ -160,7 +134,7 @@ public static void postBlockRotateEvent(BlockRecord record, ForgeDirection forge
postEvent(theBlockRotateEvent);
}

private static void postEvent(Event e) {
static void postEvent(Event e) {
try {
eventPhase.set(e, null);
} catch (IllegalArgumentException e1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.planetguy.remaininmotion.core.interop;

import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.tileentity.TileEntity;
import me.planetguy.remaininmotion.api.event.PostRenderDuringMovementEvent;
import me.planetguy.remaininmotion.api.event.PreRenderDuringMovementEvent;

public class EventPoolClient {

private static PreRenderDuringMovementEvent thePreRenderDuringMovementEvent=new PreRenderDuringMovementEvent();
private static PostRenderDuringMovementEvent thePostRenderDuringMovementEvent=new PostRenderDuringMovementEvent();

public static boolean postPreRenderDuringMovementEvent(RenderBlocks blockRenderer, int x, int y, int z, TileEntity entity, int pass) {
thePreRenderDuringMovementEvent.renderBlocks=blockRenderer;
thePreRenderDuringMovementEvent.x=x;
thePreRenderDuringMovementEvent.y=y;
thePreRenderDuringMovementEvent.z=z;
thePreRenderDuringMovementEvent.tile=entity;
thePreRenderDuringMovementEvent.pass=pass;
EventPool.postEvent(thePreRenderDuringMovementEvent);
return thePreRenderDuringMovementEvent.isCanceled();
}

public static void postPostRenderDuringMovementEvent(RenderBlocks blockRenderer, int x, int y, int z, TileEntity entity, int pass) {
thePostRenderDuringMovementEvent.renderBlocks=blockRenderer;
thePostRenderDuringMovementEvent.x=x;
thePostRenderDuringMovementEvent.y=y;
thePostRenderDuringMovementEvent.z=z;
thePostRenderDuringMovementEvent.tile=entity;
thePostRenderDuringMovementEvent.pass=pass;
EventPool.postEvent(thePostRenderDuringMovementEvent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.planetguy.remaininmotion.api.RiMRegistry;
import me.planetguy.remaininmotion.api.event.PostRenderDuringMovementEvent;
import me.planetguy.remaininmotion.api.event.PreRenderDuringMovementEvent;
import me.planetguy.remaininmotion.core.interop.EventPool;
import me.planetguy.remaininmotion.core.interop.EventPoolClient;
import me.planetguy.remaininmotion.util.position.BlockPosition;
import me.planetguy.remaininmotion.util.position.BlockRecord;
import me.planetguy.remaininmotion.util.position.BlockRecordSet;
Expand Down Expand Up @@ -62,9 +62,9 @@ public static void Render(RenderBlocks blockRenderer, BlockRecordSet Blocks, Blo
}

try {
if(!EventPool.postPreRenderDuringMovementEvent(blockRenderer, Record.X, Record.Y, Record.Z, Record.entity, Pass))
if(!EventPoolClient.postPreRenderDuringMovementEvent(blockRenderer, Record.X, Record.Y, Record.Z, Record.entity, Pass))
blockRenderer.renderBlockByRenderType(Record.block, Record.X, Record.Y, Record.Z);
EventPool.postPostRenderDuringMovementEvent(blockRenderer, Record.X, Record.Y, Record.Z, Record.entity, Pass);
EventPoolClient.postPostRenderDuringMovementEvent(blockRenderer, Record.X, Record.Y, Record.Z, Record.entity, Pass);
} catch (Throwable Throwable) {
Throwable.printStackTrace();
}
Expand Down

0 comments on commit eb12caa

Please sign in to comment.