Fixes #221 and hides the multiblock when the world is closed.

This commit is contained in:
Modmuss50 2015-11-02 15:14:54 +00:00
parent cc49f03ee5
commit 65d20ec431
3 changed files with 64 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import techreborn.client.container.ContainerBlastFurnace;
import techreborn.client.multiblock.Multiblock;
import techreborn.client.multiblock.MultiblockSet;
import techreborn.init.ModBlocks;
import techreborn.lib.Location;
import techreborn.lib.ModInfo;
import techreborn.proxies.ClientProxy;
import techreborn.tiles.TileBlastFurnace;
@ -41,6 +42,10 @@ public class GuiBlastFurnace extends GuiContainer {
GuiButton button = new GuiButton(212, k + 4, l + 6, 20, 20, "");
buttonList.add(button);
super.initGui();
ChunkCoordinates coordinates = new ChunkCoordinates(blastfurnace.xCoord - (ForgeDirection.getOrientation(blastfurnace.getRotation()).offsetX * 2), blastfurnace.yCoord - 1, blastfurnace.zCoord - (ForgeDirection.getOrientation(blastfurnace.getRotation()).offsetZ * 2));
if(coordinates.equals(ClientProxy.multiblockRenderEvent.anchor) && blastfurnace.getHeat() != 0){
ClientProxy.multiblockRenderEvent.setMultiblock(null);
}
}
@Override
@ -125,6 +130,7 @@ public class GuiBlastFurnace extends GuiContainer {
MultiblockSet set = new MultiblockSet(multiblock);
ClientProxy.multiblockRenderEvent.setMultiblock(set);
ClientProxy.multiblockRenderEvent.partent = new Location(blastfurnace.xCoord, blastfurnace.yCoord, blastfurnace.zCoord, blastfurnace.getWorldObj());
ClientProxy.multiblockRenderEvent.anchor = new ChunkCoordinates(blastfurnace.xCoord - (ForgeDirection.getOrientation(blastfurnace.getRotation()).offsetX * 2), blastfurnace.yCoord - 1, blastfurnace.zCoord - (ForgeDirection.getOrientation(blastfurnace.getRotation()).offsetZ * 2));
}
button.displayString = "A";

View file

@ -12,6 +12,7 @@ package techreborn.client.render;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
@ -27,11 +28,14 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.WorldEvent;
import org.lwjgl.opengl.GL11;
import techreborn.client.multiblock.IMultiblockRenderHook;
import techreborn.client.multiblock.Multiblock;
import techreborn.client.multiblock.MultiblockSet;
import techreborn.client.multiblock.component.MultiblockComponent;
import techreborn.lib.Location;
public class MultiblockRenderEvent {
public static boolean rendering = false;
@ -39,12 +43,14 @@ public class MultiblockRenderEvent {
private static RenderBlocks blockRender = RenderBlocks.getInstance();
public MultiblockSet currentMultiblock;
public static ChunkCoordinates anchor;
public Location partent;
public static int angle;
public void setMultiblock(MultiblockSet set) {
currentMultiblock = set;
anchor = null;
angle = 0;
partent = null;
}
@SubscribeEvent
@ -92,6 +98,9 @@ public class MultiblockRenderEvent {
int y = pos.posY + anchorY;
int z = pos.posZ + anchorZ;
if(!world.isAirBlock(x, y, z))
return false;
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
@ -109,4 +118,18 @@ public class MultiblockRenderEvent {
GL11.glPopMatrix();
return true;
}
@SubscribeEvent
public void breakBlock(BlockEvent.BreakEvent event){
if(partent != null){
if(event.x == partent.x && event.y == partent.y && event.z == partent.z && Minecraft.getMinecraft().theWorld == partent.world){
setMultiblock(null);
}
}
}
@SubscribeEvent
public void worldUnloaded(WorldEvent.Unload event){
setMultiblock(null);
}
}

View file

@ -12,6 +12,7 @@ public class Location implements Comparable<Location> {
public int y;
public int z;
public int depth;
public World world;
public Location(int x, int y, int z) {
this.x = x;
@ -26,6 +27,21 @@ public class Location implements Comparable<Location> {
this.depth = depth;
}
public Location(int x, int y, int z, int depth, World world) {
this.x = x;
this.y = y;
this.z = z;
this.depth = depth;
this.world = world;
}
public Location(int x, int y, int z, World world) {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
}
public Location(int xCoord, int yCoord, int zCoord, ForgeDirection dir) {
this.x = xCoord + dir.offsetX;
this.y = yCoord + dir.offsetY;
@ -253,4 +269,23 @@ public class Location implements Comparable<Location> {
public int compareTo(Location o) {
return ((Integer) depth).compareTo(o.depth);
}
public World getWorld() {
return world;
}
public void setWorld(World world) {
this.world = world;
}
@Override
public String toString() {
return "Location{" +
"x=" + x +
", y=" + y +
", z=" + z +
", depth=" + depth +
", world=" + world +
'}';
}
}