<commit_before>package de.nedelosk.modularmachines.api.modules.handlers.energy;

import java.util.List;

import de.nedelosk.modularmachines.api.energy.IEnergyBuffer;
import de.nedelosk.modularmachines.api.modules.handlers.IModuleContentHandler;
import de.nedelosk.modularmachines.api.modules.state.IModuleState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.util.INBTSerializable;

public class ModuleEnergyBuffer implements IEnergyBuffer, IModuleContentHandler, INBTSerializable<NBTTagCompound>{

	protected final IModuleState state;
	protected final long capacity;
	protected final long maxReceive;
	protected final long maxExtract;
	protected final int tier;
	protected long energy;

	public ModuleEnergyBuffer(IModuleState state, int capacity, int tier) {
		this(state, capacity, capacity, capacity, tier);
	}

	public ModuleEnergyBuffer(IModuleState state, int capacity, int maxTransfer, int tier) {
		this(state, capacity, maxTransfer, maxTransfer, tier);
	}

	public ModuleEnergyBuffer(IModuleState state, int capacity, int maxReceive, int maxExtract, int tier) {
		this.state = state;
		this.tier = tier;
		this.capacity = capacity;
		this.maxReceive = maxReceive;
		this.maxExtract = maxExtract;
	}

	@Override
	public void setEnergy(long energy) {
		this.energy = energy;

		if (this.energy > capacity) {
			this.energy = capacity;
		} else if (this.energy < 0) {
			this.energy = 0;
		}
	}

	@Override
	public long receiveEnergy(IModuleState state, EnumFacing facing, long maxReceive, boolean simulate) {
		long energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));

		if (!simulate) {
			energy += energyReceived;
		}
		return energyReceived;
	}

	@Override
	public long extractEnergy(IModuleState state, EnumFacing facing, long maxExtract, boolean simulate) {
		long energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));

		if (!simulate) {
			energy -= energyExtracted;
		}
		return energyExtracted;
	}

	@Override
	public long getEnergyStored() {
		return energy;
	}

	@Override
	public long getCapacity() {
		return capacity;
	}

	@Override
	public int getTier() {
		return tier;
	}

	@Override
	public NBTTagCompound serializeNBT() {
		NBTTagCompound nbt = new NBTTagCompound();
		if (energy < 0) {
			energy = 0;
		}
		nbt.setLong("Energy", energy);
		return nbt;
	}

	@Override
	public void deserializeNBT(NBTTagCompound nbt) {
		this.energy = nbt.getLong("Energy");

		if (energy > capacity) {
			energy = capacity;
		}
	}

	@Override
	public IModuleState getModuleState() {
		return state;
	}

	@Override
	public String getUID() {
		return "EnergyBuffer";
	}

	@Override
	public void addToolTip(List<String> tooltip, ItemStack stack, IModuleState state) {
	}
}<commit_msg>Fix EnergyBuffer<commit_after>package de.nedelosk.modularmachines.api.modules.handlers.energy;

import java.util.List;

import de.nedelosk.modularmachines.api.energy.IEnergyBuffer;
import de.nedelosk.modularmachines.api.modules.handlers.IModuleContentHandler;
import de.nedelosk.modularmachines.api.modules.state.IModuleState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.util.INBTSerializable;

public class ModuleEnergyBuffer implements IEnergyBuffer, IModuleContentHandler, INBTSerializable<NBTTagCompound>{

	protected final IModuleState state;
	protected final long capacity;
	protected final long maxReceive;
	protected final long maxExtract;
	protected final int tier;
	protected long energy;

	public ModuleEnergyBuffer(IModuleState state, int capacity, int tier) {
		this(state, capacity, capacity, capacity, tier);
	}

	public ModuleEnergyBuffer(IModuleState state, int capacity, int maxTransfer, int tier) {
		this(state, capacity, maxTransfer, maxTransfer, tier);
	}

	public ModuleEnergyBuffer(IModuleState state, int capacity, int maxReceive, int maxExtract, int tier) {
		this.state = state;
		this.tier = tier;
		this.capacity = capacity;
		this.maxReceive = maxReceive;
		this.maxExtract = maxExtract;
	}

	@Override
	public void setEnergy(long energy) {
		this.energy = energy;

		if (this.energy > capacity) {
			this.energy = capacity;
		} else if (this.energy < 0) {
			this.energy = 0;
		}
	}

	@Override
	public long receiveEnergy(IModuleState state, EnumFacing facing, long maxReceive, boolean simulate) {
		long energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));

		if (!simulate) {
			energy += energyReceived;
		}
		return energyReceived;
	}

	@Override
	public long extractEnergy(IModuleState state, EnumFacing facing, long maxExtract, boolean simulate) {
		long energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));

		if (!simulate) {
			energy -= energyExtracted;
		}
		return energyExtracted;
	}

	@Override
	public long getEnergyStored() {
		return energy;
	}

	@Override
	public long getCapacity() {
		return capacity;
	}

	@Override
	public int getTier() {
		return tier;
	}

	@Override
	public NBTTagCompound serializeNBT() {
		NBTTagCompound nbt = new NBTTagCompound();
		if (energy < 0) {
			energy = 0;
		}
		nbt.setLong("Energy", energy);
		return nbt;
	}

	@Override
	public void deserializeNBT(NBTTagCompound nbt) {
		this.energy = nbt.getLong("Energy");

		if (energy > capacity) {
			energy = capacity;
		}
	}

	@Override
	public IModuleState getModuleState() {
		return state;
	}

	@Override
	public String getUID() {
		return "EnergyBuffer";
	}

	@Override
	public void addToolTip(List<String> tooltip, ItemStack stack, IModuleState state) {
	}

	@Override
	public boolean canExtract() {
		return true;
	}

	@Override
	public boolean canReceive() {
		return true;
	}
}
{'fraction_non_alphanumeric': 0.09826490293763958, 'fraction_numerical': 0.001374334306820134, 'mean_word_length': 4.707843137254902, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1378665', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1874, 'n_words': 465}