added multi-block code from old UE
This commit is contained in:
parent
eac9b1ee8c
commit
bbcc18dd9c
4 changed files with 318 additions and 0 deletions
134
src/minecraft/dark/library/machine/BlockMulti.java
Normal file
134
src/minecraft/dark/library/machine/BlockMulti.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
package dark.library.machine;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockMulti extends BlockContainer
|
||||
{
|
||||
public String textureName = null;
|
||||
public String channel = "";
|
||||
|
||||
public BlockMulti(int id)
|
||||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
this.setHardness(0.8F);
|
||||
this.setUnlocalizedName("multiBlock");
|
||||
}
|
||||
|
||||
public BlockMulti setChannel(String channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockMulti setTextureName(String name)
|
||||
{
|
||||
this.textureName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock)
|
||||
{
|
||||
worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this.blockID);
|
||||
((TileEntityMulti) worldObj.getBlockTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IconRegister iconRegister)
|
||||
{
|
||||
if (this.textureName != null)
|
||||
{
|
||||
this.blockIcon = iconRegister.registerIcon(this.textureName);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.registerIcons(iconRegister);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileEntityMulti)
|
||||
{
|
||||
((TileEntityMulti) tileEntity).onBlockRemoval();
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
}
|
||||
|
||||
/** Called when the block is right clicked by the player. This modified version detects electric
|
||||
* items and wrench actions on your machine block. Do not override this function. Use
|
||||
* machineActivated instead! (It does the same thing) */
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
|
||||
{
|
||||
TileEntityMulti tileEntity = (TileEntityMulti) par1World.getBlockTileEntity(x, y, z);
|
||||
return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer);
|
||||
}
|
||||
|
||||
/** Returns the quantity of items to drop on block destruction. */
|
||||
@Override
|
||||
public int quantityDropped(Random par1Random)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return new TileEntityMulti(this.channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z)
|
||||
{
|
||||
TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z);
|
||||
Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition;
|
||||
|
||||
if (mainBlockPosition != null)
|
||||
{
|
||||
int mainBlockID = par1World.getBlockId(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
|
||||
|
||||
if (mainBlockID > 0)
|
||||
{
|
||||
return Block.blocksList[mainBlockID].getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
17
src/minecraft/dark/library/machine/IBlockActivate.java
Normal file
17
src/minecraft/dark/library/machine/IBlockActivate.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package dark.library.machine;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
* A general interface to be implemented by anything that needs it.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IBlockActivate
|
||||
{
|
||||
/**
|
||||
* Called when activated
|
||||
*/
|
||||
public boolean onActivated(EntityPlayer entityPlayer);
|
||||
}
|
28
src/minecraft/dark/library/machine/IMultiBlock.java
Normal file
28
src/minecraft/dark/library/machine/IMultiBlock.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package dark.library.machine;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
/**
|
||||
* Interface to be applied to tile entity blocks that occupies more than one block space. Useful for
|
||||
* large machines.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public interface IMultiBlock extends IBlockActivate
|
||||
{
|
||||
/**
|
||||
* Called when this multiblock is created
|
||||
*
|
||||
* @param placedPosition - The position the block was placed at
|
||||
*/
|
||||
public void onCreate(Vector3 placedPosition);
|
||||
|
||||
/**
|
||||
* Called when one of the multiblocks of this block is destroyed
|
||||
*
|
||||
* @param callingBlock - The tile entity who called the onDestroy function
|
||||
*/
|
||||
public void onDestroy(TileEntity callingBlock);
|
||||
}
|
139
src/minecraft/dark/library/machine/TileEntityMulti.java
Normal file
139
src/minecraft/dark/library/machine/TileEntityMulti.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
package dark.library.machine;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
/** This is a multiblock to be used for blocks that are bigger than one block.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class TileEntityMulti extends TileEntity implements IPacketReceiver
|
||||
{
|
||||
// The the position of the main block
|
||||
public Vector3 mainBlockPosition;
|
||||
public String channel;
|
||||
|
||||
public TileEntityMulti()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TileEntityMulti(String channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public void setMainBlock(Vector3 mainBlock)
|
||||
{
|
||||
this.mainBlockPosition = mainBlock;
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
if (this.mainBlockPosition != null)
|
||||
{
|
||||
if (this.channel == null || this.channel == "" && this.getBlockType() instanceof BlockMulti)
|
||||
{
|
||||
this.channel = ((BlockMulti) this.getBlockType()).channel;
|
||||
}
|
||||
|
||||
return PacketManager.getPacket(this.channel, this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onBlockRemoval()
|
||||
{
|
||||
if (this.mainBlockPosition != null)
|
||||
{
|
||||
TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
|
||||
|
||||
if (tileEntity != null && tileEntity instanceof IMultiBlock)
|
||||
{
|
||||
IMultiBlock mainBlock = (IMultiBlock) tileEntity;
|
||||
|
||||
if (mainBlock != null)
|
||||
{
|
||||
mainBlock.onDestroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
|
||||
{
|
||||
if (this.mainBlockPosition != null)
|
||||
{
|
||||
TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity instanceof IMultiBlock)
|
||||
{
|
||||
return ((IMultiBlock) tileEntity).onActivated(par5EntityPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Reads a tile entity from NBT. */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
this.mainBlockPosition = Vector3.readFromNBT(nbt.getCompoundTag("mainBlockPosition"));
|
||||
}
|
||||
|
||||
/** Writes a tile entity to NBT. */
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
if (this.mainBlockPosition != null)
|
||||
{
|
||||
nbt.setCompoundTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
/** Determines if this TileEntity requires update calls.
|
||||
*
|
||||
* @return True if you want updateEntity() to be called, false if not */
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.mainBlockPosition = new Vector3(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue