sensitive cables

This commit is contained in:
Raoul Van den Berge
2015-12-19 13:56:27 +01:00
parent fd787c0d0f
commit 54e4885020
12 changed files with 126 additions and 42 deletions

View File

@@ -1,6 +1,10 @@
package storagecraft.block;
import java.util.List;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import storagecraft.tile.TileCable;
@@ -15,6 +19,18 @@ public class BlockCable extends BlockBase implements ITileEntityProvider {
return new TileCable();
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List subItems) {
for (int i = 0; i < 2; i++) {
subItems.add(new ItemStack(item, 1, i));
}
}
@Override
public int damageDropped(int meta) {
return meta;
}
@Override
public int getRenderType() {
return -1;

View File

@@ -0,0 +1,16 @@
package storagecraft.item;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlockWithMetadata;
import net.minecraft.item.ItemStack;
public class ItemBlockBase extends ItemBlockWithMetadata {
public ItemBlockBase(Block block) {
super(block, block);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return getUnlocalizedName() + "." + stack.getItemDamage();
}
}

View File

@@ -0,0 +1,9 @@
package storagecraft.item;
import net.minecraft.block.Block;
public class ItemBlockCable extends ItemBlockBase {
public ItemBlockCable(Block block) {
super(block);
}
}

View File

@@ -10,6 +10,7 @@ import storagecraft.StorageCraft;
import storagecraft.StorageCraftBlocks;
import storagecraft.StorageCraftItems;
import storagecraft.gui.GuiHandler;
import storagecraft.item.ItemBlockCable;
import storagecraft.network.MessageExporterUpdate;
import storagecraft.network.MessageImporterUpdate;
import storagecraft.network.MessageRedstoneModeUpdate;
@@ -44,7 +45,7 @@ public class CommonProxy {
GameRegistry.registerTileEntity(TileExporter.class, "exporter");
GameRegistry.registerBlock(StorageCraftBlocks.CONTROLLER, "controller");
GameRegistry.registerBlock(StorageCraftBlocks.CABLE, "cable");
GameRegistry.registerBlock(StorageCraftBlocks.CABLE, ItemBlockCable.class, "cable");
GameRegistry.registerBlock(StorageCraftBlocks.GRID, "grid");
GameRegistry.registerBlock(StorageCraftBlocks.DRIVE, "drive");
GameRegistry.registerBlock(StorageCraftBlocks.STORAGE_PROXY, "storageProxy");

View File

@@ -1,31 +1,20 @@
package storagecraft.render;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import storagecraft.render.model.CableModel;
import storagecraft.tile.TileCable;
public class BlockCableRenderer extends TileEntitySpecialRenderer {
public static final CableModel CABLE_MODEL = new CableModel();
public static final ResourceLocation CABLE_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cable.png");
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
{
GL11.glPushMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
CABLE_MODEL.render((TileCable) tile, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
GL11.glPopMatrix();
}
CABLE_MODEL.render((TileCable) tile, 0.0625F);
GL11.glPopMatrix();
}

View File

@@ -2,9 +2,11 @@ package storagecraft.render;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import storagecraft.render.model.CableModel;
public class ItemCableRenderer implements IItemRenderer {
public static final BlockCableRenderer CABLE_RENDERER = new BlockCableRenderer();
public static final CableModel CABLE_MODEL = new CableModel();
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
@@ -18,6 +20,10 @@ public class ItemCableRenderer implements IItemRenderer {
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
CABLE_RENDERER.renderTileEntityAt(null, 0, 0, 0, 0);
GL11.glPushMatrix();
CABLE_MODEL.render(item, 0.0625F);
GL11.glPopMatrix();
}
}

View File

@@ -1,11 +1,18 @@
package storagecraft.render.model;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import storagecraft.tile.TileCable;
public class CableModel extends ModelBase {
public static final ResourceLocation CABLE_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cable.png");
public static final ResourceLocation CABLE_UNPOWERED_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cableUnpowered.png");
public static final ResourceLocation CABLE_POWERED_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cablePowered.png");
private ModelRenderer core;
private ModelRenderer up;
private ModelRenderer down;
@@ -44,36 +51,62 @@ public class CableModel extends ModelBase {
west.setTextureSize(16, 16);
}
public void render(TileCable cable, float f, float f1, float f2, float f3, float f4, float f5) {
core.render(f5);
public void render(ItemStack cable, float x) {
if (cable.getItemDamage() == 1) {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_UNPOWERED_RESOURCE);
} else {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
}
core.render(x);
if (cable.getItemDamage() == 1) {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
}
north.render(x);
south.render(x);
}
public void render(TileCable cable, float x) {
if (cable.isSensitiveCable()) {
if (cable.isPowered()) {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_POWERED_RESOURCE);
} else {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_UNPOWERED_RESOURCE);
}
} else {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
}
core.render(x);
if (cable.isSensitiveCable()) {
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
}
if (cable != null) {
if (cable.hasConnection(ForgeDirection.UP)) {
up.render(f5);
up.render(x);
}
if (cable.hasConnection(ForgeDirection.DOWN)) {
down.render(f5);
down.render(x);
}
if (cable.hasConnection(ForgeDirection.NORTH)) {
north.render(f5);
north.render(x);
}
if (cable.hasConnection(ForgeDirection.EAST)) {
east.render(f5);
east.render(x);
}
if (cable.hasConnection(ForgeDirection.SOUTH)) {
south.render(f5);
south.render(x);
}
if (cable.hasConnection(ForgeDirection.WEST)) {
west.render(f5);
}
} else {
north.render(f5);
south.render(f5);
west.render(x);
}
}
}

View File

@@ -25,6 +25,14 @@ public class TileCable extends TileBase {
return true;
}
public boolean isPowered() {
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
public boolean isSensitiveCable() {
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1;
}
public void addMachines(List<Vec3> visited, List<TileMachine> machines, TileController controller) {
for (Vec3 visitedBlock : visited) {
if (visitedBlock.xCoord == xCoord && visitedBlock.yCoord == yCoord && visitedBlock.zCoord == zCoord) {
@@ -58,7 +66,11 @@ public class TileCable extends TileBase {
visited.add(Vec3.createVectorHelper(x, y, z));
} else if (tile instanceof TileCable) {
TileCable cable = (TileCable) tile;
if (!cable.isSensitiveCable() || (cable.isSensitiveCable() && !cable.isPowered())) {
((TileCable) tile).addMachines(visited, machines, controller);
}
} else if (tile instanceof TileController && (x != controller.xCoord || y != controller.yCoord || z != controller.zCoord)) {
worldObj.createExplosion(null, x, y, z, 4.5f, true);
}

View File

@@ -27,7 +27,8 @@ misc.storagecraft:importer.mode.0=Whitelist
misc.storagecraft:importer.mode.1=Blacklist
block.storagecraft:controller.name=Controller
block.storagecraft:cable.name=Cable
block.storagecraft:cable.0.name=Cable
block.storagecraft:cable.1.name=Sensitive Cable
block.storagecraft:grid.name=Grid
block.storagecraft:drive.name=Drive
block.storagecraft:storageProxy.name=Storage Proxy

View File

@@ -27,7 +27,8 @@ misc.storagecraft:importer.mode.0=Whitelist
misc.storagecraft:importer.mode.1=Blacklist
block.storagecraft:controller.name=Controleur
block.storagecraft:cable.name=Kabel
block.storagecraft:cable.0.name=Kabel
block.storagecraft:cable.1.name=Gevoelige Kabel
block.storagecraft:grid.name=Rooster
block.storagecraft:drive.name=Schijf
block.storagecraft:storageProxy.name=Opslag Proxy

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B