add clear filters (as requested by Forecaster)

This commit is contained in:
asiekierka 2015-11-07 10:19:35 +01:00
parent 950426071d
commit 8377eb94f7
4 changed files with 49 additions and 13 deletions

View file

@ -21,6 +21,7 @@ public class LensFilterHandler {
int myColor = event.item.color == null ? -1 : event.item.color.ordinal(); int myColor = event.item.color == null ? -1 : event.item.color.ordinal();
for (ForgeDirection dir : event.destinations) { for (ForgeDirection dir : event.destinations) {
boolean hasFilter = false;
int sideColor = -1; int sideColor = -1;
int sideLensColor = -1; int sideLensColor = -1;
@ -29,6 +30,7 @@ public class LensFilterHandler {
PipePluggable pluggable = container.getPipePluggable(dir); PipePluggable pluggable = container.getPipePluggable(dir);
if (pluggable != null && pluggable instanceof LensPluggable) { if (pluggable != null && pluggable instanceof LensPluggable) {
if (((LensPluggable) pluggable).isFilter) { if (((LensPluggable) pluggable).isFilter) {
hasFilter = true;
sideColor = ((LensPluggable) pluggable).color; sideColor = ((LensPluggable) pluggable).color;
} else { } else {
sideLensColor = ((LensPluggable) pluggable).color; sideLensColor = ((LensPluggable) pluggable).color;
@ -42,28 +44,30 @@ public class LensFilterHandler {
pluggable = otherContainer.getPipePluggable(dir.getOpposite()); pluggable = otherContainer.getPipePluggable(dir.getOpposite());
if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) { if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) {
int otherColor = ((LensPluggable) pluggable).color; int otherColor = ((LensPluggable) pluggable).color;
if (sideColor >= 0 && otherColor != sideColor) { if (hasFilter && otherColor != sideColor) {
// Filter colors conflict - the side is unpassable // Filter colors conflict - the side is unpassable
continue; continue;
} else if (sideLensColor >= 0) { } else if (sideLensColor >= 0) {
// The closer lens color differs from the further away filter color - the side is unpassable OR treated as colorless // The closer lens color differs from the further away filter color - the side is unpassable OR treated as colorless
if (sideLensColor == otherColor) { if (sideLensColor == otherColor) {
hasFilter = false;
sideColor = -1; sideColor = -1;
} else { } else {
continue; continue;
} }
} else { } else {
hasFilter = true;
sideColor = otherColor; sideColor = otherColor;
} }
} }
} }
if (myColor == sideColor) { if (hasFilter) {
encounteredColor = true; if (myColor == sideColor) {
correctColored.add(dir); encounteredColor = true;
} correctColored.add(dir);
}
if (sideColor == -1) { } else {
notColored.add(dir); notColored.add(dir);
} }
} }

View file

@ -44,6 +44,9 @@ public final class TransportSiliconRecipes {
} }
} }
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:filter:16", 10000, new ItemStack(BuildCraftTransport.lensItem, 2, 32),
"blockGlass", Blocks.iron_bars);
// PIPE WIRE // PIPE WIRE
if (Utils.isRegistered(PipeWire.item)) { if (Utils.isRegistered(PipeWire.item)) {
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redWire", 5000, PipeWire.RED.getStack(8), BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redWire", 5000, PipeWire.RED.getStack(8),

View file

@ -38,9 +38,18 @@ public class ItemLens extends ItemBuildCraft implements IPipePluggableItem {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public IIcon getIconFromDamageForRenderPass(int meta, int pass) { public IIcon getIconFromDamageForRenderPass(int meta, int pass) {
if (meta == 32) {
return icons[2];
}
return icons[meta >= 16 ? (1 + (pass & 1)) : (1 - (pass & 1))]; return icons[meta >= 16 ? (1 + (pass & 1)) : (1 - (pass & 1))];
} }
@Override
@SideOnly(Side.CLIENT)
public int getRenderPasses(int metadata) {
return metadata == 32 ? 1 : 2;
}
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() { public boolean requiresMultipleRenderPasses() {
@ -54,12 +63,19 @@ public class ItemLens extends ItemBuildCraft implements IPipePluggableItem {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int pass) { public int getColorFromItemStack(ItemStack stack, int pass) {
if (stack.getItemDamage() == 32) {
return 16777215;
}
return pass == 0 ? ColorUtils.getRGBColor(getDye(stack)) : 16777215; return pass == 0 ? ColorUtils.getRGBColor(getDye(stack)) : 16777215;
} }
@Override @Override
public String getItemStackDisplayName(ItemStack itemstack) { public String getItemStackDisplayName(ItemStack itemstack) {
return StringUtils.localize(itemstack.getItemDamage() >= 16 ? "item.Filter.name" : "item.Lens.name") + " (" + StringUtils.localize("color." + ColorUtils.getName(getDye(itemstack))) + ")"; if (itemstack.getItemDamage() == 32) {
return StringUtils.localize("item.Filter.name") + " (" + StringUtils.localize("color.clear") + ")";
} else {
return StringUtils.localize(itemstack.getItemDamage() >= 16 ? "item.Filter.name" : "item.Lens.name") + " (" + StringUtils.localize("color." + ColorUtils.getName(getDye(itemstack))) + ")";
}
} }
@Override @Override
@ -77,7 +93,7 @@ public class ItemLens extends ItemBuildCraft implements IPipePluggableItem {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List itemList) { public void getSubItems(Item item, CreativeTabs tab, List itemList) {
for (int i = 0; i < 32; i++) { for (int i = 0; i <= 32; i++) {
itemList.add(new ItemStack(item, 1, i)); itemList.add(new ItemStack(item, 1, i));
} }
} }

View file

@ -52,6 +52,11 @@ public class LensPluggable extends PipePluggable {
zeroState[2][1] = 0.8125F; zeroState[2][1] = 0.8125F;
if (renderPass == 1) { if (renderPass == 1) {
int color = ((LensPluggable) pipePluggable).color;
if (color < 0) {
return;
}
blockStateMachine.setRenderMask(1 << side.ordinal() | (1 << (side.ordinal() ^ 1))); blockStateMachine.setRenderMask(1 << side.ordinal() | (1 << (side.ordinal() ^ 1)));
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -59,7 +64,7 @@ public class LensPluggable extends PipePluggable {
zeroState[i][1] -= zFightOffset; zeroState[i][1] -= zFightOffset;
} }
blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeLensOverlay.ordinal())); blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeLensOverlay.ordinal()));
((FakeBlock) blockStateMachine).setColor(ColorUtils.getRGBColor(15 - ((LensPluggable) pipePluggable).color)); ((FakeBlock) blockStateMachine).setColor(ColorUtils.getRGBColor(15 - color));
blockStateMachine.setRenderAllSides(); blockStateMachine.setRenderAllSides();
} else { } else {
@ -87,6 +92,9 @@ public class LensPluggable extends PipePluggable {
public LensPluggable(ItemStack stack) { public LensPluggable(ItemStack stack) {
color = stack.getItemDamage() & 15; color = stack.getItemDamage() & 15;
isFilter = stack.getItemDamage() >= 16; isFilter = stack.getItemDamage() >= 16;
if (isFilter && stack.getItemDamage() == 32) {
color = -1;
}
} }
@Override @Override
@ -103,7 +111,12 @@ public class LensPluggable extends PipePluggable {
@Override @Override
public ItemStack[] getDropItems(IPipeTile pipe) { public ItemStack[] getDropItems(IPipeTile pipe) {
return new ItemStack[]{new ItemStack(BuildCraftTransport.lensItem, 1, color | (isFilter ? 16 : 0))}; int meta = color | (isFilter ? 16 : 0);
if (isFilter && color == -1) {
meta = 32;
}
return new ItemStack[]{new ItemStack(BuildCraftTransport.lensItem, 1, meta)};
} }
@Override @Override
@ -147,13 +160,13 @@ public class LensPluggable extends PipePluggable {
@Override @Override
public void writeData(ByteBuf data) { public void writeData(ByteBuf data) {
data.writeByte(color | (isFilter ? 0x20 : 0)); data.writeByte(((color + 1) & 0x1F) | (isFilter ? 0x20 : 0));
} }
@Override @Override
public void readData(ByteBuf data) { public void readData(ByteBuf data) {
int flags = data.readUnsignedByte(); int flags = data.readUnsignedByte();
color = flags & 15; color = (flags & 31) - 1;
isFilter = (flags & 0x20) > 0; isFilter = (flags & 0x20) > 0;
} }