Update UE

This commit is contained in:
Aidan Brady 2013-12-13 17:15:53 -05:00
parent 85a2c981df
commit 7555fbee7c
2 changed files with 65 additions and 118 deletions

View file

@ -1,64 +0,0 @@
package universalelectricity.prefab;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.ChunkEvent;
import universalelectricity.core.block.INetworkConnection;
/**
* A helper class to register chunk loading for your wires if you need them to be refreshed upon
* chunk load. This prevents the need for your wire to be refreshed.
*
* @author Calclavia, Aidancbrady
*
*/
public class ConductorChunkInitiate
{
private static boolean onChunkLoadRegistered = false;
/**
* Registers and initiates Universal Electricity's network loader.
*/
public static void register()
{
if (!onChunkLoadRegistered)
{
try
{
MinecraftForge.EVENT_BUS.register(new ConductorChunkInitiate());
onChunkLoadRegistered = true;
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
@ForgeSubscribe
public void onChunkLoad(ChunkEvent.Load event)
{
if (event.getChunk() != null)
{
Collection<?> collection = new ArrayList();
collection.addAll(event.getChunk().chunkTileEntityMap.values());
for (Object obj : collection)
{
if (obj instanceof TileEntity)
{
TileEntity tileEntity = (TileEntity) obj;
if (tileEntity instanceof INetworkConnection)
{
((INetworkConnection) tileEntity).refresh();
}
}
}
}
}
}

View file

@ -8,70 +8,81 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
/** A block that can rotate based on placed position and wrenching. /**
* * A block that can rotate based on placed position and wrenching.
* @author Calclavia */ *
* @author Calclavia
*/
public abstract class BlockRotatable extends BlockTile implements IRotatableBlock public abstract class BlockRotatable extends BlockTile implements IRotatableBlock
{ {
public BlockRotatable(int id, Material material) protected byte rotationMask = 60;
{
super(id, material);
}
@Override public BlockRotatable(int id, Material material)
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
{ super(id, material);
int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; }
int change = 3;
switch (angle) @Override
{ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
case 0: {
change = 2; int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
break; int change = 3;
case 1: switch (angle)
change = 5; {
break; case 0:
change = 2;
break;
case 2: case 1:
change = 3; change = 5;
break; break;
case 3: case 2:
change = 4; change = 3;
break; break;
}
world.setBlockMetadataWithNotify(x, y, z, change, 3); case 3:
} change = 4;
break;
}
@Override world.setBlockMetadataWithNotify(x, y, z, change, 3);
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) }
{
this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side));
return true;
}
public static boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis, int mask) @Override
{ public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
int rotMeta = worldObj.getBlockMetadata(x, y, z); {
int masked = rotMeta & ~mask; return this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side));
ForgeDirection orientation = ForgeDirection.getOrientation(rotMeta & mask); }
ForgeDirection rotated = orientation.getRotation(axis);
worldObj.setBlockMetadataWithNotify(x, y, z, rotated.ordinal() & mask | masked, 3);
return true;
}
@Override @Override
public ForgeDirection getDirection(World world, int x, int y, int z) public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis)
{ {
return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); int currentRotMeta = worldObj.getBlockMetadata(x, y, z);
} ForgeDirection orientation = ForgeDirection.getOrientation(currentRotMeta);
ForgeDirection rotated = orientation.getRotation(axis);
int rmeta = rotated.ordinal();
int rmetaBit = 1 << rmeta;
System.out.println(rmetaBit + ": " + (rmetaBit & this.rotationMask));
if ((rmetaBit & this.rotationMask) == rmetaBit)
{
worldObj.setBlockMetadataWithNotify(x, y, z, rmeta, 3);
return true;
}
@Override return false;
public void setDirection(World world, int x, int y, int z, ForgeDirection direction) }
{
world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3); @Override
} public ForgeDirection getDirection(World world, int x, int y, int z)
{
return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
}
@Override
public void setDirection(World world, int x, int y, int z, ForgeDirection direction)
{
world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3);
}
} }