Merge branch 'development' of https://github.com/aidancbrady/Mekanism into development

This commit is contained in:
Aidan Brady 2014-01-12 22:47:14 -05:00
commit 763c5decb1
14 changed files with 479 additions and 12 deletions

View file

@ -0,0 +1,39 @@
package mekanism.api;
import java.util.HashSet;
import java.util.Set;
public class MekanismAPI
{
//Add a BlockInfo value here if you don't want a certain block to be picked up by cardboard boxes
public static Set<BlockInfo> cardboardBoxIgnore = new HashSet<BlockInfo>();
public static class BlockInfo
{
public int id;
public int meta;
public BlockInfo(int i, int j)
{
id = i;
meta = j;
}
@Override
public boolean equals(Object obj)
{
return obj instanceof BlockInfo &&
((BlockInfo)obj).id == id &&
((BlockInfo)obj).meta == meta;
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + id;
code = 31 * code + meta;
return code;
}
}
}

View file

@ -165,6 +165,7 @@ public class CommonProxy
Mekanism.boundingBlockID = Mekanism.configuration.getBlock("BoundingBlock", 3005).getInt();
Mekanism.gasTankID = Mekanism.configuration.getBlock("GasTank", 3006).getInt();
Mekanism.machineBlock2ID = Mekanism.configuration.getBlock("MachineBlock2", 3008).getInt();
Mekanism.cardboardBoxID = Mekanism.configuration.getBlock("CardboardBox", 3009).getInt();
Mekanism.osmiumGenerationEnabled = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "OsmiumGenerationEnabled", true).getBoolean(true);
Mekanism.copperGenerationEnabled = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "CopperGenerationEnabled", true).getBoolean(true);

View file

@ -13,6 +13,8 @@ import java.util.logging.Logger;
import mekanism.api.ChemicalPair;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.MekanismAPI;
import mekanism.api.MekanismAPI.BlockInfo;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasNetwork.GasTransferEvent;
import mekanism.api.gas.GasRegistry;
@ -34,6 +36,7 @@ import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.block.BlockBasic;
import mekanism.common.block.BlockBounding;
import mekanism.common.block.BlockCardboardBox;
import mekanism.common.block.BlockEnergyCube;
import mekanism.common.block.BlockGasTank;
import mekanism.common.block.BlockMachine;
@ -47,6 +50,7 @@ import mekanism.common.integration.OreDictManager;
import mekanism.common.item.ItemAtomicDisassembler;
import mekanism.common.item.ItemBalloon;
import mekanism.common.item.ItemBlockBasic;
import mekanism.common.item.ItemBlockCardboardBox;
import mekanism.common.item.ItemBlockEnergyCube;
import mekanism.common.item.ItemBlockGasTank;
import mekanism.common.item.ItemBlockMachine;
@ -102,6 +106,7 @@ import mekanism.common.recipe.RecipeHandler;
import mekanism.common.tank.DynamicTankCache;
import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
import mekanism.common.tile.TileEntityBoundingBlock;
import mekanism.common.tile.TileEntityCardboardBox;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.tile.TileEntityEnergizedSmelter;
import mekanism.common.transporter.TransporterManager;
@ -211,6 +216,7 @@ public class Mekanism
public static int energyCubeID;
public static int boundingBlockID;
public static int gasTankID;
public static int cardboardBoxID;
//Items
public static ItemElectricBow ElectricBow;
@ -249,6 +255,7 @@ public class Mekanism
public static Block EnergyCube;
public static Block BoundingBlock;
public static Block GasTank;
public static Block CardboardBox;
//Multi-ID Items
public static Item Dust;
@ -750,6 +757,7 @@ public class Mekanism
ObsidianTNT = new BlockObsidianTNT(obsidianTNTID).setUnlocalizedName("ObsidianTNT").setCreativeTab(tabMekanism);
BoundingBlock = (BlockBounding) new BlockBounding(boundingBlockID).setUnlocalizedName("BoundingBlock");
GasTank = new BlockGasTank(gasTankID).setUnlocalizedName("GasTank");
CardboardBox = new BlockCardboardBox(cardboardBoxID).setUnlocalizedName("CardboardBox");
//Registrations
GameRegistry.registerBlock(BasicBlock, ItemBlockBasic.class, "BasicBlock");
@ -760,6 +768,7 @@ public class Mekanism
GameRegistry.registerBlock(ObsidianTNT, "ObsidianTNT");
GameRegistry.registerBlock(BoundingBlock, "BoundingBlock");
GameRegistry.registerBlock(GasTank, ItemBlockGasTank.class, "GasTank");
GameRegistry.registerBlock(CardboardBox, ItemBlockCardboardBox.class, "CardboardBox");
}
/**
@ -932,6 +941,7 @@ public class Mekanism
//Tile entities
GameRegistry.registerTileEntity(TileEntityBoundingBlock.class, "BoundingBlock");
GameRegistry.registerTileEntity(TileEntityAdvancedBoundingBlock.class, "AdvancedBoundingBlock");
GameRegistry.registerTileEntity(TileEntityCardboardBox.class, "CardboardBox");
//Load tile entities that have special renderers.
proxy.registerSpecialTileEntities();
@ -1057,6 +1067,9 @@ public class Mekanism
addRecipes();
addEntities();
MekanismAPI.cardboardBoxIgnore.add(new BlockInfo(BoundingBlock.blockID, 0));
MekanismAPI.cardboardBoxIgnore.add(new BlockInfo(BoundingBlock.blockID, 1));
registerOreDict();
new MultipartMekanism();

View file

@ -64,6 +64,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* 12: Copper Block
* 13: Tin Block
* 14: Salination Controller
* 15: Salination Valve
* @author AidanBrady
*
*/

View file

@ -0,0 +1,213 @@
package mekanism.common.block;
import java.util.Random;
import mekanism.common.Mekanism;
import mekanism.common.item.ItemBlockCardboardBox;
import mekanism.common.tile.TileEntityCardboardBox;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockCardboardBox extends BlockContainer
{
public Icon[] icons = new Icon[6];
public BlockCardboardBox(int id)
{
super(id, Material.cloth);
setCreativeTab(Mekanism.tabMekanism);
setHardness(0.5F);
setResistance(1F);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister register)
{
icons[0] = register.registerIcon("mekanism:CardboardBoxTop");
icons[1] = register.registerIcon("mekanism:CardboardBoxSide");
icons[2] = register.registerIcon("mekanism:CardboardBoxSideStorage");
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta)
{
if(side == 0 || side == 1)
{
return icons[0];
}
else {
return meta == 0 ? icons[1] : icons[2];
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ)
{
if(!world.isRemote && entityplayer.isSneaking())
{
ItemStack itemStack = new ItemStack(Mekanism.CardboardBox);
TileEntityCardboardBox tileEntity = (TileEntityCardboardBox)world.getBlockTileEntity(x, y, z);
if(tileEntity.storedData != null)
{
BlockData data = tileEntity.storedData;
world.setBlock(x, y, z, data.id, data.meta, 3);
if(data.tileTag != null && world.getBlockTileEntity(x, y, z) != null)
{
data.updateLocation(x, y, z);
world.getBlockTileEntity(x, y, z).readFromNBT(data.tileTag);
}
float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, itemStack);
world.spawnEntityInWorld(entityItem);
}
}
return false;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityCardboardBox();
}
public ItemStack dismantleBlock(World world, int x, int y, int z, boolean returnBlock)
{
ItemStack itemStack = getPickBlock(null, world, x, y, z);
world.setBlockToAir(x, y, z);
if(!returnBlock)
{
float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, itemStack);
world.spawnEntityInWorld(entityItem);
}
return itemStack;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
TileEntityCardboardBox tileEntity = (TileEntityCardboardBox)world.getBlockTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(Mekanism.CardboardBox, 1, world.getBlockMetadata(x, y, z));
if(tileEntity.storedData != null)
{
((ItemBlockCardboardBox)itemStack.getItem()).setBlockData(itemStack, tileEntity.storedData);
}
return itemStack;
}
@Override
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z)
{
if(!player.capabilities.isCreativeMode && !world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
{
float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, getPickBlock(null, world, x, y, z));
world.spawnEntityInWorld(entityItem);
}
return world.setBlockToAir(x, y, z);
}
@Override
public int quantityDropped(Random random)
{
return 0;
}
@Override
public int idDropped(int i, Random random, int j)
{
return 0;
}
public static class BlockData
{
public int id;
public int meta;
public NBTTagCompound tileTag;
public BlockData(int i, int j, NBTTagCompound nbtTags)
{
id = i;
meta = j;
tileTag = nbtTags;
}
public BlockData() {}
public void updateLocation(int x, int y, int z)
{
if(tileTag != null)
{
tileTag.setInteger("x", x);
tileTag.setInteger("y", y);
tileTag.setInteger("z", z);
}
}
public NBTTagCompound write(NBTTagCompound nbtTags)
{
nbtTags.setInteger("id", id);
nbtTags.setInteger("meta", meta);
if(tileTag != null)
{
nbtTags.setCompoundTag("tileTag", tileTag);
}
return nbtTags;
}
public static BlockData read(NBTTagCompound nbtTags)
{
BlockData data = new BlockData();
data.id = nbtTags.getInteger("id");
data.meta = nbtTags.getInteger("meta");
if(nbtTags.hasKey("tileTag"))
{
data.tileTag = nbtTags.getCompoundTag("tileTag");
}
return data;
}
}
}

