<commit_before>package net.geforcemods.securitycraft.api;

import java.util.ArrayList;

import net.geforcemods.securitycraft.ClientHandler;
import net.geforcemods.securitycraft.misc.ModuleType;
import net.geforcemods.securitycraft.tileentity.DisguisableTileEntity;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.geforcemods.securitycraft.util.WorldUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.util.Constants;

/**
 * Extend this class in your TileEntity to make it customizable. You will
 * be able to modify it with the various modules in SecurityCraft, and
 * have your block do different functions based on what modules are
 * inserted.
 *
 * @author Geforce
 */
public abstract class CustomizableTileEntity extends SecurityCraftTileEntity implements IModuleInventory, ICustomizable
{
	private boolean linkable = false;
	public ArrayList<LinkedBlock> linkedBlocks = new ArrayList<>();
	private ListTag nbtTagStorage = null;
	private boolean firstTick = true;
	private NonNullList<ItemStack> modules = NonNullList.<ItemStack>withSize(getMaxNumberOfModules(), ItemStack.EMPTY);

	public CustomizableTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state)
	{
		super(type, pos, state);
	}

	public static void tick(Level world, BlockPos pos, BlockState state, CustomizableTileEntity te) {
		if(te.firstTick && world.isClientSide && te instanceof DisguisableTileEntity)
		{
			te.firstTick = false;
			ClientHandler.refreshModelData(te);
		}

		SecurityCraftTileEntity.tick(world, pos, state, te);

		if(te.hasLevel() && te.nbtTagStorage != null) {
			te.readLinkedBlocks(te.nbtTagStorage);
			te.sync();
			te.nbtTagStorage = null;
		}
	}

	@Override
	public void load(CompoundTag tag)
	{
		super.load(tag);

		modules = readModuleInventory(tag);
		readOptions(tag);

		if (tag.contains("linkable"))
			linkable = tag.getBoolean("linkable");

		if (linkable && tag.contains("linkedBlocks"))
		{
			if(!hasLevel()) {
				nbtTagStorage = tag.getList("linkedBlocks", Constants.NBT.TAG_COMPOUND);
				return;
			}<commit_msg>only check for firstTick on the client<commit_after>package net.geforcemods.securitycraft.api;

import java.util.ArrayList;

import net.geforcemods.securitycraft.ClientHandler;
import net.geforcemods.securitycraft.misc.ModuleType;
import net.geforcemods.securitycraft.tileentity.DisguisableTileEntity;
import net.geforcemods.securitycraft.util.ModuleUtils;
import net.geforcemods.securitycraft.util.WorldUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.util.Constants;

/**
 * Extend this class in your TileEntity to make it customizable. You will
 * be able to modify it with the various modules in SecurityCraft, and
 * have your block do different functions based on what modules are
 * inserted.
 *
 * @author Geforce
 */
public abstract class CustomizableTileEntity extends SecurityCraftTileEntity implements IModuleInventory, ICustomizable
{
	private boolean linkable = false;
	public ArrayList<LinkedBlock> linkedBlocks = new ArrayList<>();
	private ListTag nbtTagStorage = null;
	private boolean firstTick = true;
	private NonNullList<ItemStack> modules = NonNullList.<ItemStack>withSize(getMaxNumberOfModules(), ItemStack.EMPTY);

	public CustomizableTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state)
	{
		super(type, pos, state);
	}

	public static void tick(Level world, BlockPos pos, BlockState state, CustomizableTileEntity te) {
		if(world.isClientSide && te.firstTick && te instanceof DisguisableTileEntity)
		{
			te.firstTick = false;
			ClientHandler.refreshModelData(te);
		}

		SecurityCraftTileEntity.tick(world, pos, state, te);

		if(te.hasLevel() && te.nbtTagStorage != null) {
			te.readLinkedBlocks(te.nbtTagStorage);
			te.sync();
			te.nbtTagStorage = null;
		}
	}

	@Override
	public void load(CompoundTag tag)
	{
		super.load(tag);

		modules = readModuleInventory(tag);
		readOptions(tag);

		if (tag.contains("linkable"))
			linkable = tag.getBoolean("linkable");

		if (linkable && tag.contains("linkedBlocks"))
		{
			if(!hasLevel()) {
				nbtTagStorage = tag.getList("linkedBlocks", Constants.NBT.TAG_COMPOUND);
				return;
			}
{'fraction_non_alphanumeric': 0.10370670447640268, 'fraction_numerical': 0.0, 'mean_word_length': 5.471821756225426, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '141823', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1514, 'n_words': 334}