Initiate set up for the mixture fluid tile

This commit is contained in:
Calclavia 2014-02-01 12:55:50 +08:00
parent 51356b5958
commit 4c940c1949
8 changed files with 42 additions and 82 deletions

View file

@ -15,12 +15,13 @@ import net.minecraftforge.fluids.Fluid;
import org.modstats.ModstatInfo;
import org.modstats.Modstats;
import resonantinduction.core.handler.FluidEventHandler;
import resonantinduction.core.handler.TextureHookHandler;
import resonantinduction.core.handler.ToolModeLink;
import resonantinduction.core.prefab.part.PacketMultiPart;
import resonantinduction.core.resource.BlockDust;
import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.TileMaterial;
import resonantinduction.core.resource.fluid.TileFluidMixture;
import resonantinduction.core.resource.item.ItemOreResource;
import calclavia.components.tool.ToolMode;
import calclavia.lib.content.ContentRegistry;
@ -77,8 +78,8 @@ public class ResonantInduction
public static ItemOreResource itemDust;
public static ItemOreResource itemRefinedDust;
public static Block blockDust;
public static List<Block> blockFluidMixtures = new ArrayList<Block>();
public static List<Block> blockFluidMaterials = new ArrayList<Block>();
public static final List<Block> blockFluidMixtures = new ArrayList<Block>();
public static final List<Block> blockFluidMaterials = new ArrayList<Block>();
public static Block blockGas;
public static List<Fluid> fluidMixtures = new ArrayList<Fluid>();
@ -97,9 +98,8 @@ public class ResonantInduction
Settings.load();
// Register Forge Events
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(ResourceGenerator.INSTANCE);
MinecraftForge.EVENT_BUS.register(new FluidEventHandler());
MinecraftForge.EVENT_BUS.register(new TextureHookHandler());
/**
* Melting dusts
@ -115,6 +115,9 @@ public class ResonantInduction
GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName());
GameRegistry.registerItem(itemRefinedDust, itemRefinedDust.getUnlocalizedName());
//Already registered wih ContentRegistry
//GameRegistry.registerTileEntity(TileMaterial.class, "ri_material");
GameRegistry.registerTileEntity(TileFluidMixture.class, "ri_fluid_mixture");
Settings.save();
proxy.preInit();
}
@ -134,31 +137,4 @@ public class ResonantInduction
// Generate Resources
ResourceGenerator.generateOreResources();
}
public static final HashMap<String, Icon> loadedIconMap = new HashMap<String, Icon>();
public void registerIcon(String name, TextureStitchEvent.Pre event)
{
loadedIconMap.put(name, event.map.registerIcon(name));
}
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void preTextureHook(TextureStitchEvent.Pre event)
{
if (event.map.textureType == 0)
{
registerIcon(Reference.PREFIX + "mixture_flow", event);
registerIcon(Reference.PREFIX + "molten_flow", event);
registerIcon(Reference.PREFIX + "multimeter_screen", event);
}
}
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void postTextureHook(TextureStitchEvent.Post event)
{
for (Fluid fluid : fluidMaterials)
fluid.setIcons(loadedIconMap.get(Reference.PREFIX + "molten_flow"));
}
}

View file

@ -15,13 +15,13 @@ import cpw.mods.fml.relauncher.SideOnly;
* @author Calclavia
*
*/
public class FluidEventHandler
public class TextureHookHandler
{
public static final HashMap<String, Icon> fluidIconMap = new HashMap<String, Icon>();
public static final HashMap<String, Icon> loadedIconMap = new HashMap<String, Icon>();
public void registerIcon(String name, TextureStitchEvent.Pre event)
{
fluidIconMap.put(name, event.map.registerIcon(name));
loadedIconMap.put(name, event.map.registerIcon(name));
}
@ForgeSubscribe
@ -32,6 +32,7 @@ public class FluidEventHandler
{
registerIcon(Reference.PREFIX + "mixture_flow", event);
registerIcon(Reference.PREFIX + "molten_flow", event);
registerIcon(Reference.PREFIX + "multimeter_screen", event);
}
}
@ -40,8 +41,8 @@ public class FluidEventHandler
public void textureHook(TextureStitchEvent.Post event)
{
for (Fluid f : ResonantInduction.fluidMixtures)
f.setIcons(fluidIconMap.get(Reference.PREFIX + "mixture_flow"));
f.setIcons(loadedIconMap.get(Reference.PREFIX + "mixture_flow"));
for (Fluid f : ResonantInduction.fluidMaterials)
f.setIcons(fluidIconMap.get(Reference.PREFIX + "molten_flow"));
f.setIcons(loadedIconMap.get(Reference.PREFIX + "molten_flow"));
}
}

View file

@ -54,7 +54,7 @@ public class BlockDust extends BlockRI
if (tileEntity instanceof TileMaterial)
{
return ((TileMaterial) tileEntity).clientColor;
return ((TileMaterial) tileEntity).getColor();
}
return 16777215;

View file

@ -100,7 +100,7 @@ public class ResourceGenerator
FluidRegistry.registerFluid(fluidMixture);
Block blockFluidMixture = new BlockFluidMixture(fluidMixture);
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps);
ResonantInduction.blockFluidMaterials.add(blockFluidMixture);
ResonantInduction.blockFluidMixtures.add(blockFluidMixture);
if (OreDictionary.getOres("ore" + nameCaps).size() > 0)
{
@ -133,7 +133,7 @@ public class ResourceGenerator
@SideOnly(Side.CLIENT)
public static void computeColors()
{
for (String ingotName : materialNames)
for (String material : materialNames)
{
// Compute color
int totalR = 0;
@ -142,15 +142,15 @@ public class ResourceGenerator
int colorCount = 0;
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1)))
for (ItemStack ingotStack : OreDictionary.getOres("ingot" + material.substring(0, 1).toUpperCase() + material.substring(1)))
{
Item theIngot = ingotStack.getItem();
materialColors.put(ingotName, getAverageColor(ingotStack));
materialColors.put(material, getAverageColor(ingotStack));
}
if (!materialColors.containsKey(ingotName))
if (!materialColors.containsKey(material))
{
materialColors.put(ingotName, 0xFFFFFF);
materialColors.put(material, 0xFFFFFF);
}
}
}

