use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator 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.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.
the class BlockBase method breakBlock.
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
ListenerIterator it = new ListenerIterator(world, x, y, z, this, "break");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof IBlockListener) {
((IDestroyedListener) next).breakBlock(block, par6);
}
}
super.breakBlock(world, x, y, z, block, par6);
}
use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.
the class BlockBase method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
try {
boolean activated = false;
Object tile = getTile(world, x, y, z);
if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x, y, z)) {
ListenerIterator it = new ListenerIterator(world, x, y, z, this, "wrench");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof IWrenchListener && ((IWrenchListener) next).handlesWrenchRightClick() && ((IWrenchListener) next).onPlayerRightClickWrench(player, side, hitX, hitY, hitZ)) {
activated = true;
}
}
if (activated) {
WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x, y, z);
}
if (activated) {
return true;
}
}
//TODO move to listener to prevent usage of IGuiTile in special cases
if (tile instanceof IGuiTile && ((IGuiTile) tile).shouldOpenOnRightClick(player)) {
int id = ((IGuiTile) tile).getDefaultGuiID(player);
if (id >= 0) {
Object o = ((IGuiTile) tile).getServerGuiElement(id, player);
if (o != null) {
player.openGui(mod, id, world, x, y, z);
return true;
}
}
}
ListenerIterator it = new ListenerIterator(world, x, y, z, this, "activation");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof IActivationListener) {
if (((IActivationListener) next).onPlayerActivated(player, side, hitX, hitY, hitZ)) {
activated = true;
}
}
}
return activated;
} catch (Exception e) {
outputError(world, x, y, z, "while right click block on side " + side, e);
player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + LanguageUtility.getLocal("blockTile.error.onBlockActivated")));
}
return false;
}
use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.
the class BlockBase method addCollisionBoxesToList.
@Override
@SuppressWarnings("unchecked")
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
ListenerIterator it = new ListenerIterator(world, x, y, z, this, "bounds");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof IBoundListener) {
List collect = new ArrayList();
((IBoundListener) next).addCollisionBoxesToList(aabb, collect, entity);
for (Object object : list) {
if (object instanceof AxisAlignedBB && aabb.intersectsWith((AxisAlignedBB) object)) {
list.add(object);
}
}
}
}
}
use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.
the class BlockBase method getDrops.
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> items = super.getDrops(world, x, y, z, metadata, fortune);
ListenerIterator it = new ListenerIterator(world, x, y, z, this, "blockStack");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof IBlockStackListener) {
((IBlockStackListener) next).collectDrops(items, metadata, fortune);
}
}
return items;
}
Aggregations