@Override public void render(Item item, ItemStack stack, Tessellator tessellator, BufferBuilder buffer, double partialTick, BlockPos playerPos, EntityPlayerSP player, WorldClient world) { EnumArt painting = EnumArt.valueOf(stack.getTagCompound().getString("art")); RayTraceResult result = player.rayTrace(5, (float)partialTick); if(result.typeOfHit == Type.BLOCK){ BlockPos pos = result.getBlockPos(); EnumFacing facing = result.sideHit; if(!facing.getAxis().isHorizontal())return; EntityPainting ent = new EntityPainting(world, pos.offset(facing.getOpposite(), 1), facing); ent.art = painting; GlStateManager.enableBlend(); GL11.glColor4f(1f, 1f, 1f, 0.5f); double xMove = 0; if(facing.getFrontOffsetX() == 0)xMove = (painting.sizeX != 32 ? painting.sizeX >= 48 ? -painting.sizeX/16/8 : 0.5 : 0); double zMove = 0; if(facing.getFrontOffsetZ() == 0)zMove = (painting.sizeX != 32 ? painting.sizeX >= 48 ? -painting.sizeX/16/8 : 0.5 : 0); if(painting.sizeX == 16){ if(facing.getOpposite() == EnumFacing.EAST)zMove -= 1; if(facing.getOpposite() == EnumFacing.NORTH)xMove -= 1; } double yMove = (painting.sizeY == 16 || painting.sizeY == 16*3 ? 0 : 0.5); RENDER.doRender(ent, ent.posX + facing.getFrontOffsetX()*2 + xMove, ent.posY + yMove, ent.posZ + facing.getFrontOffsetZ()*2 + zMove, ent.rotationYaw, (float)partialTick); } }
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); BlockPos blockpos = pos.offset(facing); if (facing != EnumFacing.DOWN && facing != EnumFacing.UP && player.canPlayerEdit(blockpos, facing, stack)){ EntityPainting painting = new EntityPainting(worldIn, blockpos, facing); if (painting != null && painting.onValidSurface()){ if (!worldIn.isRemote){ painting.playPlaceSound(); painting.art = EnumArt.valueOf(stack.getTagCompound().getString("art")); worldIn.spawnEntity(painting); } } return EnumActionResult.SUCCESS; } else{ return EnumActionResult.FAIL; } }
/** * Sets the art for a painting at location x/y/z and sends a packet to update players. * @param direction Use the value returned from the setHangingEntity method * @return false if 'name' didn't match any EnumArt values. */ public static final boolean setPaintingArt(World world, String name, int x, int y, int z, int direction) { List<EntityPainting> paintings = world.getEntitiesWithinAABB(EntityPainting.class, getHangingEntityAxisAligned(x, y, z, direction)); if (paintings != null && !paintings.isEmpty() && name.length() > 0) { for (EntityPainting toEdit : paintings) { EnumArt[] aenumart = EnumArt.values(); int i1 = aenumart.length; for (int j1 = 0; j1 < i1; ++j1) { EnumArt enumart = aenumart[j1]; if (enumart.title.equals(name)) { toEdit.art = enumart; // TODO PacketDispatcher.sendPacketToAllAround(x, y, z, 64, world.provider.dimensionId, new Packet25EntityPainting(toEdit)); return true; } } LogHelper.warning(name + " does not match any values in EnumArt; unable to set painting art."); } } LogHelper.warning("No EntityPainting was found at " + x + "/" + y + "/" + z); return false; }
@Override public void onClientPacket(EntityPlayer player, PaintingPacket packet) { if(packet.id == -1) { //What painting is selected? MovingObjectPosition pos = Minecraft.getMinecraft().objectMouseOver; if (pos != null && pos.entityHit instanceof EntityPainting) PaintingSelectionMod.DISPATCHER.sendToServer(new PaintingPacket(pos.entityHit.getEntityId(), new String[0])); else player.addChatMessage(new ChatComponentText(PaintingSelectionMod.COLOR + "cError - No painting selected")); } else if (packet.art.length == 1) { //Set Painting EnumArt enumArt = getEnumArt(packet.art[0]); Entity e = player.worldObj.getEntityByID(packet.id); if (e instanceof EntityPainting) setPaintingArt((EntityPainting)e, enumArt); } else { //Show art GUI Minecraft mc = Minecraft.getMinecraft(); if (mc.currentScreen == null) mc.displayGuiScreen(new PaintingSelectionScreen(packet.art, packet.id)); } }
@Override public Art getArt() { for(EnumArt art : EnumArt.values()) { if(art.title.equals(title)) return (Art)(Object)art; } return Arts.KEBAB; }
@Override public void addInformation(ItemStack stack, World player, List<String> tooltip, ITooltipFlag advanced) { if(!stack.hasTagCompound())return; EnumArt painting = EnumArt.valueOf(stack.getTagCompound().getString("art")); tooltip.add("Painting: " + painting.title); tooltip.add("Size: " + painting.sizeX/16 + "x" + painting.sizeY/16); }
@Override public void onUpdate(ItemStack stack, World world, Entity entityIn, int itemSlot, boolean isSelected) { if(world.isRemote)return; if(stack.hasTagCompound())return; NBTTagCompound tag = new NBTTagCompound(); tag.setString("art", EnumArt.KEBAB.name()); stack.setTagCompound(tag); }
@Override public void trigger(World world, EntityPlayerMP player, ItemStack stack) { if(world.isRemote) return; int current = EnumArt.valueOf(stack.getTagCompound().getString("art")).ordinal(); current++; if(current >= EnumArt.values().length)current = 0; EnumArt art = EnumArt.values()[current]; stack.getTagCompound().setString("art", art.name()); player.sendMessage(new TextComponentString("Changed painting to " + TextFormatting.GOLD + art.title + TextFormatting.GREEN + " (" + art.sizeX/16 + "x" + art.sizeY/16 + ")")); }
@Override public String execute(CommandSender sender, String[] params) throws CommandException { Entity entity = getSenderAsEntity(sender.getMinecraftISender(), Entity.class); boolean sneaking = entity.isSneaking(); Entity hit = EntityUtils.traceEntity(entity, 128.0D); if (!(hit instanceof EntityPainting) || hit.isDead) throw new CommandException("command.cyclepainting.noPainting", sender); EntityPainting picture = (EntityPainting) hit; EntityPainting newPicture = new EntityPainting(picture.world, picture.getHangingPosition(), picture.facingDirection); EnumArt oldArt = picture.art; int current = 0; List<EnumArt> arts = new ArrayList<EnumArt>(); EnumArt[] all = EnumArt.values(); for (int i = 0; i < all.length; ++i) { arts.add(all[i]); if (oldArt == all[i]) current = i; } if (arts.size() <= 1) { newPicture.art = oldArt; entity.world.removeEntity(picture); entity.world.spawnEntity(newPicture); throw new CommandException("command.cyclepainting.noMoreArts", sender); } int newArt = sneaking ? (current == 0 ? arts.size() - 1 : current - 1) : (current == arts.size() - 1 ? 0 : current + 1); newPicture.art = arts.get(newArt); entity.world.removeEntity(picture); entity.world.spawnEntity(newPicture); return null; }
@Override public int compare(EnumArt a, EnumArt b) { if (a.sizeY > b.sizeY) return -1; if (a.sizeY < b.sizeY) return 1; return b.sizeX - a.sizeX; }
@Override protected void createGui() { scrollbar = new ScrollbarVanilla(10); paintingContainer = new Container(scrollbar, 0, 4); container = new Container(); title = new Label("Select a Painting"); back = new ButtonVanilla("Cancel", new CloseHandler()); EnumArt[] enumArts = EnumArt.values(); ArrayList<EnumArt> validArts = new ArrayList<EnumArt>(); for (String s : art) for (EnumArt enumArt : enumArts) if (enumArt.title.equals(s)){ validArts.add(enumArt); break; } EnumArt[] validArtsArray = validArts.toArray(new EnumArt[0]); buttons = new PaintingButton[validArtsArray.length]; for (int i = 0; i < validArtsArray.length; ++i) buttons[i] = new PaintingButton(validArtsArray[i], this); container.addWidgets(title, back); paintingContainer.addWidgets(buttons); containers.add(paintingContainer); containers.add(container); selectedContainer = paintingContainer; }
@Override public void setArt(Art art) { title = ((EnumArt)(Object)art).title; }
public static EnumArt addArt(String name, String tile, int sizeX, int sizeY, int offsetX, int offsetY) { return addEnum(EnumArt.class, name, tile, sizeX, sizeY, offsetX, offsetY); }
protected EnumArt getEnumArt(String artName) { for (EnumArt art : EnumArt.values()) if (art.title.equals(artName)) return art; return EnumArt.Kebab; }
protected void setPaintingArt(EntityPainting p, EnumArt art) { p.art = art; p.setDirection(p.hangingDirection); }
public PaintingButton(EnumArt art, ButtonHandler handler) { super(art.sizeX, art.sizeY, handler); this.art = art; }