use of com.builtbroken.mc.api.tile.listeners.ITileEventListener in project Engine by VoltzEngine-Project.
the class JsonBlockListenerProcessor method process.
@Override
public void process(BlockBase block, JsonElement arrayElement, List<IJsonGenObject> objectList) {
JsonArray array = arrayElement.getAsJsonArray();
for (JsonElement element : array) {
String key = null;
JsonObject data = null;
if (element.isJsonPrimitive()) {
key = element.getAsString().toLowerCase();
} else if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
JsonProcessor.ensureValuesExist(object, "id");
key = object.get("id").getAsString().toLowerCase();
data = object;
}
if (builders.containsKey(key)) {
ITileEventListener listener = builders.get(key).createListener(block);
if (listener != null) {
if (data != null) {
if (!injectionMaps.containsKey(listener.getClass())) {
injectionMaps.put(listener.getClass(), new JsonProcessorInjectionMap(listener.getClass()));
}
JsonProcessorInjectionMap injectionMap = injectionMaps.get(listener.getClass());
for (Map.Entry<String, JsonElement> entry : data.entrySet()) {
injectionMap.handle(listener, entry.getKey(), entry.getValue());
}
}
block.addListener(listener);
}
}
}
}
use of com.builtbroken.mc.api.tile.listeners.ITileEventListener in project Engine by VoltzEngine-Project.
the class TileRenderHandler method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) {
GL11.glPushMatrix();
try {
GL11.glTranslated(x + 0.5, y, z + 0.5);
RenderData data = getRenderData(tile);
if (data != null && data.renderType.equalsIgnoreCase("tile")) {
//Try to get tile specific state
String key = getRenderStateKey(tile);
//Loop default keys
for (String de : new String[] { key, "tile", "entity", "item.entity" }) {
if (de != null) {
IRenderState state = data.getState(de);
if (state instanceof IModelState && ((IModelState) state).render(false)) {
break;
}
}
}
}
} catch (Exception e) {
Engine.logger().error("TileRenderHandler: Error rendering " + tile, e);
}
GL11.glPopMatrix();
//If BlockBase, iterate listeners
if (tile.getBlockType() instanceof BlockBase) {
ListenerIterator it = new ListenerIterator(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, (BlockBase) tile.getBlockType(), "tilerender");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof ITileRenderListener) {
GL11.glPushMatrix();
try {
((ITileRenderListener) next).renderDynamic(tile, x, y, z, f);
} catch (Exception e) {
Engine.logger().error("TileRenderHandler: Error calling listener[" + next + "] for Tile[" + tile + "]", e);
}
GL11.glPopMatrix();
}
}
}
}
use of com.builtbroken.mc.api.tile.listeners.ITileEventListener in project Engine by VoltzEngine-Project.
the class TileEntityWrapper method updateEntity.
/**
* TILE, Called by the world to update the tile. Never
* call this from your owner code. Use Update() method
* as this is set final to ensure base functionality.
*/
@Override
public final void updateEntity() {
//Ticks listeners that require updates
for (List<ITileEventListener> list : new List[] { getListeners("multiblock"), ((BlockBase) getBlockType()).listeners.get("multiblock") }) {
if (list != null && !list.isEmpty()) {
for (ITileEventListener listener : list) {
if (listener instanceof IUpdateListener) {
try {
if (listener instanceof IBlockListener) {
((IBlockListener) listener).inject(world(), xi(), yi(), zi());
}
((IUpdateListener) listener).update(ticks);
} catch (Exception e) {
Engine.logger().error("Unexpected exception while calling first tick on " + tile + "\nWrapper:" + this, e);
}
}
}
}
}
//Ticks node
if (ticks == 0) {
try {
tile.firstTick();
} catch (Exception e) {
Engine.logger().error("Unexpected exception while calling first tick on " + tile + "\nWrapper:" + this, e);
}
} else {
try {
tile.update(ticks);
} catch (Exception e) {
Engine.logger().error("Unexpected exception while ticking " + tile + "\nTick:" + ticks + "\nWrapper:" + this, e);
}
}
//Increase tick
if (ticks >= Long.MAX_VALUE) {
ticks = 0;
}
ticks += 1;
if (ticks % nextCleanupTick == 0) {
tile.doCleanupCheck();
nextCleanupTick = tile.getNextCleanupTick();
}
if (playersUsing.size() > 0) {
//tile.doUpdateGuiUsers();
}
}
use of com.builtbroken.mc.api.tile.listeners.ITileEventListener in project Engine by VoltzEngine-Project.
the class ClientProxy method postInit.
@Override
public void postInit() {
super.postInit();
//Item that uses a model for all states
registerItemJsonRenders(new ItemJsonRenderer(), "VE-Item", "item", "tile", "block");
List<IJsonGenObject> objects = JsonContentLoader.INSTANCE.generatedObjects.get(JsonBlockProcessor.KEY);
if (objects != null && !objects.isEmpty()) {
for (IJsonGenObject object : objects) {
if (object instanceof BlockBase) {
List<ITileEventListener> listeners = ((BlockBase) object).listeners.get("placement");
if (listeners != null && !listeners.isEmpty()) {
for (ITileEventListener listener : listeners) {
if (listener instanceof RotatableListener) {
((BlockBase) object).addListener(new RotatableIconListener((BlockBase) object));
break;
}
}
}
}
}
}
}
Aggregations