<commit_before>package talecraft.tileentity;

import java.util.List;

import net.minecraft.nbt.NBTTagCompound;
import talecraft.blocks.TCTileEntity;
import talecraft.invoke.BlockTriggerInvoke;
import talecraft.invoke.EnumTriggerState;
import talecraft.invoke.IInvoke;
import talecraft.invoke.Invoke;

public class MemoryBlockTileEntity extends TCTileEntity {
	private IInvoke triggerInvoke;
	private boolean triggered;

	public MemoryBlockTileEntity() {
		triggerInvoke = BlockTriggerInvoke.ZEROINSTANCE;
		triggered = false;
	}

	@Override
	public void getInvokes(List<IInvoke> invokes) {
		invokes.add(triggerInvoke);
	}

	@Override
	public void getInvokeColor(float[] color) {
		color[0] = 0.25f;
		color[1] = 1.00f;
		color[2] = 0.75f;
	}

	@Override
	public String getName() {
		return "MemoryBlock@"+this.getPos();
	}

	public IInvoke getTriggerInvoke() {
		return triggerInvoke;
	}

	@Override
	public void readFromNBT_do(NBTTagCompound comp) {
		triggerInvoke = IInvoke.Serializer.read(comp.getCompoundTag("triggerInvoke"));
		triggered = comp.getBoolean("triggered");
	}

	@Override
	public NBTTagCompound writeToNBT_do(NBTTagCompound comp) {
		comp.setTag("triggerInvoke", IInvoke.Serializer.write(triggerInvoke));
		comp.setBoolean("triggered", triggered);
		return comp;
	}

	@Override
	public void commandReceived(String command, NBTTagCompound data) {
		if(command.equals("trigger")) {
			trigger(EnumTriggerState.ON);
			return;
		}

		if(command.equals("reset")) {
			triggered = false;
			world.notifyBlockUpdate(this.pos, world.getBlockState(pos), world.getBlockState(pos), 0); //TODO Confirm
			return;
		}

		// fall trough
		super.commandReceived(command, data);
	}

	public void trigger(EnumTriggerState triggerState) {
		switch(triggerState) {
			case IGNORE:
				// no op
				break;
			case INVERT:
				// reset
				if(triggered) {
					triggered = false;
					world.notifyBlockUpdate(this.pos, world.getBlockState(pos), world.getBlockState(pos), 0); //TODO Confirm
				}
				break;
			case OFF:
				// no op
				break;
			case ON:
				if(!triggered) {
					Invoke.invoke(triggerInvoke, this, null, triggerState);
					triggered = true;
					world.notifyBlockUpdate(this.pos, world.getBlockState(pos), world.getBlockState(pos), 0); //TODO Confirm
				}
				break;
			default:
				// no op
				break;
		}
		
		
	}

	public boolean getIsTriggered() {
		return triggered;
	}

}<commit_msg>Change how memory block states work, fix #48<commit_after>package talecraft.tileentity;

import java.util.List;

import net.minecraft.nbt.NBTTagCompound;
import talecraft.blocks.TCTileEntity;
import talecraft.invoke.BlockTriggerInvoke;
import talecraft.invoke.EnumTriggerState;
import talecraft.invoke.IInvoke;
import talecraft.invoke.Invoke;

public class MemoryBlockTileEntity extends TCTileEntity {
	private IInvoke triggerInvoke;
	private boolean triggered;

	public MemoryBlockTileEntity() {
		triggerInvoke = BlockTriggerInvoke.ZEROINSTANCE;
		triggered = false;
	}

	@Override
	public void getInvokes(List<IInvoke> invokes) {
		invokes.add(triggerInvoke);
	}

	@Override
	public void getInvokeColor(float[] color) {
		color[0] = 0.25f;
		color[1] = 1.00f;
		color[2] = 0.75f;
	}

	@Override
	public String getName() {
		return "MemoryBlock@"+this.getPos();
	}

	public IInvoke getTriggerInvoke() {
		return triggerInvoke;
	}

	@Override
	public void readFromNBT_do(NBTTagCompound comp) {
		triggerInvoke = IInvoke.Serializer.read(comp.getCompoundTag("triggerInvoke"));
		triggered = comp.getBoolean("triggered");
	}

	@Override
	public NBTTagCompound writeToNBT_do(NBTTagCompound comp) {
		comp.setTag("triggerInvoke", IInvoke.Serializer.write(triggerInvoke));
		comp.setBoolean("triggered", triggered);
		return comp;
	}

	@Override
	public void commandReceived(String command, NBTTagCompound data) {
		if(command.equals("trigger")) {
			trigger(EnumTriggerState.ON);
			return;
		}

		if(command.equals("reset")) {
			triggered = false;
			world.notifyBlockUpdate(this.pos, world.getBlockState(pos), world.getBlockState(pos), 0); //TODO Confirm
			return;
		}

		// fall trough
		super.commandReceived(command, data);
	}

	public void trigger(EnumTriggerState triggerState) {
		switch(triggerState) {
			case IGNORE:
				// no op
				break;
			case INVERT:
				trigger(triggered ? EnumTriggerState.OFF : EnumTriggerState.ON);
				break;
			case OFF:
				// reset
				if(triggered) {
					triggered = false;
					world.notifyBlockUpdate(this.pos, world.getBlockState(pos), world.getBlockState(pos), 0); //TODO Confirm
				}
				break;
			case ON:
				if(!triggered) {
					Invoke.invoke(triggerInvoke, this, null, triggerState);
					triggered = true;
					world.notifyBlockUpdate(this.pos, world.getBlockState(pos), world.getBlockState(pos), 0); //TODO Confirm
				}
				break;
			default:
				// no op
				break;
		}
		
		
	}

	public boolean getIsTriggered() {
		return triggered;
	}

}
{'fraction_non_alphanumeric': 0.11391889137966171, 'fraction_numerical': 0.0065212961076013855, 'mean_word_length': 4.188160676532769, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2274804', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1610, 'n_words': 324}