/*
 * Aeronica's mxTune MOD
 * Copyright 2019, Paul Boese a.k.a. Aeronica
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package net.aeronica.mods.mxtune.network.server;

import net.aeronica.mods.mxtune.network.AbstractMessage.AbstractServerMessage;
import net.aeronica.mods.mxtune.options.MusicOptionsUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.relauncher.Side;

public class ChunkToolMessage extends AbstractServerMessage<ChunkToolMessage>
{
    private Operation operation;

    @SuppressWarnings("unused")
    public ChunkToolMessage() {/* Required by the PacketDispatcher */}

    public ChunkToolMessage(Operation operation)
    {
        this.operation = operation;
    }
    
    @Override
    protected void read(PacketBuffer buffer)
    {
        operation = buffer.readEnumValue(Operation.class);
    }

    @Override
    protected void write(PacketBuffer buffer)
    {
        buffer.writeEnumValue(operation);
    }

    @Override
    public void process(EntityPlayer player, Side side)
    {
        if (MusicOptionsUtil.isMxTuneServerUpdateAllowed(player))
        {
            switch (operation)
            {
                case NOP:
                    break;
                case START:
                    break;
                case END:
                    break;
                case DO_IT:
                    break;
                default:
            }
        }
    }

    public enum Operation
    {
        NOP, START, END, DO_IT
    }
}

@@ -921,24 +921,98 @@
 cketBuffer;%0A
+import net.minecraft.world.World;%0Aimport net.minecraft.world.chunk.Chunk;%0A
 import net.m
@@ -1139,35 +1139,29 @@
 private 
-Operation operation
+boolean reset
 ;%0A%0A    @
@@ -1291,27 +1291,21 @@
 age(
-Operation operation
+boolean reset
 )%0A  
@@ -1325,29 +1325,21 @@
 his.
-operation = operation
+reset = reset
 ;%0A  
@@ -1420,25 +1420,21 @@
         
-operation
+reset
  = buffe
@@ -1443,33 +1443,16 @@
 read
-EnumValue(Operation.class
+Boolean(
 );%0A 
@@ -1547,27 +1547,21 @@
 rite
-EnumValue(operation
+Boolean(reset
 );%0A 
@@ -1710,32 +1710,296 @@
 yer))%0A        %7B%0A
+            World world = player.world;%0A            Chunk chunk = world.getChunk(player.getPosition());%0A            Operation operation = reset ? Operation.RESET : MusicOptionsUtil.getChunkToolOperation(player);%0A            if (chunk.isLoaded())%0A            %7B%0A    
             swit
@@ -2017,34 +2017,40 @@
 on)%0A            
-%7B%0A
+    %7B%0A  
                 
@@ -2053,16 +2053,20 @@
     
+  
 case 
-NOP
+START
 :%0A  
@@ -2087,43 +2087,150 @@
     
-break;%0A                case START:%0A
+    MusicOptionsUtil.setChunkStart(player, chunk);%0A                        MusicOptionsUtil.setChunkToolOperation(player, Operation.END);%0A    
     
@@ -2264,24 +2264,28 @@
             
+ 
+   
 case END:%0A  
@@ -2306,94 +2306,515 @@
     
-break;%0A                case DO_IT:%0A                    break;%0A                default:
+    MusicOptionsUtil.setChunkEnd(player, chunk);%0A                        MusicOptionsUtil.setChunkToolOperation(player, Operation.DO_IT);%0A                        break;%0A                    case DO_IT:%0A%0A                    case RESET:%0A                    default:%0A                        MusicOptionsUtil.setChunkToolOperation(player, Operation.START);%0A                        MusicOptionsUtil.setChunkStart(player, null);%0A                        MusicOptionsUtil.setChunkEnd(player, null);%0A                %7D
 %0A   
@@ -2884,13 +2884,8 @@
     
- NOP,
  STA
@@ -2892,16 +2892,23 @@
 RT, END,
+ RESET,
  DO_IT%0A 

Use MusicOption (player capability) to store chunk tool data and state.