View file

@ -18,7 +18,12 @@ import com.google.common.io.ByteArrayDataInput;
public class TileMaterial extends TileAdvanced implements IPacketReceiver
{
public String name;
public int clientColor;
private int clientColor = 0xFFFFFF;
public int getColor()
{
return clientColor;
}
@Override
public boolean canUpdate()

View file

@ -13,8 +13,8 @@ import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.TileMaterial;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.prefab.tile.TileAdvanced;
import com.google.common.io.ByteArrayDataInput;
@ -25,13 +25,11 @@ import cpw.mods.fml.relauncher.SideOnly;
* @author Calclavia
*
*/
public class TileFluidMixture extends TileAdvanced implements IPacketReceiver
public class TileFluidMixture extends TileMaterial
{
public final Set<ItemStack> items = new HashSet<ItemStack>();
public final Set<FluidStack> fluids = new HashSet<FluidStack>();
private int clientColor = 0xFFFFFF;
@Override
public boolean canUpdate()
{
@ -44,6 +42,12 @@ public class TileFluidMixture extends TileAdvanced implements IPacketReceiver
{
// TODO: Maybe we need to merge the stacks?
items.add(itemStack);
if (name == null)
{
name = ResourceGenerator.getName(itemStack.getItemDamage());
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
}
@ -72,32 +76,6 @@ public class TileFluidMixture extends TileAdvanced implements IPacketReceiver
}
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
clientColor = data.readInt();
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
}
@Override
public Packet getDescriptionPacket()
{
for (ItemStack item : items)
{
return ResonantInduction.PACKET_TILE.getPacket(this, ResourceGenerator.getAverageColor(item));
}
return null;
}
/**
* @return The color of the liquid based on the fluidStacks stored.
*/
@SideOnly(Side.CLIENT)
public int getColor()
{
return clientColor;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
@ -158,5 +136,4 @@ public class TileFluidMixture extends TileAdvanced implements IPacketReceiver
nbt.setTag("Items", itemList);
}
}

View file

@ -12,6 +12,7 @@ import org.lwjgl.opengl.GL11;
import resonantinduction.archaic.Archaic;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.handler.TextureHookHandler;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;
import universalelectricity.api.vector.Vector3;
@ -39,7 +40,7 @@ public class RenderMultimeter
GL11.glRotatef(90, 1, 0, 0);
RenderUtility.bind(TextureMap.locationBlocksTexture);
// Render the main panel
RenderUtility.renderCube(-0.5, -0.05, -0.5, 0.5, 0.05, 0.5, Archaic.blockMachinePart, ResonantInduction.loadedIconMap.get(Reference.PREFIX + "multimeter_screen"));
RenderUtility.renderCube(-0.5, -0.05, -0.5, 0.5, 0.05, 0.5, Archaic.blockMachinePart, TextureHookHandler.loadedIconMap.get(Reference.PREFIX + "multimeter_screen"));
ForgeDirection dir = ForgeDirection.NORTH;
final int metadata = 8;
// Render edges
@ -91,7 +92,7 @@ public class RenderMultimeter
RenderUtility.rotateFaceBlockToSideOutwards(part.getDirection().getOpposite());
RenderUtility.bind(TextureMap.locationBlocksTexture);
// Render the main panel
RenderUtility.renderCube(-0.5, -0.05, -0.5, 0.5, 0.05, 0.5, Archaic.blockMachinePart, ResonantInduction.loadedIconMap.get(Reference.PREFIX + "multimeter_screen"));
RenderUtility.renderCube(-0.5, -0.05, -0.5, 0.5, 0.05, 0.5, Archaic.blockMachinePart, TextureHookHandler.loadedIconMap.get(Reference.PREFIX + "multimeter_screen"));
final int metadata = 8;
// Render edges
// UP

View file

@ -46,13 +46,13 @@ public class TileMixer extends TileMechanical
*/
public boolean canWork()
{
return angularVelocity > 0;
return angularVelocity != 0;
}
public void doWork()
{
boolean didWork = false;
// Search for an item to "process"
AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(this.xCoord - 1, this.yCoord, this.zCoord - 1, this.xCoord + 2, this.yCoord + 1, this.zCoord + 2);
List<Entity> entities = this.worldObj.getEntitiesWithinAABB(Entity.class, aabb);
@ -65,7 +65,7 @@ public class TileMixer extends TileMechanical
*/
Vector3 originalPosition = new Vector3(entity);
Vector3 relativePosition = originalPosition.clone().subtract(new Vector3(this).add(0.5));
relativePosition.rotate(angularVelocity, 0, 0);
relativePosition.rotate(-angularVelocity, 0, 0);
Vector3 newPosition = new Vector3(this).add(0.5).add(relativePosition);
Vector3 difference = newPosition.difference(originalPosition).scale(0.5);
@ -151,7 +151,7 @@ public class TileMixer extends TileMechanical
}
else
{
mixPosition.setBlock(worldObj, ResonantInduction.blockFluidMixtures.get(entity.getEntityItem().getItemDamage()).blockID);
mixPosition.setBlock(worldObj, ResonantInduction.blockFluidMixtures.get(entity.getEntityItem().getItemDamage()).blockID, 8);
}
return false;