@SubscribeEvent public static void onClientTick(ClientTickEvent event) throws Throwable { if (event.phase == Phase.START && (!Configs.creativeOnly || Minecraft.getMinecraft().player.isCreative())) { int timer = (int) getDelayTimer.invoke(Minecraft.getMinecraft()); RayTraceResult hover = Minecraft.getMinecraft().objectMouseOver; if (hover != null && hover.typeOfHit == Type.BLOCK) { BlockPos pos = hover.getBlockPos(); if (timer > 0 && !pos.equals(lastTargetPos) && (lastTargetPos == null || !pos.equals(lastTargetPos.offset(lastTargetSide)))) { setDelayTimer.invoke(Minecraft.getMinecraft(), 0); } else if (Configs.forceNewLoc && timer == 0 && pos.equals(lastTargetPos) && hover.sideHit == lastTargetSide) { setDelayTimer.invoke(Minecraft.getMinecraft(), 4); } lastTargetPos = pos.toImmutable(); lastTargetSide = hover.sideHit; } } }
@Override public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { Spell spell = getSpellFromItemStack(stack); if (spell != null && !worldIn.isRemote) { if (entityLiving instanceof EntityPlayer) { int spellCost = spell.getCost() * 80; Optional<IEnergy> eng = EnergyHandler.getEnergy((EntityPlayer) entityLiving); if (eng.isPresent() && eng.get().get() < spellCost) return stack; EnergyHandler.addEnergy((EntityPlayer) entityLiving, -spellCost); } if (spell.getType() == EnumSpellType.INSTANT) spell.performEffect(new RayTraceResult(Type.MISS, entityLiving.getLookVec(), EnumFacing.UP, entityLiving.getPosition()), entityLiving, worldIn); else { EntitySpellCarrier car = new EntitySpellCarrier(worldIn, entityLiving.posX + entityLiving.getLookVec().x, entityLiving.posY + entityLiving.getEyeHeight() + entityLiving.getLookVec().y, entityLiving.posZ + entityLiving.getLookVec().z); car.setSpell(spell); car.setCaster(entityLiving); car.shoot(entityLiving, entityLiving.rotationPitch, entityLiving.rotationYaw, 0, 2f, 0); worldIn.spawnEntity(car); } } if (entityLiving instanceof EntityPlayer && ((EntityPlayer) entityLiving).isCreative()) return stack; return ItemStack.EMPTY; }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) { EntityLivingBase entity = (EntityLivingBase) rtrace.entityHit; EnumHand hand = null; if (!entity.getHeldItemMainhand().isEmpty()) hand = EnumHand.MAIN_HAND; else if (!entity.getHeldItemOffhand().isEmpty()) hand = EnumHand.OFF_HAND; if (hand != null) { ItemStack stack = entity.getHeldItem(hand).copy(); entity.setHeldItem(hand, ItemStack.EMPTY); if (!(entity instanceof EntityPlayer) && stack.isItemStackDamageable() && stack.getItemDamage() == 0) { stack.setItemDamage((int) (stack.getMaxDamage() * (0.5D + 0.5D * Math.random()))); } EntityItem ei = new EntityItem(world, entity.posX, entity.posY, entity.posZ, stack); ei.setPickupDelay(200); ei.setNoDespawn(); if (!world.isRemote) world.spawnEntity(ei); } } }
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn){ ItemStack stack = playerIn.getHeldItem(handIn); if (stack.getMetadata() == 0){ RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true); if (raytraceresult != null && raytraceresult.typeOfHit != null && raytraceresult.typeOfHit == Type.BLOCK){ IBlockState state = worldIn.getBlockState(raytraceresult.getBlockPos()); if (state.getBlock() == Blocks.WATER){ stack.setItemDamage(1); playerIn.setHeldItem(handIn, stack); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS,stack); } } } return new ActionResult<ItemStack>(EnumActionResult.FAIL,stack); }
@Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { if (random.nextInt(20) == 0){ int x = chunkX * 16 + 2 + random.nextInt(12); int z = chunkZ * 16 + 2 + random.nextInt(12); BlockPos p = new BlockPos(x,0,z); p = world.getHeight(p); Biome b = world.getBiome(p); if (BiomeDictionary.hasType(b, BiomeDictionary.Type.FOREST) || b == Biomes.FOREST || b == Biomes.FOREST_HILLS){ if (world.getBlockState(p.down()).getBlock() instanceof BlockGrass && world.isAirBlock(p)){ BlockTeaSapling.generateTree(world, p, Blocks.AIR.getDefaultState(), random); } } } }
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) { RayTraceResult hit = world.rayTraceBlocks(start.vec3(), end.vec3()); if (hit == null) return prevresistance; if (hit.typeOfHit == Type.BLOCK) { IBlockState state = world.getBlockState(hit.getBlockPos()); if (state.getBlock().isAir(state, world, hit.getBlockPos())) return prevresistance; /*if(Block.blocksList[blockID] instanceof ISpecialResistance) { ISpecialResistance isr = (ISpecialResistance) Block.blocksList[blockID]; return prevresistance + (isr.getSpecialExplosionResistance(world, hit.blockX, hit.blockY, hit.blockZ, start.x, start.y, start.z, wrapper) + 0.3F); } else {*/ return prevresistance + state.getBlock().getExplosionResistance(wrapper) + 0.3F; //} } return prevresistance; }
@Override protected void onImpact(RayTraceResult result) { if (result.typeOfHit == Type.ENTITY && result.entityHit != null) { result.entityHit.attackEntityFrom(this.createDamageSource(), this.getDamage()); } else { if (result.typeOfHit == Type.BLOCK) { BlockPos blockpos = result.getBlockPos(); IBlockState iblockstate = this.world.getBlockState(blockpos); this.inGround = true; this.reflectImpactTileData(result.getBlockPos()); if (iblockstate.getMaterial() != Material.AIR) { iblockstate.getBlock().onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this); } } } }
@Override protected void onImpact(RayTraceResult result) { if (result.typeOfHit == Type.ENTITY && result.entityHit != this.getThrower()) { result.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.getThrower()), 5); result.entityHit.addVelocity(this.motionX, 0.6D, this.motionZ); if (this.getThrower() != null && result.entityHit != this.getThrower() && result.entityHit instanceof EntityPlayer && this.getThrower() instanceof EntityPlayerMP) { ((EntityPlayerMP)this.getThrower()).connection.sendPacket(new SPacketChangeGameState(6, 0.0F)); } } for(int j = 0; j < 8; j++) { this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_LARGE, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); this.worldObj.spawnParticle(EnumParticleTypes.FLAME, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); } this.setDead(); }
@Override protected void onImpact(RayTraceResult result) { if (result.typeOfHit == Type.ENTITY) { Entity entity = result.entityHit; if (entity instanceof EntityPlayer) { EntityPlayer player = ((EntityPlayer)entity); if (player.inventory.armorInventory[0] != null && player.inventory.armorInventory[0].getItem() == ItemsAether.sentry_boots) { return; } } result.entityHit.motionX += this.motionX * 1.5F; result.entityHit.motionY += 0.5D; result.entityHit.motionZ += this.motionZ * 1.5F; } this.setDead(); }
/** * Event listener for bucket using. When you place water or lava with * bucket it doesn't considered place block action like with any other * types of blocks. * * So here's my hack for placing water and lava blocks. */ @SubscribeEvent public void onPlayerUseBucket(FillBucketEvent event) { EntityPlayer player = event.getEntityPlayer(); List<Action> events = CommonProxy.manager.getActions(player); RayTraceResult target = event.getTarget(); if (!player.worldObj.isRemote && events != null && target != null && target.typeOfHit == Type.BLOCK) { Item bucket = event.getEmptyBucket().getItem(); BlockPos pos = target.getBlockPos().offset(target.sideHit); if (bucket == Items.LAVA_BUCKET) { this.placeBlock(events, pos, Blocks.FLOWING_LAVA, 0); } else if (bucket == Items.WATER_BUCKET) { this.placeBlock(events, pos, Blocks.FLOWING_WATER, 0); } } }
@Override protected void onImpact(RayTraceResult result){ if(result.typeOfHit == Type.BLOCK && !worldObj.isRemote){ if(worldObj.getBlockState(result.getBlockPos()) != null && worldObj.getBlockState(result.getBlockPos()).getBlock() == Blocks.GRAVEL){ worldObj.setBlockState(result.getBlockPos(), DungeonDimension.corruption.getDefaultState()); } }else if (result.entityHit != null){ if(result.entityHit instanceof EntityLivingBase){ EntityLivingBase ent = (EntityLivingBase) result.entityHit; if(ent instanceof EntityPlayer) ent.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 10*20, 1)); ent.addPotionEffect(new PotionEffect(MobEffects.POISON, 2*20, 1)); } } for (int j = 0; j < 8; ++j){ this.worldObj.spawnParticle(EnumParticleTypes.ITEM_CRACK, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[]{Item.getIdFromItem(DungeonDimension.corruptionslime)}); } if (!this.worldObj.isRemote){ this.setDead(); } setDead(); }
@Override protected void onImpact(RayTraceResult result) { if (world.isRemote) return; boolean kill = true; if (result.typeOfHit == Type.ENTITY) { Entity ent = result.entityHit; if (ent instanceof EntityPlayerMP) { kill = false; } else ent.attackEntityFrom( (new EntityDamageSource("arrow", getThrower())).setProjectile(), damage); } if (result.typeOfHit == Type.BLOCK) { if (!world.getBlockState(result.getBlockPos()).isFullBlock()) { kill = false; } } if (kill) setDead(); }
@Override protected void onImpact(RayTraceResult result) { if (world.isRemote) return; if (result.typeOfHit == Type.ENTITY) { Entity ent = result.entityHit; if (ent == getThrower()) { setDead(); } else { ent.attackEntityFrom( DamageSource.causeIndirectDamage(this, getThrower()), 4F); } } else { if (isReturning) { setDead(); } else { returnToThrower(); } } }
@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 ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { // ItemStack stack = player.getHeldItem(hand); float lerp = 1F; float dist = 7; Vec3d start = this.getPositionEyes(lerp, player); Vec3d direction = player.getLook(lerp); Vec3d end = start.addVector(direction.xCoord * dist, direction.yCoord * dist, direction.zCoord * dist); RayTraceResult result = world.rayTraceBlocks(start, end, false, false, false); if(result.typeOfHit == Type.BLOCK){ spawnNPC(world, result.getBlockPos()); if(!world.isRemote) player.sendMessage(new TextComponentString("NPC spawned!")); } return super.onItemRightClick(world, player, hand); }
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if(world.isRemote) return ActionResult.newResult(EnumActionResult.PASS, stack); if(stack.hasTagCompound()){ NBTTagCompound tag = stack.getTagCompound(); EnumTriggerState state = EnumTriggerState.values()[tag.getInteger("trigger")]; float lerp = 1F; float dist = 6; Vec3d start = this.getPositionEyes(lerp, player); Vec3d direction = player.getLook(lerp); Vec3d end = start.addVector(direction.xCoord * dist, direction.yCoord * dist, direction.zCoord * dist); RayTraceResult result = world.rayTraceBlocks(start, end, false, false, false); if(result != null && result.typeOfHit != null && result.typeOfHit == Type.BLOCK){ BlockPos pos = result.getBlockPos(); Block block = world.getBlockState(pos).getBlock(); if(block instanceof TCITriggerableBlock){ ((TCITriggerableBlock)block).trigger(world, pos, state); return ActionResult.newResult(EnumActionResult.PASS, stack); } } } return ActionResult.newResult(EnumActionResult.SUCCESS, stack); }
@SubscribeEvent public void onMouseEvent(MouseEvent event) { int button = event.getButton() - 100; Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = mc.player; World world = mc.world; int key = mc.gameSettings.keyBindAttack.getKeyCode(); if (button == key && Mouse.isButtonDown(button + 100)) if(mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == Type.BLOCK){ BlockPos pos = mc.objectMouseOver.getBlockPos(); EnumFacing face = mc.objectMouseOver.sideHit; if(pos != null && face != null) if (world.getBlockState(pos).getBlock() != null) extinguishFire(player, pos, face, world, event); } }
@Override protected void castSpellServer(World world, BlockPos pos, EntityPlayer player) { RayTraceResult r = rayTrace(player, world, 16, 1); if(r != null && r.typeOfHit == Type.BLOCK){ IBlockState state = getDegradation(world.getBlockState(r.getBlockPos())); if(state != null && world.isBlockModifiable(player, r.getBlockPos())){ world.destroyBlock(r.getBlockPos(), false); world.setBlockState(r.getBlockPos(), state); AbyssalCraftAPI.getInternalMethodHandler().spawnPEStream(pos, r.getBlockPos(), world.provider.getDimension()); for(int i = 0; i < 9; i++){ ItemStack stack = player.inventory.getStackInSlot(i); if(stack.getItem() instanceof IEnergyContainerItem){ ((IEnergyContainerItem)stack.getItem()).addEnergy(stack, 5 + world.rand.nextInt(5)); break; } } } } }
@Override protected void castSpellServer(World world, BlockPos pos, EntityPlayer player) { RayTraceResult r = rayTrace(player, world, 16, 1); if(r != null && r.typeOfHit == Type.BLOCK) for(int i = 0; i < 3; i++) for(BlockPos pos2 : getPositions(r.getBlockPos().offset(r.sideHit.getOpposite(), i), r.sideHit.getOpposite())){ IBlockState state = getRemains(world.getBlockState(pos2)); if(state != null && world.isBlockModifiable(player, pos2)){ if(i == 0) world.destroyBlock(pos2, false); world.setBlockState(pos2, state); } } }
@Override protected void onImpact(RayTraceResult par1RayTraceResult) { if(!worldObj.isRemote) if(par1RayTraceResult.typeOfHit == Type.ENTITY) { if(par1RayTraceResult.entityHit instanceof EntityPlayer) if(((EntityPlayer)par1RayTraceResult.entityHit).capabilities.isCreativeMode || (EntityLivingBase)par1RayTraceResult.entityHit == getThrower()) return; if(par1RayTraceResult.entityHit instanceof EntityLivingBase) { ((EntityLivingBase) par1RayTraceResult.entityHit).attackEntityFrom(DamageSource.generic, 1F); ((EntityLivingBase) par1RayTraceResult.entityHit).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("weakness"), 500, 2)); ((EntityLivingBase) par1RayTraceResult.entityHit).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("nausea"), 500, 2)); ((EntityLivingBase) par1RayTraceResult.entityHit).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("slowness"), 500, 2)); setDead(); } } }
@Override protected void onImpact(RayTraceResult par1RayTraceResult) { if(!world.isRemote) if(par1RayTraceResult.typeOfHit == Type.ENTITY) { if(par1RayTraceResult.entityHit instanceof EntityPlayer) if(((EntityPlayer)par1RayTraceResult.entityHit).capabilities.isCreativeMode || (EntityLivingBase)par1RayTraceResult.entityHit == getThrower()) return; if(par1RayTraceResult.entityHit instanceof EntityLivingBase) { ((EntityLivingBase) par1RayTraceResult.entityHit).attackEntityFrom(DamageSource.GENERIC, 1F); ((EntityLivingBase) par1RayTraceResult.entityHit).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("weakness"), 500, 2)); ((EntityLivingBase) par1RayTraceResult.entityHit).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("nausea"), 500, 2)); ((EntityLivingBase) par1RayTraceResult.entityHit).addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("slowness"), 500, 2)); setDead(); } } }
public void runAutoTool(boolean proactive) { // proactive means we're doing this before the keybinding is even logged yet. // currently mining? and not using swap command? if (swappedInventoryState == 0 && (proactive || mc.gameSettings.keyBindAttack.isKeyDown()) && mc.objectMouseOver != null) { // get the block being targetted if (!mc.playerController.isInCreativeMode() && ControlPackOptions.booleanOptions.get(ControlPackEnumOptions.AUTOTOOL) && mc.objectMouseOver.typeOfHit == Type.BLOCK) { Block block = mc.world.getBlockState(mc.objectMouseOver.getBlockPos()).getBlock(); if (block != null) { ensureCorrectToolSelected(block); } } else if (ControlPackOptions.booleanOptions.get(ControlPackEnumOptions.AUTOSWORD) && (mc.objectMouseOver.typeOfHit == Type.ENTITY && mc.objectMouseOver.entityHit instanceof EntityLivingBase)) { ensureSwordSelected(); } // fyi change item: player.inventory.changeCurrentItem(k);, or player.inventory.currentItem = i; // mc.objectMouseOver // objectMouseOver.typeOfHit == EnumMovingObjectType.TILE // objectMouseOver.typeOfHit == EnumMovingObjectType.ENTITY // objectMouseOver.blockX,Y,Z // world.getBlockId(i,j,k) // Block.blocksList[id] } }
@Override protected void onImpact(RayTraceResult result) { if (!world.isRemote) { Spell spell = getSpell(); EntityLivingBase caster = getCaster(); if (spell != null) { if (result.typeOfHit != Type.ENTITY || result.entityHit != caster) spell.performEffect(result, caster, world); if (result.typeOfHit == Type.BLOCK && (spell.getType() == EnumSpellType.PROJECTILE_BLOCK || spell.getType() == EnumSpellType.PROJECTILE_ALL)) this.setDead(); if (result.typeOfHit == Type.ENTITY && (spell.getType() == EnumSpellType.PROJECTILE_ENTITY || spell.getType() == EnumSpellType.PROJECTILE_ALL) && result.entityHit != caster) this.setDead(); } else Bewitchment.logger.warn("Spell is null for " + this + " with spell reg name of " + getSpellName()); } }
public ItemSpellPage(String id) { super(id); this.setMaxStackSize(1); this.setHasSubtypes(true); BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, new IBehaviorDispenseItem() { @Override public ItemStack dispense(IBlockSource source, ItemStack stack) { Spell s = ItemSpellPage.getSpellFromItemStack(stack); if (s != null) { EnumFacing enumfacing = source.getBlockState().getValue(BlockDispenser.FACING); Vec3d lookVect = new Vec3d(enumfacing.getDirectionVec()); if (s.canBeUsed(source.getWorld(), source.getBlockPos().offset(enumfacing), null)) { if (s.getType() == EnumSpellType.INSTANT) s.performEffect(new RayTraceResult(Type.MISS, lookVect, EnumFacing.UP, source.getBlockPos()), null, source.getWorld()); else { EntitySpellCarrier car = new EntitySpellCarrier(source.getWorld(), source.getBlockPos().getX() + 1.5 * lookVect.x + 0.5, source.getBlockPos().getY() + 0.5d + lookVect.y, source.getBlockPos().getZ() + 1.5 * lookVect.z + 0.5); car.setSpell(s); car.setCaster(null); car.shoot(car, 0, enumfacing.getHorizontalAngle(), 0, 1f, 0); source.getWorld().spawnEntity(car); } return ItemStack.EMPTY; } } return stack; } }); }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (caster != null && rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) { caster.attackEntityFrom(DamageSource.causeIndirectMagicDamage(caster, null), 1f); ((EntityLivingBase) rtrace.entityHit).heal(1f); } }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) { if (caster != null) rtrace.entityHit.attackEntityFrom(new EntityDamageSource(DamageSource.MAGIC.getDamageType(), caster), 1f); else rtrace.entityHit.attackEntityFrom(DamageSource.MAGIC, 0.5f); } }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (rtrace.typeOfHit == Type.BLOCK && caster != null) { world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(rtrace.hitVec, rtrace.hitVec.addVector(1, 1, 1)).grow(2)).forEach(ei -> { ei.setNoPickupDelay(); if (caster instanceof EntityPlayer) { ei.onCollideWithPlayer((EntityPlayer) caster); } else { ei.setPositionAndUpdate(caster.posX, caster.posY, caster.posZ); } }); } }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (caster != null && rtrace.typeOfHit == Type.BLOCK) { BlockPos dest = rtrace.getBlockPos().offset(EnumFacing.UP); caster.attemptTeleport(dest.getX() + 0.5, dest.getY() + 0.5, dest.getZ() + 0.5); } }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (rtrace.typeOfHit == Type.BLOCK) { Block block = world.getBlockState(rtrace.getBlockPos()).getBlock(); if ((caster == null || caster instanceof EntityPlayer) && (block instanceof BlockButton || block instanceof BlockLever || block instanceof BlockDoor || block instanceof BlockTrapDoor)) { block.onBlockActivated(world, rtrace.getBlockPos(), world.getBlockState(rtrace.getBlockPos()), (EntityPlayer) caster, EnumHand.MAIN_HAND, rtrace.sideHit, 0.5f, 0.5f, 0.5f); } } }
@Override public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) { if (rtrace.typeOfHit == Type.BLOCK) { BlockPos pos = rtrace.getBlockPos().offset(rtrace.sideHit); if (world.isAirBlock(pos)) world.setBlockState(pos, Blocks.WATER.getDefaultState(), 3); } }
@Override public void onLeftClick(LeftClickEvent event) { // check hitResult if(mc.objectMouseOver == null || mc.objectMouseOver.getBlockPos() == null || mc.objectMouseOver.typeOfHit != Type.BLOCK) return; // set id if(mode.getSelected() == Mode.ID.ordinal()) id = WBlock.getId(mc.objectMouseOver.getBlockPos()); }
private void updateTargetedBlock() { targetBlockPos = null; targetBlockSide = null; EntityPlayerSP player = Minecraft.getMinecraft().player; double distance = Minecraft.getMinecraft().playerController.getBlockReachDistance(); RayTraceResult r = RayTracer.rayTrace(player, distance, 1, false); if (r != null && Type.BLOCK.equals(r.typeOfHit)) { targetBlockPos = r.getBlockPos(); targetBlockSide = r.sideHit; } }
@SubscribeEvent public void onRightClick(PlayerInteractEvent.RightClickBlock event) { if (!event.getWorld().isRemote) { EntityPlayer player = event.getEntityPlayer(); IExPPlayer data = IExPPlayer.of(player); if (data.getThirst() < data.getMaxThirst(true) - 200) { RayTraceResult rtr = event.getWorld().rayTraceBlocks(player.getPositionEyes(1), player.getPositionEyes(1).add(player.getLook(1).scale(3)), true, false, false); if (rtr != null && rtr.typeOfHit == Type.BLOCK) { BlockPos pos = rtr.getBlockPos(); IBlockState hit = event.getWorld().getBlockState(pos); if (hit.getBlock() instanceof IWater && !((IWater)hit.getBlock()).isSalt(event.getWorld(), pos)) { int level = hit.getValue(BlockFluidBase.LEVEL); if (level > 0) { event.getWorld().setBlockState(pos, hit.withProperty(BlockFluidBase.LEVEL, level - 1)); } else { event.getWorld().setBlockToAir(pos); } data.setThirst(data.getThirst() + 200, true); event.getWorld().playSound(null, pos, SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.PLAYERS, 1, 1); } } } } }
@Override public void execute(EntityLivingBase target, @Nullable AbstractMorph morph) { float reachDistance = 32; Vec3d pos = new Vec3d(target.posX, target.posY + target.getEyeHeight(), target.posZ); Vec3d look = target.getLook(1.0F); Vec3d vec = pos.addVector(look.xCoord * reachDistance, look.yCoord * reachDistance, look.zCoord * reachDistance); RayTraceResult result = target.worldObj.rayTraceBlocks(pos, vec, false, false, true); if (result != null && result.typeOfHit == Type.BLOCK) { BlockPos block = result.getBlockPos(); if (target instanceof EntityPlayer && ((EntityPlayer) target).getCooledAttackStrength(0.0F) < 1) { return; } if (target.isSneaking() || !target.worldObj.getBlockState(block.offset(EnumFacing.UP)).getBlock().equals(Blocks.AIR)) { block = block.offset(result.sideHit); } double x = block.getX() + 0.5F; double y = block.getY() + 1.0F; double z = block.getZ() + 0.5F; target.worldObj.playSound(null, target.prevPosX, target.prevPosY, target.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.HOSTILE, 1.0F, 1.0F); target.setPositionAndUpdate(x, y, z); if (target instanceof EntityPlayer) { ((EntityPlayer) target).resetCooldown(); } target.worldObj.playSound(null, target.posX, target.posY, target.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.HOSTILE, 1.0F, 1.0F); } }
@Override public void execute(EntityLivingBase target, AbstractMorph morph) { if (target.worldObj.isRemote) { return; } float reachDistance = 5; Vec3d pos = new Vec3d(target.posX, target.posY + target.getEyeHeight(), target.posZ); Vec3d look = target.getLook(1.0F); Vec3d vec = pos.addVector(look.xCoord * reachDistance, look.yCoord * reachDistance, look.zCoord * reachDistance); RayTraceResult result = target.worldObj.rayTraceBlocks(pos, vec, false, false, true); if (result != null && result.typeOfHit == Type.BLOCK && target instanceof EntityPlayer) { BlockMorph block = new BlockMorph(); block.blockPos = result.getBlockPos(); block.block = target.worldObj.getBlockState(block.blockPos); block.name = "metamorph.Block"; target.worldObj.setBlockToAir(block.blockPos); MorphAPI.morph((EntityPlayer) target, block, true); } }
@Override protected void onImpact(RayTraceResult result) { if (result.typeOfHit != Type.MISS) { EntityLightningBolt lightning = new EntityLightningBolt(this.worldObj, result.hitVec.xCoord, result.hitVec.yCoord, result.hitVec.zCoord, false); this.worldObj.spawnEntityInWorld(lightning); } this.setDead(); }
@SideOnly (Side.CLIENT) public static void addLandingEffects(World world, BlockPos pos, IBlockState state, Vector3 entityPos, int numParticles) { //Speshal raytrace, from feet to, down. Vector3 start = entityPos.copy(); Vector3 end = start.copy().add(Vector3.down.copy().multiply(4)); RayTraceResult traceResult = world.rayTraceBlocks(start.vec3(), end.vec3(), true, false, true); if (traceResult != null && traceResult.typeOfHit == Type.BLOCK) { ParticleManager manager = Minecraft.getMinecraft().effectRenderer; Random randy = new Random(); BlockModelShapes modelProvider = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); try { state = state.getActualState(world, pos); } catch (Throwable ignored) { } IBakedModel model = modelProvider.getModelForState(state); state = state.getBlock().getExtendedState(state, world, pos); if (model instanceof IModelParticleProvider) { Set<TextureAtlasSprite> hitSprites = ((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos); List<TextureAtlasSprite> sprites = hitSprites.stream().filter(sprite -> !ignoredParticleSprites.contains(sprite)).collect(Collectors.toList()); double speed = 0.15000000596046448D; if (numParticles != 0) { for (int i = 0; i < numParticles; i++) { double mX = randy.nextGaussian() * speed; double mY = randy.nextGaussian() * speed; double mZ = randy.nextGaussian() * speed; manager.addEffect(DigIconParticle.newLandingParticle(world, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, sprites.get(randy.nextInt(sprites.size())))); } } } } }