Brush Color Setting and Changing Interaction

This commit is contained in:
Kam committed 2025-02-13 15:35:45 -05:00
1 parent bd2eb0fe16
commit 4b8e0cd8c3
11 files changed
+109 -34

No files matched your search

@@ -3,17 +3,23 @@ package noppes.npcs.items;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.constants.EnumGuiType;
import java.util.List;
@@ -23,6 +29,7 @@ public class ItemNpcTool extends Item {
// Define our tool types based on metadata:
// meta 0: Hammer, meta 1: Paintbrush, meta 2: Wrench
public static final String[] toolTypes = new String[] {"hammer", "paintbrush", "wrench"};
public static String BRUSH_COLOR_TAG = "BrushColor";
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@@ -71,23 +78,40 @@ public class ItemNpcTool extends Item {
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(!world.isRemote)
if(world.isRemote)
return stack;
if(player.isSneaking() && isPaintbrush(stack)){
} else if(isPaintbrush(stack)){
if(isPaintbrush(stack) && !player.isSneaking()){
if(CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.PAINTBRUSH_GUI)){
NoppesUtil.requestOpenGUI(EnumGuiType.Paintbrush);
}
}
if(CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.PAINTBRUSH_GUI)){
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.Paintbrush, player);
}
else
player.addChatMessage(new ChatComponentTranslation("item.npc_tool." + toolTypes[stack.getItemDamage()] + ".use"));
return stack;
}
public boolean isPaintbrush(ItemStack itemStack){
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if(isPaintbrush(stack)) {
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileColorable) {
if(player.isSneaking() && world.isRemote){
int color = ((TileColorable) tile).color;
PacketClient.sendClient(new ColorSetPacket(color));
}
else if (!world.isRemote && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.NPC_BUILD)){
int color = getColor(stack.getTagCompound());
TileColorable colorable = (TileColorable) tile;
colorable.setColor(color);
}
return true;
}
}
return false;
}
public static boolean isPaintbrush(ItemStack itemStack){
return itemStack.getItemDamage() == 1;
}
@@ -96,4 +120,18 @@ public class ItemNpcTool extends Item {
GameRegistry.registerItem(this, name);
return super.setUnlocalizedName(name);
}
public static int getColor(NBTTagCompound tagCompound){
if(tagCompound == null || !tagCompound.hasKey(BRUSH_COLOR_TAG))
return 0xFFFFFF;
return tagCompound.getInteger(BRUSH_COLOR_TAG);
}
public static int setColor(NBTTagCompound tagCompound, int color){
if(tagCompound == null || !tagCompound.hasKey(BRUSH_COLOR_TAG))
return 0xFFFFFF;
return tagCompound.getInteger(BRUSH_COLOR_TAG);
}
}