add redstone controls

This commit is contained in:
Raoul Van den Berge
2015-12-18 15:10:38 +01:00
parent 8bf0f66530
commit 2bae408c59
23 changed files with 376 additions and 98 deletions

View File

@@ -0,0 +1,60 @@
package storagecraft.network;
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 io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import storagecraft.tile.RedstoneMode;
import storagecraft.tile.TileMachine;
public class MessageRedstoneModeUpdate implements IMessage, IMessageHandler<MessageRedstoneModeUpdate, IMessage> {
private int x;
private int y;
private int z;
public MessageRedstoneModeUpdate() {
}
public MessageRedstoneModeUpdate(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
}
@Override
public IMessage onMessage(MessageRedstoneModeUpdate message, MessageContext context) {
EntityPlayerMP player = context.getServerHandler().playerEntity;
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
if (tile instanceof TileMachine) {
TileMachine machine = (TileMachine) tile;
int id = machine.getRedstoneMode().id + 1;
if (RedstoneMode.getById(id) == null) {
id = 0;
}
machine.setRedstoneMode(RedstoneMode.getById(id));
}
return null;
}
}