Add additional support for Gate Expansions

Things left to do:
-Sync expansions on the pipe to the client
-Rewrite Assembly table to support modifying Item NBT so you can add
expansions to Gates
This commit is contained in:
CovertJaguar 2013-12-10 02:02:35 -08:00
parent acef0b4d60
commit 70822c0178
15 changed files with 174 additions and 46 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

View file

@ -32,6 +32,9 @@ fluid.fuel=Fuel
gate.action.pipe.item.color=Paint Items %s
gate.expansion.pulsar=Autarchic Pulsar
gate.expansion.timer=Clock Timer
gate.logic.and=AND
gate.logic.or=OR
@ -85,24 +88,6 @@ item.diamondGearItem=Diamond Gear
item.templateItem=Template
item.wrenchItem=Wrench
item.pipeWaterproof=Pipe Sealant
item.pipeGate.0=Gate
item.pipeGate.1=Iron AND Gate
item.pipeGate.2=Iron OR Gate
item.pipeGate.3=Gold AND Gate
item.pipeGate.4=Gold OR Gate
item.pipeGate.5=Diamond AND Gate
item.pipeGate.6=Diamond OR Gate
item.pipeGate.7=Quartz AND Gate
item.pipeGate.8=Quartz OR Gate
item.pipeGateAutarchic.0=Autarchic Gate
item.pipeGateAutarchic.1=Autarchic Iron AND Gate
item.pipeGateAutarchic.2=Autarchic Iron OR Gate
item.pipeGateAutarchic.3=Autarchic Gold AND Gate
item.pipeGateAutarchic.4=Autarchic Gold OR Gate
item.pipeGateAutarchic.5=Autarchic Diamond AND Gate
item.pipeGateAutarchic.6=Autarchic Diamond OR Gate
item.pipeGateAutarchic.7=Autarchic Quartz AND Gate
item.pipeGateAutarchic.8=Autarchic Quartz OR Gate
item.redPipeWire=Red Pipe Wire
item.bluePipeWire=Blue Pipe Wire
item.greenPipeWire=Green Pipe Wire

View file

@ -41,7 +41,7 @@ import buildcraft.transport.blueprints.BptItemPipeEmerald;
import buildcraft.transport.blueprints.BptItemPipeIron;
import buildcraft.transport.blueprints.BptItemPipeWooden;
import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.transport.gates.GateExpansions;
import buildcraft.api.gates.GateExpansions;
import buildcraft.transport.network.PacketHandlerTransport;
import buildcraft.transport.pipes.PipeFluidsCobblestone;
import buildcraft.transport.pipes.PipeFluidsEmerald;

View file

@ -6,10 +6,8 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.gates;
package buildcraft.api.gates;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

View file

@ -6,7 +6,7 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.gates;
package buildcraft.api.gates;
import java.util.HashMap;
import java.util.Map;

View file

@ -6,9 +6,11 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.gates;
package buildcraft.api.gates;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
/**
*
@ -21,4 +23,12 @@ public interface IGateExpansion {
String getDisplayName();
GateExpansionController makeController(TileEntity pipeTile);
void registerBlockOverlay(IconRegister iconRegister);
void registerItemOverlay(IconRegister iconRegister);
Icon getOverlayBlock();
Icon getOverlayItem();
}

View file

@ -35,6 +35,8 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.ISolidSideTile;
@ -1049,6 +1051,11 @@ public class BlockGenericPipe extends BlockBuildCraft {
for (GateDefinition.GateLogic logic : GateDefinition.GateLogic.VALUES) {
logic.registerBlockIcon(iconRegister);
}
for (IGateExpansion expansion : GateExpansions.expansions.values()) {
expansion.registerBlockOverlay(iconRegister);
}
}
@Override

View file

@ -13,7 +13,7 @@ import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionRedstoneOutput;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import buildcraft.transport.gates.GateExpansionController;
import buildcraft.api.gates.GateExpansionController;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.triggers.ActionSignalOutput;
import com.google.common.collect.HashMultiset;

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) SpaceToad, 2011-2012
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.gates;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.core.utils.StringUtils;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public abstract class GateExpansionBuildcraft implements IGateExpansion {
private final String tag;
private Icon iconBlock;
private Icon iconItem;
public GateExpansionBuildcraft(String tag) {
this.tag = tag;
}
@Override
public String getUniqueIdentifier() {
return "buildcraft:" + tag;
}
@Override
public String getDisplayName() {
return StringUtils.localize("gate.expansion." + tag);
}
@Override
public void registerBlockOverlay(IconRegister iconRegister) {
iconBlock = iconRegister.registerIcon("buildcraft:gates/gate_expansion_" + tag);
}
@Override
public void registerItemOverlay(IconRegister iconRegister) {
iconItem = iconRegister.registerIcon("buildcraft:gates/gate_expansion_" + tag);
}
@Override
public Icon getOverlayBlock() {
return iconBlock;
}
@Override
public Icon getOverlayItem() {
return iconItem;
}
}

View file

@ -8,12 +8,13 @@
*/
package buildcraft.transport.gates;
import buildcraft.api.gates.GateExpansionController;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import java.util.List;
@ -25,21 +26,12 @@ import net.minecraftforge.common.ForgeDirection;
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class GateExpansionPulsar implements IGateExpansion {
public class GateExpansionPulsar extends GateExpansionBuildcraft implements IGateExpansion {
public static GateExpansionPulsar INSTANCE = new GateExpansionPulsar();
private GateExpansionPulsar() {
}
@Override
public String getUniqueIdentifier() {
return "buildcraft:pulsar";
}
@Override
public String getDisplayName() {
return StringUtils.localize("gate.expansion.pulsar");
super("pulsar");
}
@Override

View file

@ -8,6 +8,8 @@
*/
package buildcraft.transport.gates;
import buildcraft.api.gates.GateExpansionController;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.transport.Gate;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.GateDefinition.GateLogic;
@ -29,7 +31,13 @@ public class GateFactory {
if (stack == null || stack.stackSize <= 0 || !(stack.getItem() instanceof ItemGate))
return null;
return makeGate(pipe, ItemGate.getMaterial(stack), ItemGate.getLogic(stack));
Gate gate = makeGate(pipe, ItemGate.getMaterial(stack), ItemGate.getLogic(stack));
for (IGateExpansion expansion : ItemGate.getInstalledExpansions(stack)) {
gate.expansions.add(expansion.makeController(pipe.container));
}
return gate;
}
public static Gate makeGate(Pipe pipe, NBTTagCompound nbt) {

View file

@ -1,7 +1,10 @@
package buildcraft.transport.gates;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.GateExpansionController;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.ItemBuildCraft;
@ -11,11 +14,16 @@ import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.Icon;
public class ItemGate extends ItemBuildCraft {
@ -37,7 +45,7 @@ public class ItemGate extends ItemBuildCraft {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return GateMaterial.REDSTONE;
return GateMaterial.fromOrdinal(nbt.getByte("material"));
return GateMaterial.fromOrdinal(nbt.getByte("mat"));
}
public static GateLogic getLogic(ItemStack stack) {
@ -51,20 +59,49 @@ public class ItemGate extends ItemBuildCraft {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return;
nbt.setBoolean(expansion.getUniqueIdentifier(), true);
NBTTagList expansionList = nbt.getTagList("ex");
expansionList.appendTag(new NBTTagString("ex", expansion.getUniqueIdentifier()));
nbt.setTag("ex", expansionList);
}
public static boolean hasGateExpansion(ItemStack stack, IGateExpansion expansion) {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return false;
return nbt.getBoolean(expansion.getUniqueIdentifier());
try {
NBTTagList expansionList = nbt.getTagList("ex");
for (int i = 0; i < expansionList.tagCount(); i++) {
NBTTagString ex = (NBTTagString) expansionList.tagAt(i);
if (ex.data.equals(expansion.getUniqueIdentifier()))
return true;
}
} catch (RuntimeException error) {
}
return false;
}
public static Set<IGateExpansion> getInstalledExpansions(ItemStack stack) {
Set<IGateExpansion> expansions = new HashSet<IGateExpansion>();
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return expansions;
try {
NBTTagList expansionList = nbt.getTagList("ex");
for (int i = 0; i < expansionList.tagCount(); i++) {
NBTTagString exTag = (NBTTagString) expansionList.tagAt(i);
IGateExpansion ex = GateExpansions.expansions.get(exTag.data);
if (ex != null)
expansions.add(ex);
}
} catch (RuntimeException error) {
}
return expansions;
}
public static ItemStack makeGateItem(GateMaterial material, GateLogic logic) {
ItemStack stack = new ItemStack(BuildCraftTransport.pipeGate);
NBTTagCompound nbt = InvUtils.getItemData(stack);
nbt.setByte("material", (byte) material.ordinal());
nbt.setByte("mat", (byte) material.ordinal());
nbt.setByte("logic", (byte) logic.ordinal());
return stack;
}
@ -72,8 +109,11 @@ public class ItemGate extends ItemBuildCraft {
public static ItemStack makeGateItem(Gate gate) {
ItemStack stack = new ItemStack(BuildCraftTransport.pipeGate);
NBTTagCompound nbt = InvUtils.getItemData(stack);
nbt.setByte("material", (byte) gate.material.ordinal());
nbt.setByte("mat", (byte) gate.material.ordinal());
nbt.setByte("logic", (byte) gate.logic.ordinal());
for (GateExpansionController expansion : gate.expansions) {
addGateExpansion(stack, expansion.getType());
}
return stack;
}
@ -99,6 +139,14 @@ public class ItemGate extends ItemBuildCraft {
}
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean adv) {
super.addInformation(stack, player, list, adv);
for (IGateExpansion expansion : getInstalledExpansions(stack)) {
list.add(expansion.getDisplayName());
}
}
@Override
public Icon getIconIndex(ItemStack stack) {
return getLogic(stack).getIconItem();
@ -116,6 +164,10 @@ public class ItemGate extends ItemBuildCraft {
logic.registerItemIcon(iconRegister);
}
for (IGateExpansion expansion : GateExpansions.expansions.values()) {
expansion.registerItemOverlay(iconRegister);
}
for (IAction action : ActionManager.actions.values()) {
action.registerIcons(iconRegister);
}

View file

@ -1,5 +1,6 @@
package buildcraft.transport.render;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.transport.gates.ItemGate;
import java.util.Random;
import net.minecraft.item.ItemStack;
@ -57,6 +58,10 @@ public class GateItemRenderer implements IItemRenderer {
GL11.glScalef(1, 1, 1.05f);
renderLayerIn3D(ItemGate.getMaterial(stack).getIconItem());
for (IGateExpansion expansion : ItemGate.getInstalledExpansions(stack)) {
renderLayerIn3D(expansion.getOverlayItem());
}
GL11.glPopMatrix();
}
@ -145,11 +150,18 @@ public class GateItemRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING);
Icon icon = ItemGate.getLogic(stack).getIconItem();
renderItem.renderIcon(0, 0, icon, 16, 16);
if (type == ItemRenderType.ENTITY)
GL11.glTranslatef(0, 0, -0.01f);
icon = ItemGate.getMaterial(stack).getIconItem();
if (icon != null) {
if (type == ItemRenderType.ENTITY)
GL11.glTranslatef(0, 0, -0.01f);
if (icon != null)
renderItem.renderIcon(0, 0, icon, 16, 16);
for (IGateExpansion expansion : ItemGate.getInstalledExpansions(stack)) {
icon = expansion.getOverlayItem();
if (icon != null)
renderItem.renderIcon(0, 0, icon, 16, 16);
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();

View file

@ -10,6 +10,7 @@ package buildcraft.transport.render;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.GateExpansionController;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipe.WireColor;
import buildcraft.core.CoreConstants;
@ -462,6 +463,10 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
if (materialIcon != null)
renderGate(pipe, materialIcon, 1);
for (GateExpansionController expansion : pipe.pipe.gate.expansions) {
renderGate(pipe, expansion.getType().getOverlayBlock(), 2);
}
RenderHelper.enableStandardItemLighting();
GL11.glPopAttrib();