Crane work
This commit is contained in:
parent
673fe6469d
commit
b1d5ea505c
10 changed files with 232 additions and 39 deletions
Binary file not shown.
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 718 B |
Before Width: | Height: | Size: 7 KiB After Width: | Height: | Size: 7 KiB |
BIN
resources/assemblyline/textures/quarryControllerValid.png
Normal file
BIN
resources/assemblyline/textures/quarryControllerValid.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
|
@ -1,4 +1,4 @@
|
|||
package assemblyline.common.machine.crane;
|
||||
package assemblyline.api;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
6
src/minecraft/assemblyline/api/ICraneStructure.java
Normal file
6
src/minecraft/assemblyline/api/ICraneStructure.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package assemblyline.api;
|
||||
|
||||
public interface ICraneStructure extends ICraneConnectable
|
||||
{
|
||||
|
||||
}
|
|
@ -1,25 +1,24 @@
|
|||
package assemblyline.client.render;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_LIGHTING;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glRotatef;
|
||||
import static org.lwjgl.opengl.GL11.glTranslated;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import assemblyline.client.model.ModelCraneController;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.machine.crane.TileEntityCraneController;
|
||||
|
||||
public class RenderCraneController extends RenderImprintable
|
||||
{
|
||||
public static final String TEXTURE = "quarry_controller_map.png";
|
||||
public static final String TEXTURE = "quarryControllerOff.png";
|
||||
public static final String TEXTURE_VALID = "quarryControllerValid.png";
|
||||
public static final ModelCraneController MODEL = new ModelCraneController();
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
|
||||
{
|
||||
this.bindTextureByName(AssemblyLine.TEXTURE_PATH + TEXTURE);
|
||||
if (tileEntity != null && tileEntity instanceof TileEntityCraneController)
|
||||
{
|
||||
this.bindTextureByName(AssemblyLine.TEXTURE_PATH + (((TileEntityCraneController) tileEntity).isCraneValid() ? TEXTURE_VALID : TEXTURE));
|
||||
ForgeDirection rot = ForgeDirection.getOrientation(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
||||
float angle = 0f;
|
||||
switch (rot)
|
||||
|
@ -48,5 +47,6 @@ public class RenderCraneController extends RenderImprintable
|
|||
MODEL.render(0.0625f);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -34,30 +34,26 @@ public class BlockCraneController extends BlockMachine
|
|||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity)
|
||||
{
|
||||
int rot = (int) Math.min((entity.rotationYaw - 45f) / 90f, 3);
|
||||
int rot = (int) Math.min(((entity.rotationYaw + 315f) % 360f) / 90f, 3);
|
||||
switch (rot)
|
||||
{
|
||||
case 0: // WEST
|
||||
{
|
||||
System.out.println("Facing west...");
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.WEST.ordinal());
|
||||
break;
|
||||
}
|
||||
case 1: // NORTH
|
||||
{
|
||||
System.out.println("Facing north...");
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.NORTH.ordinal());
|
||||
break;
|
||||
}
|
||||
case 2: // EAST
|
||||
{
|
||||
System.out.println("Facing east...");
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.EAST.ordinal());
|
||||
break;
|
||||
}
|
||||
default: // SOUTH
|
||||
{
|
||||
System.out.println("Facing south...");
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.SOUTH.ordinal());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package assemblyline.common.machine.crane;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import assemblyline.api.ICraneConnectable;
|
||||
import assemblyline.api.ICraneStructure;
|
||||
|
||||
/**
|
||||
* Manager of crane movement, mapping, setup, but not AI
|
||||
|
@ -16,6 +19,16 @@ public class CraneHelper
|
|||
*/
|
||||
public static final int MAX_SIZE = 64;
|
||||
|
||||
public static boolean isCraneBlock(World world, int x, int y, int z)
|
||||
{
|
||||
return world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof ICraneConnectable;
|
||||
}
|
||||
|
||||
public static boolean isCraneStructureBlock(World world, int x, int y, int z)
|
||||
{
|
||||
return world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof ICraneStructure;
|
||||
}
|
||||
|
||||
public static boolean canFrameConnectTo(TileEntity tileEntity, int x, int y, int z, ForgeDirection side)
|
||||
{
|
||||
if (tileEntity.worldObj.getBlockTileEntity(x, y, z) != null && tileEntity.worldObj.getBlockTileEntity(x, y, z) instanceof ICraneConnectable)
|
||||
|
|
|
@ -1,14 +1,170 @@
|
|||
package assemblyline.common.machine.crane;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import assemblyline.api.ICraneConnectable;
|
||||
import assemblyline.common.machine.TileEntityAssemblyNetwork;
|
||||
|
||||
public class TileEntityCraneController extends TileEntityAssemblyNetwork implements ICraneConnectable
|
||||
{
|
||||
int width, height, depth;
|
||||
boolean isCraneValid;
|
||||
long ticks;
|
||||
|
||||
public TileEntityCraneController()
|
||||
{
|
||||
super();
|
||||
width = height = depth = 0;
|
||||
isCraneValid = false;
|
||||
ticks = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
ticks++;
|
||||
if (ticks % 20 == 0)
|
||||
{
|
||||
validateCrane();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCraneValid()
|
||||
{
|
||||
return isCraneValid;
|
||||
}
|
||||
|
||||
private void validateCrane()
|
||||
{
|
||||
isCraneValid = false;
|
||||
width = height = depth = 0;
|
||||
findCraneHeight();
|
||||
findCraneWidth();
|
||||
findCraneDepth();
|
||||
if (Math.abs(height) > 1 && Math.abs(width) > 1 && Math.abs(depth) > 1)
|
||||
{
|
||||
isCraneValid = isFrameValid();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFrameValid()
|
||||
{
|
||||
for (int x = Math.min(0, width); x <= Math.max(0, width); x++)
|
||||
{
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + x, yCoord + height, zCoord))
|
||||
return false;
|
||||
}
|
||||
for (int x = Math.min(0, width); x <= Math.max(0, width); x++)
|
||||
{
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + x, yCoord + height, zCoord + depth))
|
||||
return false;
|
||||
}
|
||||
for (int z = Math.min(0, depth); z <= Math.max(0, depth); z++)
|
||||
{
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord, yCoord + height, zCoord + z))
|
||||
return false;
|
||||
}
|
||||
for (int z = Math.min(0, depth); z <= Math.max(0, depth); z++)
|
||||
{
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + width, yCoord + height, zCoord + z))
|
||||
return false;
|
||||
}
|
||||
for (int x = Math.min(width + 1, 1); x <= Math.max(-1, width - 1); x++)
|
||||
{
|
||||
for (int z = Math.min(depth + 1, 1); z <= Math.max(-1, depth - 1); z++)
|
||||
{
|
||||
if (!worldObj.isAirBlock(xCoord + x, yCoord + height, zCoord + z))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find x size and store in this.width
|
||||
*/
|
||||
private void findCraneWidth()
|
||||
{
|
||||
if (height == 0)
|
||||
{
|
||||
width = 0;
|
||||
return;
|
||||
}
|
||||
int x = 0;
|
||||
ForgeDirection facing = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
|
||||
while (true)
|
||||
{
|
||||
if (Math.abs(x) > CraneHelper.MAX_SIZE)
|
||||
break;
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + x, yCoord + height, zCoord))
|
||||
break;
|
||||
if (facing == ForgeDirection.NORTH || facing == ForgeDirection.EAST)
|
||||
{
|
||||
x++;
|
||||
}
|
||||
else
|
||||
{
|
||||
x--;
|
||||
}
|
||||
}
|
||||
width = x; //can be negative
|
||||
if (width < 0)
|
||||
width++;
|
||||
if (width > 0)
|
||||
width--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find y size and store in this.height
|
||||
*/
|
||||
private void findCraneHeight()
|
||||
{
|
||||
int y = 1;
|
||||
while (true)
|
||||
{
|
||||
if (yCoord + y >= 256)
|
||||
break;
|
||||
if (y > CraneHelper.MAX_SIZE)
|
||||
break;
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord, yCoord + y, zCoord))
|
||||
break;
|
||||
y++;
|
||||
}
|
||||
height = y - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find x size and store in this.depth
|
||||
*/
|
||||
private void findCraneDepth()
|
||||
{
|
||||
if (height == 0)
|
||||
{
|
||||
width = 0;
|
||||
return;
|
||||
}
|
||||
int z = 0;
|
||||
ForgeDirection facing = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
|
||||
while (true)
|
||||
{
|
||||
if (Math.abs(z) > CraneHelper.MAX_SIZE)
|
||||
break;
|
||||
if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord, yCoord + height, zCoord + z))
|
||||
break;
|
||||
if (facing == ForgeDirection.SOUTH || facing == ForgeDirection.EAST)
|
||||
{
|
||||
z++;
|
||||
}
|
||||
else
|
||||
{
|
||||
z--;
|
||||
}
|
||||
}
|
||||
depth = z; //can be negative
|
||||
if (depth < 0)
|
||||
depth++;
|
||||
if (depth > 0)
|
||||
depth--;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,4 +179,24 @@ public class TileEntityCraneController extends TileEntityAssemblyNetwork impleme
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("width", width);
|
||||
nbt.setInteger("height", height);
|
||||
nbt.setInteger("depth", depth);
|
||||
nbt.setBoolean("isValid", isCraneValid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
width = nbt.getInteger("width");
|
||||
height = nbt.getInteger("height");
|
||||
depth = nbt.getInteger("depth");
|
||||
isCraneValid = nbt.getBoolean("isValid");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package assemblyline.common.machine.crane;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import assemblyline.api.ICraneConnectable;
|
||||
import assemblyline.api.ICraneStructure;
|
||||
import assemblyline.common.machine.TileEntityAssemblyNetwork;
|
||||
|
||||
public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements ICraneConnectable
|
||||
public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements ICraneStructure
|
||||
{
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue