Merge branch 'Prototik-transparent-facades' into 6.1.x

This commit is contained in:
SpaceToad 2014-05-18 17:07:44 +02:00
commit 2b532f7f66
9 changed files with 81 additions and 52 deletions

View file

@ -173,7 +173,8 @@ item.PipeFluidsSandstone.name=Sandstone Fluid Pipe
item.Facade.name=Facade
item.FacadePhased.name=Phased Facade
item.FacadePhased.state=%s: %s
item.FacadePhase.state_default=Default: %s
item.FacadePhased.state_default=Default: %s
item.FacadePhased.state_transparent=Transparent
item.PipePlug.name=Pipe Plug
itemGroup.buildcraft.blocks=Buildcraft Blocks

View file

@ -34,7 +34,8 @@ public class AdvancedFacadeRecipe implements IIntegrationRecipeManager.IIntegrat
@Override
public boolean isValidInputB(ItemStack inputB) {
return inputB != null && inputB.getItem() instanceof ItemFacade && ItemFacade.getType(inputB) == ItemFacade.FacadeType.Basic;
return inputB != null && (inputB.getItem() instanceof ItemFacade && ItemFacade.getType(inputB) == ItemFacade.FacadeType.Basic ||
inputB.getItem() == BuildCraftTransport.plugItem);
}
@Override
@ -57,21 +58,24 @@ public class AdvancedFacadeRecipe implements IIntegrationRecipeManager.IIntegrat
}
if (wire != null) {
ItemFacade.FacadeState[] statesA = ItemFacade.getFacadeStates(inputA),
statesB = ItemFacade.getFacadeStates(inputB);
ItemFacade.FacadeState[] states = ItemFacade.getFacadeStates(inputA);
ItemFacade.FacadeState additionalState;
if (inputB.getItem() == BuildCraftTransport.plugItem) {
additionalState = ItemFacade.FacadeState.createTransparent(wire);
} else {
additionalState = ItemFacade.getFacadeStates(inputB)[0];
additionalState = ItemFacade.FacadeState.create(additionalState.block, additionalState.metadata, wire);
}
ItemFacade.FacadeState additionalState = statesB[0];
additionalState = new ItemFacade.FacadeState(additionalState.block, additionalState.metadata, wire);
// if in statesA exists state with the same wire just override it
for (int i = 0; i < statesA.length; i++) {
if (statesA[i].wire == wire) {
statesA[i] = additionalState;
return ItemFacade.getFacade(statesA);
// if in states array exists state with the same wire just override it
for (int i = 0; i < states.length; i++) {
if (states[i].wire == wire) {
states[i] = additionalState;
return ItemFacade.getFacade(states);
}
}
// otherwise concat all states into one facade
return ItemFacade.getFacade(JavaTools.concat(statesA, new ItemFacade.FacadeState[] {additionalState}));
return ItemFacade.getFacade(JavaTools.concat(states, new ItemFacade.FacadeState[] {additionalState}));
} else {
return null;
}

View file

@ -227,32 +227,32 @@ public class BlockGenericPipe extends BlockBuildCraft {
float facadeThickness = TransportConstants.FACADE_THICKNESS;
if (tileG.hasFacade(ForgeDirection.EAST)) {
if (tileG.hasEnabledFacade(ForgeDirection.EAST)) {
setBlockBounds(1 - facadeThickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.WEST)) {
if (tileG.hasEnabledFacade(ForgeDirection.WEST)) {
setBlockBounds(0.0F, 0.0F, 0.0F, facadeThickness, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.UP)) {
if (tileG.hasEnabledFacade(ForgeDirection.UP)) {
setBlockBounds(0.0F, 1 - facadeThickness, 0.0F, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.DOWN)) {
if (tileG.hasEnabledFacade(ForgeDirection.DOWN)) {
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, facadeThickness, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.SOUTH)) {
if (tileG.hasEnabledFacade(ForgeDirection.SOUTH)) {
setBlockBounds(0.0F, 0.0F, 1 - facadeThickness, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.hasFacade(ForgeDirection.NORTH)) {
if (tileG.hasEnabledFacade(ForgeDirection.NORTH)) {
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, facadeThickness);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}

View file

@ -51,22 +51,28 @@ public class ItemFacade extends ItemBuildCraft {
public static class FacadeState {
public final Block block;
public final int metadata;
public final boolean transparent;
public final PipeWire wire;
public FacadeState(Block block, int metadata, PipeWire wire) {
this.block = block;
this.metadata = metadata;
this.wire = wire;
this.transparent = false;
}
public FacadeState(NBTTagCompound nbt) {
block = (Block) Block.blockRegistry.getObject(nbt.getString("block"));
metadata = nbt.getInteger("metadata");
if (nbt.hasKey("wire")) {
wire = PipeWire.fromOrdinal(nbt.getInteger("wire"));
} else {
wire = null;
}
this.block = nbt.hasKey("block") ? (Block) Block.blockRegistry.getObject(nbt.getString("block")) : null;
this.metadata = nbt.getInteger("metadata");
this.wire = nbt.hasKey("wire") ? PipeWire.fromOrdinal(nbt.getInteger("wire")) : null;
this.transparent = nbt.hasKey("transparent") && nbt.getBoolean("transparent");
}
private FacadeState(PipeWire wire) {
this.block = null;
this.metadata = 0;
this.wire = wire;
this.transparent = true;
}
public static FacadeState create(Block block, int metadata) {
@ -77,12 +83,19 @@ public class ItemFacade extends ItemBuildCraft {
return new FacadeState(block, metadata, wire);
}
public static FacadeState createTransparent(PipeWire wire) {
return new FacadeState(wire);
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setString("block", Block.blockRegistry.getNameForObject(block));
if (block != null) {
nbt.setString("block", Block.blockRegistry.getNameForObject(block));
}
nbt.setInteger("metadata", metadata);
if (wire != null) {
nbt.setInteger("wire", wire.ordinal());
}
nbt.setBoolean("transparent", transparent);
}
public static NBTTagList writeArray(FacadeState[] states) {
@ -162,14 +175,17 @@ public class ItemFacade extends ItemBuildCraft {
list.add(String.format(stateString, state.wire.getColor(), getFacadeStateDisplayName(state)));
}
if (defaultState != null) {
list.add(1, String.format(StringUtils.localize("item.FacadePhase.state_default"), getFacadeStateDisplayName(defaultState)));
list.add(1, String.format(StringUtils.localize("item.FacadePhased.state_default"), getFacadeStateDisplayName(defaultState)));
}
}
}
public static String getFacadeStateDisplayName(FacadeState state) {
if (state.block == null) {
return StringUtils.localize("item.FacadePhased.state_transparent");
}
int meta = state.metadata;
if (state.block != null && state.block.getRenderType() == 31) {
if (state.block.getRenderType() == 31) {
meta &= 0x3;
}
return CoreProxy.proxy.getItemDisplayName(new ItemStack(state.block, 1, meta));

View file

@ -129,6 +129,8 @@ public class PipeIconProvider implements IIconProvider {
Power_Overload("texture_red_lit"),
Stripes("pipeStripes"),
//
TransparentFacade("transparent_facade"),
//
ItemBox("itemBox");
public static final TYPE[] VALUES = values();
private final String iconTag;

View file

@ -366,7 +366,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
ItemFacade.FacadeState[] states = sideProperties.facadeStates[direction.ordinal()];
if (states == null) {
renderState.facadeMatrix.setFacade(direction, null, 0);
renderState.facadeMatrix.setFacade(direction, null, 0, true);
continue;
}
// Iterate over all states and activate first proper
@ -384,9 +384,10 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (activeState == null) {
activeState = defaultState;
}
if (activeState != null) {
renderState.facadeMatrix.setFacade(direction, activeState.block, activeState.metadata);
}
Block block = activeState != null ? activeState.block : null;
int metadata = activeState != null ? activeState.metadata : 0;
boolean transparent = activeState == null || block == null;
renderState.facadeMatrix.setFacade(direction, block, metadata, transparent);
}
//Plugs
@ -751,6 +752,10 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
}
}
public boolean hasEnabledFacade(ForgeDirection direction) {
return hasFacade(direction) && !renderState.facadeMatrix.getFacadeTransparent(direction);
}
private void dropFacadeItem(ForgeDirection direction) {
InvUtils.dropItems(worldObj, getFacade(direction), this.xCoord, this.yCoord, this.zCoord);
}

View file

@ -14,7 +14,6 @@ import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
@ -47,11 +46,8 @@ public class FacadeItemRenderer implements IItemRenderer {
} else if (type == ItemFacade.FacadeType.Phased) {
activeState = states[renderState % states.length];
}
if (activeState == null) {
return;
}
Block block = activeState.block;
int decodedMeta = activeState.metadata;
Block block = activeState != null ? activeState.block : null;
int decodedMeta = activeState != null ? activeState.metadata : 0;
try {
int color = item.getItem().getColorFromItemStack(new ItemStack(block, 1, decodedMeta), 0);
@ -61,10 +57,6 @@ public class FacadeItemRenderer implements IItemRenderer {
Tessellator tessellator = Tessellator.instance;
if (block == null) {
return;
}
if (tryGetBlockIcon(block, 0, decodedMeta) == null) {
return;
}
@ -73,14 +65,13 @@ public class FacadeItemRenderer implements IItemRenderer {
GL11.glPushMatrix();
// Enable glBlending for transparency
if (block.getRenderBlockPass() > 0) {
if (block != null && block.getRenderBlockPass() > 0) {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
}
block.setBlockBounds(0F, 0F, 1F - 1F / 16F, 1F, 1F, 1F);
render.setRenderBoundsFromBlock(block);
render.setRenderBounds(0F, 0F, 1F - 1F / 16F, 1F, 1F, 1F);
GL11.glTranslatef(translateX, translateY, translateZ);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1F, 0.0F);
@ -106,10 +97,9 @@ public class FacadeItemRenderer implements IItemRenderer {
tessellator.setNormal(1.0F, 0.0F, 0.0F);
render.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 5, decodedMeta));
tessellator.draw();
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
// Disable blending
if (block.getRenderBlockPass() > 0) {
if (block != null && block.getRenderBlockPass() > 0) {
GL11.glDisable(GL11.GL_BLEND);
}
@ -159,7 +149,7 @@ public class FacadeItemRenderer implements IItemRenderer {
try {
return block.getBlockTextureFromSide(side);
} catch (Throwable t2) {
return Blocks.cobblestone.getIcon(0, 0);
return PipeIconProvider.TYPE.TransparentFacade.getIcon();
}
}
}

View file

@ -18,15 +18,17 @@ public class FacadeMatrix {
private final Block[] blocks = new Block[ForgeDirection.VALID_DIRECTIONS.length];
private final int[] blockMetas = new int[ForgeDirection.VALID_DIRECTIONS.length];
private final boolean[] transparent = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
private boolean dirty = false;
public FacadeMatrix() {
}
public void setFacade(ForgeDirection direction, Block block, int blockMeta) {
if (blocks[direction.ordinal()] != block || blockMetas[direction.ordinal()] != blockMeta) {
public void setFacade(ForgeDirection direction, Block block, int blockMeta, boolean trans) {
if (blocks[direction.ordinal()] != block || blockMetas[direction.ordinal()] != blockMeta || transparent[direction.ordinal()] != trans) {
blocks[direction.ordinal()] = block;
blockMetas[direction.ordinal()] = blockMeta;
transparent[direction.ordinal()] = trans;
dirty = true;
}
}
@ -39,6 +41,10 @@ public class FacadeMatrix {
return blockMetas[direction.ordinal()];
}
public boolean getFacadeTransparent(ForgeDirection direction) {
return transparent[direction.ordinal()];
}
public boolean isDirty() {
return dirty;
}
@ -54,7 +60,7 @@ public class FacadeMatrix {
} else {
data.writeShort(Block.blockRegistry.getIDForObject(blocks[i]));
}
data.writeBoolean(transparent[i]);
data.writeByte(blockMetas[i]);
}
}
@ -75,6 +81,11 @@ public class FacadeMatrix {
blocks[i] = block;
dirty = true;
}
boolean trans = data.readBoolean();
if (transparent[i] != trans) {
transparent[i] = trans;
dirty = true;
}
byte meta = data.readByte();
if (blockMetas[i] != meta) {
blockMetas[i] = meta;