Brush Setting and Getting Packets

This commit is contained in:
Kam committed 2025-02-13 17:40:16 -05:00
1 parent 4b8e0cd8c3
commit 6193f77bf5
12 files changed
+146 -58

No files matched your search

@@ -10,7 +10,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -46,7 +45,7 @@ public class BlockBanner extends BlockContainer{
TileBanner tile = (TileBanner) par1World.getTileEntity(i, j, k);
if(tile.canEdit())
return true;
else if(TileColorable.doNotAllowModification(item))
else if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
@@ -11,7 +11,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -19,7 +18,6 @@ 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;
@@ -38,8 +36,12 @@ 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(TileColorable.doNotAllowModification(item))
TileColorable.ColorChangeType colorChangeType = TileColorable.allowColorChange(item);
if(colorChangeType == TileColorable.ColorChangeType.NONE)
return BlockChair.MountBlock(par1World, i, j, k, player);
else if(colorChangeType == TileColorable.ColorChangeType.PAINTBRUSH)
return false;
int meta = par1World.getBlockMetadata(i, j, k);
if(meta >= 7)
j--;
@@ -10,7 +10,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -40,7 +39,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(TileColorable.doNotAllowModification(item))
if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int meta = world.getBlockMetadata(x, y, z);
TileColorable tile = (TileColorable) world.getTileEntity(x, y, z);
@@ -10,7 +10,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -39,8 +38,8 @@ 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(TileColorable.doNotAllowModification(item))
return false;
if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int meta = par1World.getBlockMetadata(i, j, k);
if(meta >= 7)
j--;
@@ -10,7 +10,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -42,8 +41,8 @@ public class BlockWallBanner extends BlockContainer{
TileWallBanner tile = (TileWallBanner) par1World.getTileEntity(i, j, k);
if(tile.canEdit())
return true;
else if(TileColorable.doNotAllowModification(item))
return false;
else if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
if(tile.color != color){
@@ -7,9 +7,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
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 {
@@ -31,27 +28,22 @@ public class TileColorable extends TileVariant {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
public void changeColor(EntityPlayer player, ItemStack stack){
if(stack == null)
return;
public static ColorChangeType allowColorChange(ItemStack stack){
if(stack == null || stack.getItem() == null)
return ColorChangeType.NONE;
if(stack.getItem() == null)
return;
if(stack.getItem() == Items.dye)
return ColorChangeType.DYE;
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);
}
if(ItemNpcTool.isPaintbrush(stack))
return ColorChangeType.PAINTBRUSH;
return ColorChangeType.NONE;
}
public static boolean doNotAllowModification(ItemStack stack){
return stack == null || stack.getItem() == null ||
(stack.getItem() != Items.dye &&
!(stack.getItem() instanceof ItemNpcTool));
public enum ColorChangeType {
NONE,
DYE,
PAINTBRUSH
}
}
@@ -1,11 +1,10 @@
package noppes.npcs.client.gui.item;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
import kamkeel.npcs.network.packets.request.item.ColorBrushPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.IResource;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.GuiNpcButton;
@@ -18,8 +17,6 @@ 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;
@@ -90,7 +87,7 @@ public class GuiNpcPaintbrush extends GuiNPCInterface {
@Override
public void close(){
PacketClient.sendClient(new ColorSetPacket(this.color));
PacketClient.sendClient(new ColorBrushPacket(this.color));
super.close();
}
@@ -4,7 +4,9 @@ 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.ColorBrushPacket;
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@@ -12,12 +14,13 @@ 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.BlockBanner;
import noppes.npcs.blocks.BlockTallLamp;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.constants.EnumGuiType;
@@ -90,18 +93,26 @@ public class ItemNpcTool extends Item {
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if(!world.isRemote)
return false;
if(isPaintbrush(stack)) {
Block block = world.getBlock(x, y, z);
if(block instanceof BlockTallLamp || block instanceof BlockBanner){
int meta = world.getBlockMetadata(x, y, z);
if(meta >= 7)
y--;
}
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileColorable) {
if(player.isSneaking() && world.isRemote){
if(player.isSneaking()){
int color = ((TileColorable) tile).color;
PacketClient.sendClient(new ColorSetPacket(color));
PacketClient.sendClient(new ColorBrushPacket(color));
}
else if (!world.isRemote && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.NPC_BUILD)){
int color = getColor(stack.getTagCompound());
TileColorable colorable = (TileColorable) tile;
colorable.setColor(color);
else {
PacketClient.sendClient(new ColorSetPacket(x, y, z));
}
return true;
}