@EventTarget private void onPostUpdate(UpdateEvent event) { if (event.state == Event.State.POST) { int soupSlot = this.getSoupFromInventory(); if ((double)this.mc.thePlayer.getHealth() < this.health * 2.0 && this.time.delay((float)this.delay) && soupSlot != -1) { int prevSlot = this.mc.thePlayer.inventory.currentItem; if (soupSlot < 9) { this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(soupSlot)); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(this.mc.thePlayer.inventory.getCurrentItem())); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(prevSlot)); this.mc.playerController.syncCurrentPlayItem(); this.mc.thePlayer.inventory.currentItem = prevSlot; } else { this.swap(soupSlot, this.mc.thePlayer.inventory.currentItem + (this.mc.thePlayer.inventory.currentItem < 8 ? 1 : -1)); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(this.mc.thePlayer.inventory.currentItem + (this.mc.thePlayer.inventory.currentItem < 8 ? 1 : -1))); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(this.mc.thePlayer.inventory.getCurrentItem())); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(prevSlot)); } this.time.reset(); } } }
public boolean sendUseItem(EntityPlayer p_78769_1_, World p_78769_2_, ItemStack p_78769_3_) { syncCurrentPlayItem(); this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(-1, -1, -1, 255, p_78769_1_.inventory.getCurrentItem(), 0.0F, 0.0F, 0.0F)); int i = p_78769_3_.stackSize; ItemStack itemstack1 = p_78769_3_.useItemRightClick(p_78769_2_, p_78769_1_); if ((itemstack1 == p_78769_3_) && ((itemstack1 == null) || (itemstack1.stackSize == i))) { return false; } p_78769_1_.inventory.mainInventory[p_78769_1_.inventory.currentItem] = itemstack1; if (itemstack1.stackSize <= 0) { p_78769_1_.inventory.mainInventory[p_78769_1_.inventory.currentItem] = null; MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(p_78769_1_, itemstack1)); } return true; }
@Override public void onOutwardPacket(EventOnOutwardPacket event){ if(!invoker.isOnGround()) return; Packet packet = event.getPacket(); if (packet instanceof C08PacketPlayerBlockPlacement) { if(Item.getIdFromItem(invoker.getCurrentItem().getItem()) != 261) return; C08PacketPlayerBlockPlacement packetBlockPlacement = (C08PacketPlayerBlockPlacement) packet; if (packetBlockPlacement.func_149576_c() != -1 || packetBlockPlacement.func_149571_d() != -1 || packetBlockPlacement.func_149570_e() != -1 || packetBlockPlacement.func_149568_f() != 255) { return; } event.addPacketToList(new C09PacketHeldItemChange(Minecraft.getMinecraft().thePlayer.inventory.currentItem)); for (int i = 0; i < 40; i++) { event.addPacketToList(new C03PacketPlayer(false)); } event.addPacketToList(new C07PacketPlayerDigging(5, 0, 0, 0, 255)); } }
@Override public void onOutwardPacket(EventOnOutwardPacket event){ if(!invoker.isOnGround()) return; Packet packet = event.getPacket(); if (packet instanceof C08PacketPlayerBlockPlacement) { if(!(invoker.getCurrentItem().getItem() instanceof ItemFood)) return; C08PacketPlayerBlockPlacement packetBlockPlacement = (C08PacketPlayerBlockPlacement) packet; if (packetBlockPlacement.func_149576_c() != -1 || packetBlockPlacement.func_149571_d() != -1 || packetBlockPlacement.func_149570_e() != -1 || packetBlockPlacement.func_149568_f() != 255) { return; } event.addPacketToList(new C09PacketHeldItemChange(Minecraft.getMinecraft().thePlayer.inventory.currentItem)); for (int i = 0; i < 40; i++) { event.addPacketToList(new C03PacketPlayer(false)); } event.addPacketToList(new C07PacketPlayerDigging(5, 0, 0, 0, 255)); } }
/** * Notifies the server of things like consuming food, etc... */ public boolean sendUseItem(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack) { this.syncCurrentPlayItem(); this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(-1, -1, -1, 255, par1EntityPlayer.inventory.getCurrentItem(), 0.0F, 0.0F, 0.0F)); int var4 = par3ItemStack.stackSize; ItemStack var5 = par3ItemStack.useItemRightClick(par2World, par1EntityPlayer); if (var5 == par3ItemStack && (var5 == null || var5.stackSize == var4)) { return false; } else { par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = var5; if (var5.stackSize == 0) { par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = null; } return true; } }
public boolean sendUseItem(EntityPlayer p_78769_1_, World p_78769_2_, ItemStack p_78769_3_) { this.syncCurrentPlayItem(); this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(-1, -1, -1, 255, p_78769_1_.inventory.getCurrentItem(), 0.0F, 0.0F, 0.0F)); int i = p_78769_3_.stackSize; ItemStack itemstack1 = p_78769_3_.useItemRightClick(p_78769_2_, p_78769_1_); if (itemstack1 == p_78769_3_ && (itemstack1 == null || itemstack1.stackSize == i)) { return false; } else { p_78769_1_.inventory.mainInventory[p_78769_1_.inventory.currentItem] = itemstack1; if (itemstack1.stackSize <= 0) { p_78769_1_.inventory.mainInventory[p_78769_1_.inventory.currentItem] = null; MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(p_78769_1_, itemstack1)); } return true; } }
/** * Notifies the server of things like consuming food, etc... */ public boolean sendUseItem(EntityPlayer playerIn, World worldIn, ItemStack itemStackIn) { if (this.currentGameType == WorldSettings.GameType.SPECTATOR) { return false; } else { this.syncCurrentPlayItem(); this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(playerIn.inventory.getCurrentItem())); int i = itemStackIn.stackSize; ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn); if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i) { playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack; if (itemstack.stackSize == 0) { playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null; } return true; } else { return false; } } }
@EventTarget private void onUpdate(UpdateEvent event) { int foodSlot; if (event.state == Event.State.PRE && (foodSlot = this.getFoodSlotInHotbar()) != -1 && (double)this.mc.thePlayer.getFoodStats().getFoodLevel() < this.hunger * 2.0 && this.mc.thePlayer.isCollidedVertically) { this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(foodSlot)); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(this.mc.thePlayer.inventory.mainInventory[foodSlot])); int i = 0; while (i < 32) { this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C03PacketPlayer(false)); ++i; } this.mc.thePlayer.stopUsingItem(); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(this.mc.thePlayer.inventory.currentItem)); } }
@EventTarget private void onPacketSend(PacketSendEvent event) { if (event.packet instanceof C0BPacketEntityAction || event.packet instanceof C03PacketPlayer || event.packet instanceof C02PacketUseEntity || event.packet instanceof C0APacketAnimation || event.packet instanceof C08PacketPlayerBlockPlacement) { this.packetList.add(event.packet); event.setCancelled(true); } }
@EventTarget(value=4) private void onUpdate(UpdateEvent event) { if (this.mc.thePlayer.isBlocking() && (this.mc.thePlayer.motionX != 0.0 || this.mc.thePlayer.motionZ != 0.0)) { if (event.state == Event.State.PRE) { this.mc.getNetHandler().getNetworkManager().dispatchPacket((Packet)new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN), null); } else if (event.state == Event.State.POST) { this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(this.mc.thePlayer.inventory.getCurrentItem())); } } }
@EventTarget private void onTick(TickEvent event) { int i = 0; while (i < 8) { Item item; if (this.mc.thePlayer.inventory.mainInventory[i] != null && ((item = this.mc.thePlayer.inventory.mainInventory[i].getItem()) instanceof ItemRedstone || Item.getIdFromItem((Item)item) == 353 || item instanceof ItemFirework)) { this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(i)); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(this.mc.thePlayer.inventory.mainInventory[i])); this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(this.mc.thePlayer.inventory.currentItem)); } ++i; } }
@Override public void sendUsePacket(final PlayerInteractEvent event) { if (event.world.isRemote) { final Vec3 hitVec = Minecraft.getMinecraft().objectMouseOver.hitVec; final float f = (float)hitVec.xCoord - event.x; final float f2 = (float)hitVec.yCoord - event.y; final float f3 = (float)hitVec.zCoord - event.z; Minecraft.getMinecraft().getNetHandler().addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(event.x, event.y, event.z, event.face, event.entityPlayer.inventory.getCurrentItem(), f, f2, f3)); } }
@Override public void sendUsePacket(final int x, final int y, final int z, final int face, final ItemStack item, final float hitX, final float hitY, final float hitZ) { if (this.isAltSneaking()) { this.sendAltUsePacket(x, y, z, face, item, hitX, hitY, hitZ); } else { Minecraft.getMinecraft().getNetHandler().addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(x, y, z, face, item, hitX, hitY, hitZ)); } }
/** * Processes block placement and block activation (anvil, furnace, etc.) */ public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer()); WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); ItemStack itemstack = this.playerEntity.inventory.getCurrentItem(); boolean flag = false; BlockPos blockpos = packetIn.getPosition(); EnumFacing enumfacing = EnumFacing.getFront(packetIn.getPlacedBlockDirection()); this.playerEntity.markPlayerActive(); if (packetIn.getPlacedBlockDirection() == 255) { if (itemstack == null) { return; } this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack); } else if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit()) { if (this.hasMoved && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos)) { this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, blockpos, enumfacing, packetIn.getPlacedBlockOffsetX(), packetIn.getPlacedBlockOffsetY(), packetIn.getPlacedBlockOffsetZ()); } flag = true; } else { ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())}); chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation)); flag = true; } if (flag) { this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos)); this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos.offset(enumfacing))); } itemstack = this.playerEntity.inventory.getCurrentItem(); if (itemstack != null && itemstack.stackSize == 0) { this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null; itemstack = null; } if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) { this.playerEntity.isChangingQuantityOnly = true; this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]); Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem); this.playerEntity.openContainer.detectAndSendChanges(); this.playerEntity.isChangingQuantityOnly = false; if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), packetIn.getStack())) { this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem())); } } }
public boolean onPlayerRightClick(EntityPlayerSP player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, EnumFacing side, Vec3 hitVec) { this.syncCurrentPlayItem(); float f = (float)(hitVec.xCoord - (double)hitPos.getX()); float f1 = (float)(hitVec.yCoord - (double)hitPos.getY()); float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ()); boolean flag = false; if (!this.mc.theWorld.getWorldBorder().contains(hitPos)) { return false; } else { if (this.currentGameType != WorldSettings.GameType.SPECTATOR) { IBlockState iblockstate = worldIn.getBlockState(hitPos); if ((!player.isSneaking() || player.getHeldItem() == null) && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2)) { flag = true; } if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock) { ItemBlock itemblock = (ItemBlock)heldStack.getItem(); if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack)) { return false; } } } this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2)); if (!flag && this.currentGameType != WorldSettings.GameType.SPECTATOR) { if (heldStack == null) { return false; } else if (this.currentGameType.isCreative()) { int i = heldStack.getMetadata(); int j = heldStack.stackSize; boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2); heldStack.setItemDamage(i); heldStack.stackSize = j; return flag1; } else { return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2); } } else { return true; } } }
public boolean onPlayerRightClick(EntityPlayer p_78760_1_, World p_78760_2_, ItemStack p_78760_3_, int p_78760_4_, int p_78760_5_, int p_78760_6_, int p_78760_7_, Vec3 p_78760_8_) { syncCurrentPlayItem(); float f = (float)p_78760_8_.xCoord - p_78760_4_; float f1 = (float)p_78760_8_.yCoord - p_78760_5_; float f2 = (float)p_78760_8_.zCoord - p_78760_6_; boolean flag = false; if ((p_78760_3_ != null) && (p_78760_3_.getItem() != null) && (p_78760_3_.getItem().onItemUseFirst(p_78760_3_, p_78760_1_, p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, f, f1, f2))) { return true; } if ((!p_78760_1_.isSneaking()) || (p_78760_1_.getHeldItem() == null) || (p_78760_1_.getHeldItem().getItem().doesSneakBypassUse(p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_1_))) { flag = p_78760_2_.getBlock(p_78760_4_, p_78760_5_, p_78760_6_).onBlockActivated(p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_1_, p_78760_7_, f, f1, f2); } if ((!flag) && (p_78760_3_ != null) && ((p_78760_3_.getItem() instanceof ItemBlock))) { ItemBlock itemblock = (ItemBlock)p_78760_3_.getItem(); if (!itemblock.func_150936_a(p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, p_78760_1_, p_78760_3_)) { return false; } } this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, p_78760_1_.inventory.getCurrentItem(), f, f1, f2)); if (flag) { return true; } if (p_78760_3_ == null) { return false; } if (this.currentGameType.isCreative()) { int j1 = p_78760_3_.getItemDamage(); int i1 = p_78760_3_.stackSize; boolean flag1 = p_78760_3_.tryPlaceItemIntoWorld(p_78760_1_, p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, f, f1, f2); p_78760_3_.setItemDamage(j1); p_78760_3_.stackSize = i1; return flag1; } if (!p_78760_3_.tryPlaceItemIntoWorld(p_78760_1_, p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, f, f1, f2)) { return false; } if (p_78760_3_.stackSize <= 0) { MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(p_78760_1_, p_78760_3_)); } return true; }
public static void buildNext(int[][] building, MovingObjectPosition mouseOver, float playerYaw, int i) { if (playerYaw > -45 && playerYaw <= 45) {// F: 0 South BlockUtils.faceBlockPacket(new BlockPos(mouseOver.getBlockPos().getX() + building[i][0], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() + building[i][2])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(mouseOver.getBlockPos().getX() + building[i][0], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() + building[i][2]), mouseOver.sideHit.getIndex(), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() + building[i][0]), (float) mouseOver.hitVec.yCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.zCoord - (mouseOver.getBlockPos().getZ() + building[i][2]))); } else if (playerYaw > 45 && playerYaw <= 135) {// F: 1 West BlockUtils.faceBlockPacket(new BlockPos(mouseOver.getBlockPos().getX() - building[i][2], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() + building[i][0])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(mouseOver.getBlockPos().getX() - building[i][2], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() + building[i][0]), mouseOver.sideHit.getIndex(), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() - building[i][2]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() + building[i][0]))); } else if (playerYaw > 135 || playerYaw <= -135) {// F: 2 North BlockUtils.faceBlockPacket(new BlockPos(mouseOver.getBlockPos().getX() - building[i][0], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() - building[i][2])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(mouseOver.getBlockPos().getX() - building[i][0], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() - building[i][2]), mouseOver.sideHit.getIndex(), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() - building[i][0]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() - building[i][2]))); } else if (playerYaw > -135 && playerYaw <= -45) {// F: 3 East BlockUtils.faceBlockPacket(new BlockPos(mouseOver.getBlockPos().getX() + building[i][2], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() - building[i][0])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(mouseOver.getBlockPos().getX() + building[i][2], mouseOver.getBlockPos().getY() + building[i][1], mouseOver.getBlockPos().getZ() - building[i][0]), mouseOver.sideHit.getIndex(), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() + building[i][2]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() - building[i][0]))); } }
public static void advancedBuildNext(int[][] building, MovingObjectPosition mouseOver, float playerYaw, int i) { if (playerYaw > -45 && playerYaw <= 45) {// F: 0 South BlockUtils.faceBlockPacket(new BlockPos(convertPosNext(1, mouseOver) + building[i][0], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) + building[i][2])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(convertPosNext(1, mouseOver) + building[i][0], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) + building[i][2]), building[i][3], Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() + building[i][0]), (float) mouseOver.hitVec.yCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.zCoord - (mouseOver.getBlockPos().getZ() + building[i][2]))); } else if (playerYaw > 45 && playerYaw <= 135) {// F: 1 West BlockUtils.faceBlockPacket(new BlockPos(convertPosNext(1, mouseOver) - building[i][2], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) + building[i][0])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(convertPosNext(1, mouseOver) - building[i][2], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) + building[i][0]), convertSide(building[i][3], 1), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() - building[i][2]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() + building[i][0]))); } else if (playerYaw > 135 || playerYaw <= -135) {// F: 2 North BlockUtils.faceBlockPacket(new BlockPos(convertPosNext(1, mouseOver) - building[i][0], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) - building[i][2])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(convertPosNext(1, mouseOver) - building[i][0], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) - building[i][2]), convertSide(building[i][3], 2), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() - building[i][0]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() - building[i][2]))); } else if (playerYaw > -135 && playerYaw <= -45) {// F: 3 East BlockUtils.faceBlockPacket(new BlockPos(convertPosNext(1, mouseOver) + building[i][2], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) - building[i][0])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos(convertPosNext(1, mouseOver) + building[i][2], convertPosNext(2, mouseOver) + building[i][1], convertPosNext(3, mouseOver) - building[i][0]), convertSide(building[i][3], 3), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() + building[i][2]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() - building[i][0]))); } }
public static void advancedInstantBuildNext(int[][] building, MovingObjectPosition mouseOver, float playerYaw, double posX, double posY, double posZ, int i) { if (playerYaw > -45 && playerYaw <= 45) {// F: 0 South BlockUtils.faceBlockPacket(new BlockPos((int) posX - 1 + building[i][0], (int) posY - 2 + building[i][1], (int) posZ + building[i][2])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos((int) posX - 1 + building[i][0], (int) posY - 2 + building[i][1], (int) posZ + building[i][2]), building[i][3], Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() + building[i][0]), (float) mouseOver.hitVec.yCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.zCoord - (mouseOver.getBlockPos().getZ() + building[i][2]))); } else if (playerYaw > 45 && playerYaw <= 135) {// F: 1 West BlockUtils.faceBlockPacket(new BlockPos((int) (posX - 1 - building[i][2]), (int) posY - 2 + building[i][1], (int) posZ + building[i][0])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos((int) (posX - 1 - building[i][2]), (int) posY - 2 + building[i][1], (int) posZ + building[i][0]), convertSide(building[i][3], 1), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() - building[i][2]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() + building[i][0]))); } else if (playerYaw > 135 || playerYaw <= -135) {// F: 2 North BlockUtils.faceBlockPacket(new BlockPos((int) posX - 1 - building[i][0], (int) posY - 2 + building[i][1], (int) posZ - building[i][2])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos((int) posX - 1 - building[i][0], (int) posY - 2 + building[i][1], (int) posZ - building[i][2]), convertSide(building[i][3], 2), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() - building[i][0]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() - building[i][2]))); } else if (playerYaw > -135 && playerYaw <= -45) {// F: 3 East BlockUtils.faceBlockPacket(new BlockPos((int) posX - 1 + building[i][2], (int) posY - 2 + building[i][1], (int) posZ - building[i][0])); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C08PacketPlayerBlockPlacement( new BlockPos((int) posX - 1 + building[i][2], (int) posY - 2 + building[i][1], (int) posZ - building[i][0]), convertSide(building[i][3], 3), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getX() + building[i][2]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getY() + building[i][1]), (float) mouseOver.hitVec.xCoord - (mouseOver.getBlockPos().getZ() - building[i][0]))); } }
@Override public void onUpdate() { if (WurstClient.INSTANCE.mods.getModByClass(FreecamMod.class).isActive() || WurstClient.INSTANCE.mods.getModByClass(RemoteViewMod.class).isActive() || Minecraft.getMinecraft().objectMouseOver == null || Minecraft.getMinecraft().objectMouseOver.typeOfHit != MovingObjectType.BLOCK) { return; } if (Minecraft.getMinecraft().rightClickDelayTimer > 0 && !WurstClient.INSTANCE.mods.getModByClass(FastPlaceMod.class).isActive()) { return; } float xDiff; float yDiff; float zDiff; float distance = RANGE + 1; boolean hasBlocks = false; for (int y = (int) RANGE; y >= -RANGE; y--) { for (int x = (int) RANGE; x >= -RANGE - 1; x--) { for (int z = (int) RANGE; z >= -RANGE; z--) { if (Block.getIdFromBlock(Minecraft.getMinecraft().theWorld.getBlockState( new BlockPos((int) (x + Minecraft.getMinecraft().thePlayer.posX), (int) (y + Minecraft.getMinecraft().thePlayer.posY), (int) (z + Minecraft.getMinecraft().thePlayer.posZ))).getBlock()) != 0 && BlockUtils.getBlockDistance(x, y, z) <= RANGE) { hasBlocks = true; break; } } if (hasBlocks) break; } if (hasBlocks) break; } if (!hasBlocks) return; BlockPos randomPos = null; while (distance > RANGE || distance < -RANGE || Block.getIdFromBlock(Minecraft.getMinecraft().theWorld.getBlockState(randomPos).getBlock()) == 0) { xDiff = (int) (Math.random() * RANGE * 2 - RANGE - 1); yDiff = (int) (Math.random() * RANGE * 2 - RANGE); zDiff = (int) (Math.random() * RANGE * 2 - RANGE); distance = BlockUtils.getBlockDistance(xDiff, yDiff, zDiff); int randomPosX = (int) (xDiff + Minecraft.getMinecraft().thePlayer.posX); int randomPosY = (int) (yDiff + Minecraft.getMinecraft().thePlayer.posY); int randomPosZ = (int) (zDiff + Minecraft.getMinecraft().thePlayer.posZ); randomPos = new BlockPos(randomPosX, randomPosY, randomPosZ); } MovingObjectPosition fakeObjectMouseOver = Minecraft.getMinecraft().objectMouseOver; if (fakeObjectMouseOver == null) return; fakeObjectMouseOver.setBlockPos(randomPos); BlockUtils.faceBlockPacket(randomPos); Minecraft.getMinecraft().thePlayer.swingItem(); Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue( new C08PacketPlayerBlockPlacement(randomPos, fakeObjectMouseOver.sideHit.getIndex(), Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem(), (float) fakeObjectMouseOver.hitVec.xCoord - fakeObjectMouseOver.getBlockPos().getX(), (float) fakeObjectMouseOver.hitVec.yCoord - fakeObjectMouseOver.getBlockPos().getY(), (float) fakeObjectMouseOver.hitVec.zCoord - fakeObjectMouseOver.getBlockPos().getZ())); }
/** * Handles a players right click. Args: player, world, x, y, z, side, hitVec */ public boolean onPlayerRightClick(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, Vec3 par8Vec3) { this.syncCurrentPlayItem(); float var9 = (float)par8Vec3.xCoord - (float)par4; float var10 = (float)par8Vec3.yCoord - (float)par5; float var11 = (float)par8Vec3.zCoord - (float)par6; boolean var12 = false; if ((!par1EntityPlayer.isSneaking() || par1EntityPlayer.getHeldItem() == null) && par2World.getBlock(par4, par5, par6).onBlockActivated(par2World, par4, par5, par6, par1EntityPlayer, par7, var9, var10, var11)) { var12 = true; } if (!var12 && par3ItemStack != null && par3ItemStack.getItem() instanceof ItemBlock) { ItemBlock var13 = (ItemBlock)par3ItemStack.getItem(); if (!var13.func_150936_a(par2World, par4, par5, par6, par7, par1EntityPlayer, par3ItemStack)) { return false; } } this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(par4, par5, par6, par7, par1EntityPlayer.inventory.getCurrentItem(), var9, var10, var11)); if (var12) { return true; } else if (par3ItemStack == null) { return false; } else if (this.currentGameType.isCreative()) { int var16 = par3ItemStack.getItemDamage(); int var14 = par3ItemStack.stackSize; boolean var15 = par3ItemStack.tryPlaceItemIntoWorld(par1EntityPlayer, par2World, par4, par5, par6, par7, var9, var10, var11); par3ItemStack.setItemDamage(var16); par3ItemStack.stackSize = var14; return var15; } else { return par3ItemStack.tryPlaceItemIntoWorld(par1EntityPlayer, par2World, par4, par5, par6, par7, var9, var10, var11); } }
@Override public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement p_147346_1_) { }
public boolean onPlayerRightClick(EntityPlayer p_78760_1_, World p_78760_2_, ItemStack p_78760_3_, int p_78760_4_, int p_78760_5_, int p_78760_6_, int p_78760_7_, Vec3 p_78760_8_) { this.syncCurrentPlayItem(); float f = (float)p_78760_8_.xCoord - (float)p_78760_4_; float f1 = (float)p_78760_8_.yCoord - (float)p_78760_5_; float f2 = (float)p_78760_8_.zCoord - (float)p_78760_6_; boolean flag = false; if (p_78760_3_ != null && p_78760_3_.getItem() != null && p_78760_3_.getItem().onItemUseFirst(p_78760_3_, p_78760_1_, p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, f, f1, f2)) { return true; } if (!p_78760_1_.isSneaking() || p_78760_1_.getHeldItem() == null || p_78760_1_.getHeldItem().getItem().doesSneakBypassUse(p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_1_)) { flag = p_78760_2_.getBlock(p_78760_4_, p_78760_5_, p_78760_6_).onBlockActivated(p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_1_, p_78760_7_, f, f1, f2); } if (!flag && p_78760_3_ != null && p_78760_3_.getItem() instanceof ItemBlock) { ItemBlock itemblock = (ItemBlock)p_78760_3_.getItem(); if (!itemblock.func_150936_a(p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, p_78760_1_, p_78760_3_)) { return false; } } this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, p_78760_1_.inventory.getCurrentItem(), f, f1, f2)); if (flag) { return true; } else if (p_78760_3_ == null) { return false; } else if (this.currentGameType.isCreative()) { int j1 = p_78760_3_.getItemDamage(); int i1 = p_78760_3_.stackSize; boolean flag1 = p_78760_3_.tryPlaceItemIntoWorld(p_78760_1_, p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, f, f1, f2); p_78760_3_.setItemDamage(j1); p_78760_3_.stackSize = i1; return flag1; } else { if (!p_78760_3_.tryPlaceItemIntoWorld(p_78760_1_, p_78760_2_, p_78760_4_, p_78760_5_, p_78760_6_, p_78760_7_, f, f1, f2)) { return false; } if (p_78760_3_.stackSize <= 0) { MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(p_78760_1_, p_78760_3_)); } return true; } }
public static boolean place(EntityPlayer player, World world){ MovingObjectPosition hit = RayTracer.reTrace(world, player); if(hit == null) return false; BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ); ItemStack held = player.getHeldItem(); PartPressureTube part = null; if(held == null) return false; Block heldBlock = Block.getBlockFromItem(held.getItem()); if(heldBlock == Blockss.pressureTube) { part = new PartPressureTube(); } else if(heldBlock == Blockss.advancedPressureTube) { part = new PartAdvancedPressureTube(); } if(part == null) return false; if(world.isRemote && !player.isSneaking())//attempt to use block activated like normal and tell the server the right stuff { Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ); Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ); if(!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z)) { player.swingItem(); PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float)f.x, (float)f.y, (float)f.z)); return true; } } TileMultipart tile = TileMultipart.getOrConvertTile(world, pos); if(tile == null || !tile.canAddPart(part)) { pos = pos.offset(hit.sideHit); tile = TileMultipart.getOrConvertTile(world, pos); if(tile == null || !tile.canAddPart(part)) return false; } if(!world.isRemote) { TileMultipart.addPart(world, pos, part); world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blockss.pressureTube.stepSound.func_150496_b(), (Blockss.pressureTube.stepSound.getVolume() + 1.0F) / 2.0F, Blockss.pressureTube.stepSound.getPitch() * 0.8F); if(!player.capabilities.isCreativeMode) { held.stackSize--; if(held.stackSize == 0) { player.inventory.mainInventory[player.inventory.currentItem] = null; MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held)); } } } else { player.swingItem(); NetworkHandler.sendToServer(new PacketFMPPlacePart()); } return true; }
/** * Processes block placement and block activation (anvil, furnace, etc.) */ void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn);
/** * Processes block placement and block activation (anvil, furnace, etc.) */ void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement var1);