Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MessageTrafficBox implements IMessage, IMessageHandler<MessageTrafficBox, IMessage> {
- public int x,y,z;
- private int timeBetweenEachSequence, timeForEachSequence;
- private List<Sequence> sequences;
- private List<BlockPos> lights;
- public MessageTrafficBox() {
- }
- public MessageTrafficBox(int x, int y, int z, int timeBetweenEachSequence, int timeForEachSequence, List<BlockPos> lights, List<Sequence> sequences) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.timeBetweenEachSequence = timeBetweenEachSequence;
- this.timeForEachSequence = timeForEachSequence;
- this.lights = lights;
- this.sequences = sequences;
- }
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeInt(x);
- buf.writeInt(y);
- buf.writeInt(z);
- buf.writeInt(timeBetweenEachSequence);
- buf.writeInt(timeForEachSequence);
- NBTTagCompound compound = new NBTTagCompound();
- NBTTagList tagList = new NBTTagList();
- lights.forEach(blockPos -> tagList.appendTag(new NBTTagLong(blockPos.toLong())));
- compound.setTag("lights", tagList);
- NBTTagList tagList2 = new NBTTagList();
- sequences.forEach(sequence -> tagList2.appendTag(new NBTTagString(sequence.toString())));
- compound.setTag("sequences", tagList2);
- ByteBufUtils.writeTag(buf, compound);
- }
- @Override
- public void fromBytes(ByteBuf buf) {
- this.x = buf.readInt();
- this.y = buf.readInt();
- this.z = buf.readInt();
- this.timeBetweenEachSequence = buf.readInt();
- this.timeForEachSequence = buf.readInt();
- NBTTagCompound compound = ByteBufUtils.readTag(buf);
- sequences = new ArrayList<>();
- lights = new ArrayList<>();
- if(compound.hasKey("lights",Constants.NBT.TAG_LIST)){
- lights.clear();
- NBTTagList tagList = compound.getTagList("lights", Constants.NBT.TAG_LONG);
- for (NBTBase nbtBase : tagList) {
- lights.add(BlockPos.fromLong(((NBTTagLong) nbtBase).getLong()));
- }
- }
- if(compound.hasKey("sequences",Constants.NBT.TAG_LIST)){
- sequences.clear();
- NBTTagList tagList = compound.getTagList("sequences", Constants.NBT.TAG_STRING);
- for (NBTBase nbtBase : tagList) {
- sequences.add(Sequence.fromString(((NBTTagString) nbtBase).getString(), lights));
- }
- }
- }
- @Override
- public IMessage onMessage(MessageTrafficBox message, MessageContext ctx) {
- World world = ctx.getServerHandler().player.world;
- BlockPos pos = new BlockPos(message.x, message.y, message.z);
- TileEntity tileEntity = world.getTileEntity(pos);
- if(tileEntity instanceof TileEntityTrafficBox) {
- TileEntityTrafficBox trafficBox = (TileEntityTrafficBox) tileEntity;
- trafficBox.setLights(message.lights);
- trafficBox.setSequences(message.sequences);
- trafficBox.setTimeBetweenEachSequence(message.timeBetweenEachSequence);
- trafficBox.setTimeForEachSequence(message.timeForEachSequence);
- TileEntityUtil.markBlockForUpdate(world, pos);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement