Added Network Tool Facade Transparency Option.

This commit is contained in:
AlgorithmX2 2014-08-02 23:53:34 -05:00
parent 06856eb957
commit c45d7f1b71
15 changed files with 257 additions and 34 deletions

View file

@ -33,6 +33,7 @@ import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.opengl.GL11;
import appeng.api.parts.CableRenderMode;
import appeng.api.util.AEColor;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
@ -72,6 +73,36 @@ public class ClientHelper extends ServerHelper
private static RenderItem itemRenderer = new RenderItem();
private static RenderBlocks blockRenderer = new RenderBlocks();
@Override
public CableRenderMode getRenderMode()
{
if ( Platform.isServer() )
return super.getRenderMode();
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
return renderModeForPlayer( player );
}
@Override
public void triggerUpdates()
{
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
if ( player == null )
return;
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
int range = 16 * 16;
mc.theWorld.markBlockRangeForRenderUpdate( x - range, y - range, z - range, x + range, y + range, z + range );
}
@SubscribeEvent
public void postPlayerRender(RenderLivingEvent.Pre p)
{

View file

@ -1,19 +1,54 @@
package appeng.client.gui.implementations;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiToggleButton;
import appeng.container.implementations.ContainerNetworkTool;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
public class GuiNetworkTool extends AEBaseGui
{
GuiToggleButton tFacades;
public GuiNetworkTool(InventoryPlayer inventoryPlayer, INetworkTool te) {
super( new ContainerNetworkTool( inventoryPlayer, te ) );
this.ySize = 166;
}
@Override
protected void actionPerformed(GuiButton btn)
{
super.actionPerformed( btn );
try
{
if ( btn == tFacades )
NetworkHandler.instance.sendToServer( new PacketValueConfig( "NetworkTool", "Toggle" ) );
}
catch (IOException e)
{
AELog.error( e );
}
}
@Override
public void initGui()
{
super.initGui();
tFacades = new GuiToggleButton( this.guiLeft - 18, guiTop + 8, 23, 22, GuiText.TransparentFacades.getLocal(), GuiText.TransparentFacadesHint.getLocal() );
buttonList.add( tFacades );
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
@ -24,6 +59,9 @@ public class GuiNetworkTool extends AEBaseGui
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
if ( tFacades != null )
tFacades.setState( ((ContainerNetworkTool) inventorySlots).facadeMode );
fontRendererObj.drawString( getGuiDisplayName( GuiText.NetworkTool.getLocal() ), 8, 6, 4210752 );
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
}

View file

@ -234,7 +234,7 @@ public class RenderBlocksWorkaround extends RenderBlocks
brightnessBottomRight = z[1];
brightnessTopLeft = z[2];
brightnessTopRight = z[3];
Tessellator.instance.setColorOpaque_I( z[4] );
Tessellator.instance.setColorRGBA_I( z[4], (int) (opacity * 255) );
colorRedTopLeft = c[0];
colorGreenTopLeft = c[1];
@ -430,7 +430,7 @@ public class RenderBlocksWorkaround extends RenderBlocks
int out = (high << 16) | low;
Tessellator.instance.setColorOpaque_F( r, g, b );
Tessellator.instance.setColorRGBA_F( r, g, b, opacity );
Tessellator.instance.setBrightness( out );
}
@ -657,6 +657,7 @@ public class RenderBlocksWorkaround extends RenderBlocks
}
int lightHashTmp[] = new int[27];
public float opacity = 1.0f;
private int getLightingHash(Block blk, IBlockAccess w, int x, int y, int z)
{

View file

@ -2,8 +2,10 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.util.Platform;
@ -13,6 +15,9 @@ public class ContainerNetworkTool extends AEBaseContainer
INetworkTool toolInv;
@GuiSync(1)
public boolean facadeMode;
public ContainerNetworkTool(InventoryPlayer ip, INetworkTool te) {
super( ip, null, null );
toolInv = te;
@ -26,6 +31,13 @@ public class ContainerNetworkTool extends AEBaseContainer
bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 );
}
public void toggleFacadeMode()
{
NBTTagCompound data = Platform.openNbtData( toolInv.getItemStack() );
data.setBoolean( "hideFacades", !data.getBoolean( "hideFacades" ) );
this.detectAndSendChanges();
}
@Override
public void detectAndSendChanges()
{
@ -36,7 +48,9 @@ public class ContainerNetworkTool extends AEBaseContainer
if ( currentItem != null )
{
if ( Platform.isSameItem( toolInv.getItemStack(), currentItem ) )
{
getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, toolInv.getItemStack() );
}
else
isContainerValid = false;
}
@ -44,6 +58,12 @@ public class ContainerNetworkTool extends AEBaseContainer
isContainerValid = false;
}
if ( isContainerValid )
{
NBTTagCompound data = Platform.openNbtData( currentItem );
facadeMode = data.getBoolean( "hideFacades" );
}
super.detectAndSendChanges();
}
}

View file

@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import appeng.api.parts.CableRenderMode;
import appeng.block.AEBaseBlock;
import appeng.client.EffectType;
import appeng.core.sync.AppEngPacket;
@ -38,9 +39,10 @@ public abstract class CommonHelper
public abstract void postinit();
{
// TODO Auto-generated method stub
}
public abstract CableRenderMode getRenderMode();
public abstract void triggerUpdates();
public abstract void updateRenderMode(EntityPlayer player);
}

View file

@ -23,12 +23,14 @@ import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import appeng.api.parts.CableRenderMode;
import appeng.api.parts.IPartHelper;
import appeng.api.parts.IPartItem;
import appeng.api.parts.LayerBase;
import appeng.client.render.BusRenderer;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.CommonHelper;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IFMP;
import appeng.parts.PartPlacement;
@ -345,4 +347,10 @@ public class ApiPart implements IPartHelper
return false;
}
@Override
public CableRenderMode getCableRenderMode()
{
return CommonHelper.proxy.getRenderMode();
}
}

View file

@ -24,15 +24,29 @@ public enum GuiText
CraftingTerminal, FormationPlane, Inscriber, QuartzCuttingKnife,
METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, StoredSize,
METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel,
CopyMode, CopyModeDesc, PatternTerminal, CraftingPattern, ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler,
StoredSize, CopyMode, CopyModeDesc, PatternTerminal, CraftingPattern,
StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurificationCertus, inWorldPurificationNether, inWorldPurificationFluix, inWorldSingularity, ChargedQuartz,
ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler,
OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting,
StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting,
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean, InvalidPattern, InterfaceTerminalHint, Range;
inWorldFluix, inWorldPurificationCertus, inWorldPurificationNether,
inWorldPurificationFluix, inWorldSingularity, ChargedQuartz, OfSecondOutput,
NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty,
ConfirmCrafting, Stored, Crafting, Scheduled, CraftingStatus, Cancel,
FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes,
CraftingCPU, Automatic, CoProcessors, Simulation, Missing,
InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean, InvalidPattern,
InterfaceTerminalHint, Range, TransparentFacades, TransparentFacadesHint;
String root;

View file

@ -7,6 +7,7 @@ import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.parts.PartPlacement;
@ -28,7 +29,9 @@ public class PacketPartPlacement extends AppEngPacket
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
CommonHelper.proxy.updateRenderMode( sender );
PartPlacement.place( sender.getHeldItem(), x, y, z, face, sender, sender.worldObj, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
CommonHelper.proxy.updateRenderMode( null );
}
// api

View file

@ -20,6 +20,7 @@ import appeng.container.implementations.ContainerCellWorkbench;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerCraftingCPU;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerNetworkTool;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.implementations.ContainerPriority;
import appeng.container.implementations.ContainerQuartzKnife;
@ -151,6 +152,13 @@ public class PacketValueConfig extends AppEngPacket
ccw.setFuzzy( FuzzyMode.valueOf( Value ) );
}
}
else if ( c instanceof ContainerNetworkTool )
{
if ( Name.equals( "NetworkTool" ) && Value.equals( "Toggle" ) )
{
((ContainerNetworkTool) c).toggleFacadeMode();
}
}
else if ( c instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) c).getConfigManager();

View file

@ -5,6 +5,8 @@ import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@ -16,6 +18,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import appeng.api.AEApi;
import appeng.api.parts.IFacadeContainer;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPartCollsionHelper;
@ -52,11 +55,19 @@ public class FacadePart implements IFacadePart
}
@Override
public void getBoxes(IPartCollsionHelper ch)
public void getBoxes(IPartCollsionHelper ch, Entity e)
{
if ( e instanceof EntityLivingBase )
{
// prevent weird snagg behavior
ch.addBox( 0.0, 0.0, 14, 16.0, 16.0, 16.0 );
}
else
{
// the box is 15.9 for transition planes to pick up collision events.
ch.addBox( 0.0, 0.0, 14, 16.0, 16.0, 15.9 );
}
}
public static boolean isFacade(ItemStack is)
{
@ -136,10 +147,19 @@ public class FacadePart implements IFacadePart
ItemBlock ib = (ItemBlock) randomItem.getItem();
Block blk = Block.getBlockFromItem( ib );
if ( AEApi.instance().partHelper().getCableRenderMode().transparentFacades )
{
if ( rbw != null )
rbw.opacity = 0.3f;
instance.renderForPass( 1 );
}
else
{
if ( blk.canRenderInPass( 1 ) )
{
instance.renderForPass( 1 );
}
}
int color = 0xffffff;
@ -265,6 +285,7 @@ public class FacadePart implements IFacadePart
if ( rbw != null )
{
rbw.opacity = 1.0f;
rbw.faces = EnumSet.allOf( ForgeDirection.class );
}
@ -505,6 +526,9 @@ public class FacadePart implements IFacadePart
@Override
public boolean isTransparent()
{
if ( AEApi.instance().partHelper().getCableRenderMode().transparentFacades )
return true;
ItemStack is = getTexture();
Block blk = Block.getBlockFromItem( is.getItem() );
if ( !blk.isOpaqueCube() )

View file

@ -311,7 +311,7 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
{
List<AxisAlignedBB> boxes = new ArrayList();
IPartCollsionHelper bch = new BusCollisionHelper( boxes, side, null, true );
fp.getBoxes( bch );
fp.getBoxes( bch, null );
for (AxisAlignedBB bb : boxes)
{
disableFacadeOcclusion.set( true );

View file

@ -11,9 +11,12 @@ import java.util.concurrent.Callable;
import net.minecraft.world.World;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
import appeng.api.AEApi;
import appeng.api.networking.IGridNode;
import appeng.api.parts.CableRenderMode;
import appeng.api.util.AEColor;
import appeng.core.AELog;
import appeng.core.CommonHelper;
import appeng.core.sync.packets.PacketPaintedEntity;
import appeng.crafting.CraftingJob;
import appeng.entity.EntityFloatingItem;
@ -181,6 +184,8 @@ public class TickHandler
}
}
CableRenderMode crm = CableRenderMode.Standard;
@SubscribeEvent
public void onTick(TickEvent ev)
{
@ -189,6 +194,12 @@ public class TickHandler
{
tickColors( cliPlayerColors );
EntityFloatingItem.ageStatic = (EntityFloatingItem.ageStatic + 1) % 60000;
CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
if ( currentMode != crm )
{
crm = currentMode;
CommonHelper.proxy.triggerUpdates();
}
}
// rwar!

View file

@ -447,11 +447,14 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
part.getBoxes( bch );
}
if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades || !visual )
{
if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN )
{
IFacadePart fp = fc.getFacade( s );
if ( fp != null )
fp.getBoxes( bch );
fp.getBoxes( bch, e );
}
}
}
@ -844,6 +847,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
}
}
if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades )
{
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
IFacadePart p = fc.getFacade( side );
@ -852,7 +857,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
List<AxisAlignedBB> boxes = new LinkedList<AxisAlignedBB>();
IPartCollsionHelper bch = new BusCollisionHelper( boxes, side, null, true );
p.getBoxes( bch );
p.getBoxes( bch, null );
for (AxisAlignedBB bb : boxes)
{
bb = bb.expand( 0.01, 0.01, 0.01 );
@ -863,6 +868,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
}
}
}
}
return new SelectedPart();
}

View file

@ -27,6 +27,7 @@ import appeng.api.parts.PartItemStack;
import appeng.api.parts.SelectedPart;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.CommonHelper;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketClick;
import appeng.core.sync.packets.PacketPartPlacement;
@ -137,7 +138,7 @@ public class PartPlacement
if ( mop != null )
{
List<ItemStack> is = new LinkedList();
SelectedPart sp = host.selectPart( mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
SelectedPart sp = selectPart( player, host, mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
if ( sp.part != null )
{
@ -247,7 +248,7 @@ public class PartPlacement
if ( mop != null )
{
mop.hitVec = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ );
SelectedPart sPart = host.selectPart( mop.hitVec );
SelectedPart sPart = selectPart( player, host, mop.hitVec );
if ( sPart != null && sPart.part != null )
if ( sPart.part.onShiftActivate( player, mop.hitVec ) )
{
@ -364,7 +365,7 @@ public class PartPlacement
MovingObjectPosition mop = block.collisionRayTrace( world, x, y, z, dir.a, dir.b );
if ( mop != null )
{
SelectedPart sp = host.selectPart( mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
SelectedPart sp = selectPart( player, host, mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
if ( sp.part != null )
{
@ -407,6 +408,15 @@ public class PartPlacement
return true;
}
private static SelectedPart selectPart(EntityPlayer player, IPartHost host, Vec3 pos)
{
CommonHelper.proxy.updateRenderMode( player );
SelectedPart sp = host.selectPart( pos );
CommonHelper.proxy.updateRenderMode( null );
return sp;
}
public static IFacadePart isFacade(ItemStack held, ForgeDirection side)
{
if ( held.getItem() instanceof IFacadeItem )

View file

@ -6,15 +6,19 @@ import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import appeng.api.parts.CableRenderMode;
import appeng.block.AEBaseBlock;
import appeng.client.EffectType;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.NetworkHandler;
import appeng.items.tools.ToolNetworkTool;
import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
@ -107,4 +111,47 @@ public class ServerHelper extends CommonHelper
return null;
}
@Override
public CableRenderMode getRenderMode()
{
if ( renderModeBased == null )
return CableRenderMode.Standard;
return renderModeForPlayer( renderModeBased );
}
private EntityPlayer renderModeBased;
@Override
public void updateRenderMode(EntityPlayer player)
{
renderModeBased = player;
}
protected CableRenderMode renderModeForPlayer(EntityPlayer player)
{
if ( player != null )
{
for (int x = 0; x < InventoryPlayer.getHotbarSize(); x++)
{
ItemStack is = player.inventory.getStackInSlot( x );
if ( is != null && is.getItem() instanceof ToolNetworkTool )
{
NBTTagCompound c = is.getTagCompound();
if ( c != null && c.getBoolean( "hideFacades" ) )
return CableRenderMode.CableView;
}
}
}
return CableRenderMode.Standard;
}
@Override
public void triggerUpdates()
{
}
}