use of io.xol.chunkstories.api.events.EventHandler in project chunkstories by Hugobros3.
the class DefaultPluginManager method registerEventListener.
@Override
public void registerEventListener(Listener listener, ChunkStoriesPlugin plugin) {
System.out.println("Registering " + listener);
try {
// Get a list of all the classes methods
Set<Method> methods = new HashSet<Method>();
for (Method method : listener.getClass().getMethods()) methods.add(method);
for (Method method : listener.getClass().getDeclaredMethods()) methods.add(method);
// Filter it so only interested in @EventHandler annoted methods
for (final Method method : methods) {
EventHandler eventHandlerAnnotation = method.getAnnotation(EventHandler.class);
// We look for the annotation in the method
if (eventHandlerAnnotation == null)
continue;
// TODO something about priority
if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(method.getParameterTypes()[0])) {
logger().warn("Plugin " + plugin + " attempted to register an invalid EventHandler");
continue;
}
Class<? extends Event> parameter = method.getParameterTypes()[0].asSubclass(Event.class);
// Create an EventExecutor to launch the event code
EventExecutor executor = new EventExecutor() {
@Override
public void fireEvent(Event event) throws Exception {
method.invoke(listener, event);
}
};
RegisteredListener registeredListener = new RegisteredListener(listener, plugin, executor, eventHandlerAnnotation.priority());
// Get the listeners list for this event
Method getListeners = parameter.getMethod("getListenersStatic");
getListeners.setAccessible(true);
EventListeners thisEventKindOfListeners = (EventListeners) getListeners.invoke(null);
// Add our own to it
thisEventKindOfListeners.registerListener(registeredListener);
registeredEventListeners.put(thisEventKindOfListeners, registeredListener);
// Depending on the event configuration we may or may not care about the children events
if (eventHandlerAnnotation.listenToChildEvents() != EventHandler.ListenToChildEvents.NO)
addRegisteredListenerToEventChildren(thisEventKindOfListeners, registeredListener, eventHandlerAnnotation.listenToChildEvents() == EventHandler.ListenToChildEvents.RECURSIVE);
logger().info("Successuflly added EventHandler for " + parameter.getName() + "in " + listener + " of plugin " + plugin);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.xol.chunkstories.api.events.EventHandler in project chunkstories-core by Hugobros3.
the class RenderingEventsListener method onRenderPassesInitialization.
@EventHandler
public void onRenderPassesInitialization(RenderPassesInitEvent event) {
RenderPasses pipeline = event.getPasses();
WorldRenderer worldRenderer = pipeline.getWorldRenderer();
SkyRenderer sky = new DefaultSkyRenderer(event.getPasses().getRenderingInterface().getWorldRenderer());
worldRenderer.setSkyRenderer(sky);
SkyPass skyPass = new SkyPass(pipeline, "sky", worldRenderer.getSkyRenderer());
pipeline.registerRenderPass(skyPass);
// gbuffer uses the zBuffer and outputs albedo/normal/materials
GBuffersOpaquePass gBuffers = new GBuffersOpaquePass(pipeline, "gBuffers", new String[] { "sky.zBuffer!" }, new String[] { "albedoBuffer", "normalBuffer", "voxelLightBuffer", "specularityBuffer", "materialsBuffer" /*"zBuffer"*/
});
pipeline.registerRenderPass(gBuffers);
DecalsPass decals = new DecalsPass(pipeline, "decals", new String[] { "gBuffers.albedoBuffer!", "gBuffers.zBuffer" }, new String[] {});
pipeline.registerRenderPass(decals);
WaterPass waterPass = new WaterPass(pipeline, "water", new String[] { "decals.albedoBuffer", "gBuffers.normalBuffer", "gBuffers.voxelLightBuffer", "gBuffers.specularityBuffer", "gBuffers.materialsBuffer", "gBuffers.zBuffer" }, new String[] {/*"albedoBuffer", "normalBuffer", "voxelLightBuffer", "specularityBuffer", "materialsBuffer", "zBuffer"*/
}, sky);
pipeline.registerRenderPass(waterPass);
boolean shadows = client.getConfiguration().getBooleanOption("client.rendering.shadows");
// a shadowmap pass requires no previous buffer and just outputs a shadowmap
ShadowPass sunShadowPass = null;
if (shadows) {
sunShadowPass = new ShadowPass(pipeline, "shadowsSun", new String[] {}, new String[] { "shadowMap" }, sky);
// note we could generalize the shadowmappass to not only the sun but also the moon, point and spotlights
pipeline.registerRenderPass(sunShadowPass);
}
// aka shadows_apply in the current code, it takes the gbuffers and applies the shadowmapping to them, then outputs to the shaded pixels buffers already filled with the far terrain pixels
ApplySunlightPass applySunlight = new ApplySunlightPass(pipeline, "applySunlight", new String[] { "water.albedoBuffer", "water.normalBuffer", "water.voxelLightBuffer", "water.specularityBuffer", "water.materialsBuffer", "water.zBuffer", "sky.shadedBuffer!" }, new String[] {/*"shadedBuffer"*/
}, sunShadowPass);
if (shadows)
applySunlight.requires.add("shadowsSun.shadowMap");
pipeline.registerRenderPass(applySunlight);
boolean gi = client.getConfiguration().getBooleanOption("client.rendering.globalIllumination") && shadows;
if (gi) {
GiPass giPass = new GiPass(pipeline, "gi", new String[] { "water.albedoBuffer", "water.normalBuffer", "water.zBuffer" }, new String[] { "giBuffer" }, sunShadowPass);
pipeline.registerRenderPass(giPass);
}
DefferedLightsPass lightsPass = new DefferedLightsPass(pipeline, "lights", new String[] { "applySunlight.shadedBuffer!", "water.albedoBuffer", "water.normalBuffer", "water.zBuffer" }, new String[] {});
pipeline.registerRenderPass(lightsPass);
// far terrain needs the shaded buffer from sky and outputs it, as well with a zbuffer
FarTerrainPass farTerrain = new FarTerrainPass(pipeline, "farTerrain", new String[] { "lights.shadedBuffer!", "gBuffers.specularityBuffer!", "gBuffers.zBuffer!" }, new String[] {/*"shadedBuffer", "zBuffer", "specularityBuffer"*/
});
pipeline.registerRenderPass(farTerrain);
BloomPass bloomPass = new BloomPass(pipeline, "bloom", new String[] { "farTerrain.shadedBuffer" }, new String[] { "bloomBuffer" });
pipeline.registerRenderPass(bloomPass);
ForwardPass forward = new ForwardPass(pipeline, "forward", new String[] { "farTerrain.shadedBuffer!", "farTerrain.zBuffer!" }, new String[] {});
pipeline.registerRenderPass(forward);
ReflectionsPass reflections = new ReflectionsPass(pipeline, "reflections", new String[] { "farTerrain.shadedBuffer", "gBuffers.normalBuffer", "gBuffers.voxelLightBuffer", "farTerrain.specularityBuffer", "farTerrain.zBuffer" }, new String[] { "reflectionsBuffer" }, sky);
pipeline.registerRenderPass(reflections);
// the pass declared as 'final' is considered the last one and it's outputs are shown to the screen
PostProcessPass postprocess = new PostProcessPass(pipeline, "final", new String[] { "water.albedoBuffer", "forward.shadedBuffer", "farTerrain.zBuffer", "bloom.bloomBuffer", "reflections.reflectionsBuffer", "farTerrain.specularityBuffer" }, sunShadowPass);
if (gi)
postprocess.requires.add("gi.giBuffer");
pipeline.registerRenderPass(postprocess);
}
use of io.xol.chunkstories.api.events.EventHandler in project chunkstories-core by Hugobros3.
the class ItemsLogicListener method onDroppedItem.
@EventHandler
public void onDroppedItem(EventItemDroppedToWorld event) {
// Create an EntityGroundItem and add it to the event
Location throwLocation = event.getLocation();
Vector3d throwForce = new Vector3d(0.0);
// Throw it when dropping it from a player's inventory ?
System.out.println(event.getInventoryFrom());
if (event.getInventoryFrom() != null && event.getInventoryFrom().getHolder() != null && event.getInventoryFrom().getHolder() instanceof Entity) {
System.out.println("from som 1");
EntityWithInventory entity = ((EntityWithInventory) event.getInventoryFrom().getHolder());
Location pos = entity.getLocation();
if (entity instanceof EntityLiving) {
System.out.println("he l i v e s");
EntityLiving owner = (EntityLiving) entity;
throwLocation = new Location(pos.getWorld(), pos.x(), pos.y() + ((EntityPlayer) owner).eyePosition, pos.z());
throwForce = new Vector3d(((EntityPlayer) owner).getDirectionLookingAt()).mul(0.15 - Math2.clampd(((EntityPlayer) owner).getEntityRotationComponent().getVerticalRotation(), -45, 20) / 45f * 0.0f);
throwForce.add(((EntityPlayer) owner).getVelocityComponent().getVelocity());
}
}
EntityGroundItem thrownItem = (EntityGroundItem) core.getPluginExecutionContext().getContent().entities().getEntityDefinition("groundItem").create(throwLocation);
thrownItem.positionComponent.setPosition(throwLocation);
thrownItem.velocityComponent.setVelocity(throwForce);
thrownItem.setItemPile(event.getItemPile());
// EntityGroundItem entity = new EntityGroundItem(core.getPluginExecutionContext().getContent().entities().getEntityDefinitionByName("groundItem"), event.getLocation(), event.getItemPile());
event.setItemEntity(thrownItem);
}
Aggregations