View file

@ -0,0 +1,166 @@
package mekanism.common.item;
import java.util.List;
import mekanism.api.EnumColor;
import mekanism.api.MekanismAPI;
import mekanism.api.MekanismAPI.BlockInfo;
import mekanism.common.Mekanism;
import mekanism.common.block.BlockCardboardBox.BlockData;
import mekanism.common.tile.TileEntityCardboardBox;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemBlockCardboardBox extends ItemBlock
{
public Block metaBlock;
public ItemBlockCardboardBox(int id, Block block)
{
super(id);
setMaxStackSize(1);
metaBlock = block;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
list.add(EnumColor.INDIGO + "Block data: " + (getBlockData(itemstack) != null ? "Yes" : "No"));
if(getBlockData(itemstack) != null)
{
list.add("Block ID: " + getBlockData(itemstack).id);
list.add("Metadata: " + getBlockData(itemstack).meta);
if(getBlockData(itemstack).tileTag != null)
{
list.add("Tile: " + getBlockData(itemstack).tileTag.getString("id"));
}
}
}
@Override
public int getMetadata(int i)
{
return i;
}
@Override
public Icon getIconFromDamage(int i)
{
return metaBlock.getIcon(2, i);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if(!player.isSneaking() && !world.isAirBlock(x, y, z) && stack.getItemDamage() == 0)
{
int id = world.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!world.isRemote && !MekanismAPI.cardboardBoxIgnore.contains(new BlockInfo(id, meta)))
{
BlockData data = new BlockData();
data.id = id;
data.meta = meta;
if(world.getBlockTileEntity(x, y, z) != null)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
NBTTagCompound tag = new NBTTagCompound();
tile.writeToNBT(tag);
data.tileTag = tag;
if(tile instanceof IInventory)
{
IInventory inv = (IInventory)tile;
for(int i = 0; i < inv.getSizeInventory(); i++)
{
inv.setInventorySlotContents(i, null);
}
}
if(tile instanceof IDeepStorageUnit)
{
((IDeepStorageUnit)tile).setStoredItemCount(0);
}
}
if(!player.capabilities.isCreativeMode)
{
stack.stackSize--;
}
world.setBlock(x, y, z, Mekanism.cardboardBoxID, 1, 3);
TileEntityCardboardBox tileEntity = (TileEntityCardboardBox)world.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
tileEntity.storedData = data;
}
return true;
}
}
return false;
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if(world.isRemote)
{
return true;
}
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
if(place)
{
TileEntityCardboardBox tileEntity = (TileEntityCardboardBox)world.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
tileEntity.storedData = getBlockData(stack);
}
}
return place;
}
public void setBlockData(ItemStack itemstack, BlockData data)
{
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
itemstack.stackTagCompound.setCompoundTag("blockData", data.write(new NBTTagCompound()));
}
public BlockData getBlockData(ItemStack itemstack)
{
if(itemstack.stackTagCompound == null || !itemstack.stackTagCompound.hasKey("blockData"))
{
return null;
}
return BlockData.read(itemstack.stackTagCompound.getCompoundTag("blockData"));
}
}

View file

@ -742,6 +742,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
@Override
public boolean onRightClick(EntityPlayer player, int side)
{
super.onRightClick(player, side);
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.configurator.viewColor") + ": " + (color != null ? color.getName() : "None")));
return true;
}

View file

@ -26,6 +26,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
@ -68,6 +69,8 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
public boolean sendDesc = false;
public boolean redstonePowered = false;
public boolean redstoneReactive = true;
public ConnectionType[] connectionTypes = {ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL};
static
@ -166,7 +169,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
{
byte connections = 0x00;
if(world().isBlockIndirectlyGettingPowered(x(), y(), z()))
if(redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return connections;
}
@ -191,7 +194,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
{
byte connections = 0x00;
if(world().isBlockIndirectlyGettingPowered(x(), y(), z()))
if(redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return connections;
}
@ -330,7 +333,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
@Override
public boolean canConnect(ForgeDirection side)
{
if(world().isBlockIndirectlyGettingPowered(x(), y(), z()))
if(redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return false;
}
@ -438,7 +441,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
if(possibleTransmitters != currentTransmitterConnections)
{
boolean nowPowered = world().isBlockIndirectlyGettingPowered(x(), y(), z());
boolean nowPowered = redstoneReactive && world().isBlockIndirectlyGettingPowered(x(), y(), z());
if(nowPowered != redstonePowered)
{
@ -571,6 +574,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
sendDesc = true;
onModeChange(ForgeDirection.getOrientation(side));
player.sendChatToPlayer(ChatMessageComponent.createFromText("Connection type changed to " + connectionTypes[hit.subHit].toString()));
return true;
}
@ -592,7 +596,12 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
@Override
public boolean onRightClick(EntityPlayer player, int side)
{
return false;
redstoneReactive ^= true;
refreshConnections();
tile().notifyPartChange(this);
player.sendChatToPlayer(ChatMessageComponent.createFromText("Redstone sensitivity turned " + (redstoneReactive ? "on." : "off.")));
return true;
}
public boolean canConnectToAcceptor(ForgeDirection side, boolean ignoreActive)

View file

@ -218,13 +218,6 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
}
}
@Override
public boolean onRightClick(EntityPlayer player, int side)
{
fixTransmitterNetwork();
return true;
}
@Override
public void chunkLoad() {}
}

View file

@ -0,0 +1,28 @@
package mekanism.common.tile;
import mekanism.common.block.BlockCardboardBox.BlockData;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class TileEntityCardboardBox extends TileEntity
{
public BlockData storedData;
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
if(nbtTags.hasKey("storedData"))
{
storedData = BlockData.read(nbtTags.getCompoundTag("storedData"));
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTags)
{
if(storedData != null)
{
nbtTags.setCompoundTag("storedData", storedData.write(new NBTTagCompound()));
}
}
}

View file

@ -32,6 +32,9 @@ item.CompressedRedstone.name=Compressed Redstone
//Gas Tank
tile.GasTank.GasTank.name=Gas Tank
//Cardboard Box
tile.CardboardBox.name=Cardboard Box
//Basic Block
tile.BasicBlock.OsmiumBlock.name=Osmium Block
tile.BasicBlock.BronzeBlock.name=Bronze Block

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB