mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 19:34:09 +00:00
Brush Color Setting and Changing Interaction
This commit is contained in:
1 parent
bd2eb0fe16
commit
4b8e0cd8c3
11 files changed
+109
-34
No files matched your search
@@ -53,7 +53,7 @@ public final class GuiRequestPacket extends AbstractPacket {
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER, EnumItemPacketType.BRUSH))
|
||||
return;
|
||||
int index = in.readInt();
|
||||
int x = in.readInt();
|
||||
|
||||
@@ -9,16 +9,16 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.LinkedNpcController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
|
||||
|
||||
public final class ColorSetPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ColorSet";
|
||||
|
||||
@@ -68,7 +68,7 @@ public final class ColorSetPacket extends AbstractPacket {
|
||||
if(brushCompound == null)
|
||||
brushCompound = new NBTTagCompound();
|
||||
|
||||
brushCompound.setInteger("Color", color);
|
||||
brushCompound.setInteger(BRUSH_COLOR_TAG, color);
|
||||
brush.setTagCompound(brushCompound);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.blocks.tiles.TileBanner;
|
||||
import noppes.npcs.blocks.tiles.TileColorable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,7 +46,7 @@ public class BlockBanner extends BlockContainer{
|
||||
TileBanner tile = (TileBanner) par1World.getTileEntity(i, j, k);
|
||||
if(tile.canEdit())
|
||||
return true;
|
||||
else if(item.getItem() != Items.dye)
|
||||
else if(TileColorable.doNotAllowModification(item))
|
||||
return false;
|
||||
|
||||
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.blocks.tiles.TileColorable;
|
||||
import noppes.npcs.blocks.tiles.TileCouchWool;
|
||||
@@ -27,7 +28,7 @@ import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
|
||||
|
||||
public class BlockCouchWool extends BlockContainer{
|
||||
public class BlockCouchWool extends BlockContainer {
|
||||
|
||||
public int renderId = -1;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class BlockCouchWool extends BlockContainer{
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if(item == null || item.getItem() != Items.dye)
|
||||
if(TileColorable.doNotAllowModification(item))
|
||||
return BlockChair.MountBlock(par1World, i, j, k, player);
|
||||
int meta = par1World.getBlockMetadata(i, j, k);
|
||||
if(meta >= 7)
|
||||
|
||||
@@ -40,7 +40,7 @@ public class BlockShortLamp extends BlockContainer {
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player,
|
||||
int side, float hitX, float hitY, float hitZ) {
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if (item == null || item.getItem() != Items.dye)
|
||||
if(TileColorable.doNotAllowModification(item))
|
||||
return false;
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
TileColorable tile = (TileColorable) world.getTileEntity(x, y, z);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class BlockTallLamp extends BlockContainer {
|
||||
@Override
|
||||
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if(item == null || item.getItem() != Items.dye)
|
||||
if(TileColorable.doNotAllowModification(item))
|
||||
return false;
|
||||
int meta = par1World.getBlockMetadata(i, j, k);
|
||||
if(meta >= 7)
|
||||
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.blocks.tiles.TileColorable;
|
||||
import noppes.npcs.blocks.tiles.TileWallBanner;
|
||||
|
||||
import java.util.List;
|
||||
@@ -41,7 +42,7 @@ public class BlockWallBanner extends BlockContainer{
|
||||
TileWallBanner tile = (TileWallBanner) par1World.getTileEntity(i, j, k);
|
||||
if(tile.canEdit())
|
||||
return true;
|
||||
else if(item.getItem() != Items.dye)
|
||||
else if(TileColorable.doNotAllowModification(item))
|
||||
return false;
|
||||
|
||||
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package noppes.npcs.blocks.tiles;
|
||||
|
||||
import net.minecraft.block.BlockColored;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.items.ItemStaff;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
|
||||
|
||||
public class TileColorable extends TileVariant {
|
||||
|
||||
@@ -20,4 +24,34 @@ public class TileColorable extends TileVariant {
|
||||
super.writeToNBT(compound);
|
||||
compound.setInteger("BrushColor", color);
|
||||
}
|
||||
|
||||
public void setColor(int color){
|
||||
this.color = color;
|
||||
this.markDirty();
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
public void changeColor(EntityPlayer player, ItemStack stack){
|
||||
if(stack == null)
|
||||
return;
|
||||
|
||||
if(stack.getItem() == null)
|
||||
return;
|
||||
|
||||
if(stack.getItem() == Items.dye){
|
||||
int color = colorTableInts[BlockColored.func_150031_c(stack.getItemDamage())];
|
||||
NoppesUtilServer.consumeItemStack(1, player);
|
||||
setColor(color);
|
||||
} else if(ItemNpcTool.isPaintbrush(stack)){
|
||||
int color = colorTableInts[BlockColored.func_150031_c(stack.getItemDamage())];
|
||||
NoppesUtilServer.consumeItemStack(1, player);
|
||||
setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean doNotAllowModification(ItemStack stack){
|
||||
return stack == null || stack.getItem() == null ||
|
||||
(stack.getItem() != Items.dye &&
|
||||
!(stack.getItem() instanceof ItemNpcTool));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -17,6 +18,8 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
|
||||
|
||||
public class GuiNpcPaintbrush extends GuiNPCInterface {
|
||||
|
||||
private GuiNpcTextField textfield;
|
||||
@@ -33,9 +36,7 @@ public class GuiNpcPaintbrush extends GuiNPCInterface {
|
||||
if(brush == null)
|
||||
return;
|
||||
|
||||
NBTTagCompound compound = brush.getTagCompound();
|
||||
if(compound != null && compound.hasKey("Color"))
|
||||
color = compound.getInteger("Color");
|
||||
color = ItemNpcTool.getColor(brush.getTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,8 @@ import noppes.npcs.items.ItemRenderInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
|
||||
|
||||
public class NpcItemToolRenderer implements IItemRenderer {
|
||||
|
||||
// Textures for the assembled paintbrush parts:
|
||||
@@ -53,7 +55,7 @@ public class NpcItemToolRenderer implements IItemRenderer {
|
||||
|
||||
/**
|
||||
* Renders the paintbrush by drawing its handle first, then overlaying the brush part tinted
|
||||
* by the NBT "Color" value (an integer/hex value).
|
||||
* by the NBT "BrushColor" value (an integer/hex value).
|
||||
*/
|
||||
private void renderPaintbrush(EntityLivingBase entity, ItemStack item) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
@@ -71,10 +73,7 @@ public class NpcItemToolRenderer implements IItemRenderer {
|
||||
ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, width, height, thickness);
|
||||
|
||||
// Get the NBT color (default is white if not present)
|
||||
int color = 0xFFFFFF;
|
||||
if (item.hasTagCompound() && item.getTagCompound().hasKey("Color")) {
|
||||
color = item.getTagCompound().getInteger("Color");
|
||||
}
|
||||
int color = ItemNpcTool.getColor(item.getTagCompound());
|
||||
float red = ((color >> 16) & 0xFF) / 255.0F;
|
||||
float green = ((color >> 8) & 0xFF) / 255.0F;
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user