mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-10-26 14:24:33 +00:00
Added network plumbing to discriminate left-clicks
This commit is contained in:
1 parent
5fcd910d67
commit
b164248b68
5 files changed
+122
-1
No files matched your search
@@ -2,11 +2,15 @@ package com.jaquadro.minecraft.storagedrawers;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.core.CommonProxy;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
@Mod(modid = StorageDrawers.MOD_ID, name = StorageDrawers.MOD_NAME, version = StorageDrawers.MOD_VERSION)
|
||||
public class StorageDrawers
|
||||
@@ -18,6 +22,8 @@ public class StorageDrawers
|
||||
|
||||
public static final ModBlocks blocks = new ModBlocks();
|
||||
|
||||
public static SimpleNetworkWrapper network;
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static StorageDrawers instance;
|
||||
|
||||
@@ -26,6 +32,9 @@ public class StorageDrawers
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit (FMLPreInitializationEvent event) {
|
||||
network = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID);
|
||||
network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER);
|
||||
|
||||
blocks.init();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,24 @@ package com.jaquadro.minecraft.storagedrawers.block;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ClientProxy;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockDrawers extends BlockContainer
|
||||
public class BlockDrawers extends BlockContainer implements IExtendedBlockClickHandler
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon iconSide;
|
||||
@@ -93,6 +96,33 @@ public class BlockDrawers extends BlockContainer
|
||||
return countAdded > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockClicked (World world, int x, int y, int z, EntityPlayer player) {
|
||||
if (world.isRemote) {
|
||||
MovingObjectPosition posn = Minecraft.getMinecraft().objectMouseOver;
|
||||
float hitX = (float)(posn.hitVec.xCoord - posn.blockX);
|
||||
float hitY = (float)(posn.hitVec.yCoord - posn.blockY);
|
||||
float hitZ = (float)(posn.hitVec.zCoord - posn.blockZ);
|
||||
|
||||
StorageDrawers.network.sendToServer(new BlockClickMessage(x, y, z, posn.sideHit, hitX, hitY, hitZ));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockClicked (World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
x += y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer (World world, EntityPlayer player, int x, int y, int z) {
|
||||
if (player.capabilities.isCreativeMode && !player.isSneaking()) {
|
||||
onBlockClicked(world, x, y, z, player);
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityDrawers createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityDrawers();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IExtendedBlockClickHandler
|
||||
{
|
||||
public void onBlockClicked (World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ);
|
||||
}
|
||||
+3
@@ -34,6 +34,9 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
private double itemOffset2X[] = new double[] { .5, .5 };
|
||||
private double itemOffset2Y[] = new double[] { 10.25, 2.25 };
|
||||
|
||||
private double itemOffset4X[] = new double[] { .25, .25, .75, .75 };
|
||||
private double itemOffset4Y[] = new double[] { 10.25, 2.25, 10.25, 2.25 };
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt (TileEntity tile, double x, double y, double z, float partialTickTime) {
|
||||
TileEntityDrawers tileDrawers = (TileEntityDrawers) tile;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.network;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.IExtendedBlockClickHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockClickMessage implements IMessage
|
||||
{
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int side;
|
||||
private float hitX;
|
||||
private float hitY;
|
||||
private float hitZ;
|
||||
|
||||
public BlockClickMessage () { }
|
||||
|
||||
public BlockClickMessage (int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.side = side;
|
||||
this.hitX = hitX;
|
||||
this.hitY = hitY;
|
||||
this.hitZ = hitZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes (ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readShort();
|
||||
z = buf.readInt();
|
||||
side = buf.readByte();
|
||||
hitX = buf.readByte() / 16f;
|
||||
hitY = buf.readByte() / 16f;
|
||||
hitZ = buf.readByte() / 16f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes (ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeShort(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeByte(side);
|
||||
buf.writeByte((int)(hitX * 16));
|
||||
buf.writeByte((int)(hitY * 16));
|
||||
buf.writeByte((int)(hitZ * 16));
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<BlockClickMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage (BlockClickMessage message, MessageContext ctx) {
|
||||
if (ctx.side == Side.SERVER) {
|
||||
World world = ctx.getServerHandler().playerEntity.getEntityWorld();
|
||||
Block block = world.getBlock(message.x, message.y, message.z);
|
||||
if (block instanceof IExtendedBlockClickHandler)
|
||||
((IExtendedBlockClickHandler) block).onBlockClicked(world, message.x, message.y, message.z, ctx.getServerHandler().playerEntity, message.side, message.hitX, message.hitY, message.hitZ);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user