public boolean equalPos(RayTraceResult pos) { return pos.getBlockPos().equals(this.pos.getBlockPos()); } }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(!entity.world.isRemote && !burst.isFake()) { BlockPos coords = burst.getBurstSourceBlockPos(); if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !coords.equals(pos.getBlockPos()))) entity.world.createExplosion(entity, entity.posX, entity.posY, entity.posZ, 5F, true); } else dead = false; return dead; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(!entity.world.isRemote && !burst.isFake()) { BlockPos coords = burst.getBurstSourceBlockPos(); if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !coords.equals(pos.getBlockPos()))) entity.world.createExplosion(entity, entity.posX, entity.posY, entity.posZ, burst.getMana() / 50F, true); } else dead = false; return dead; }
@Override @SideOnly(Side.CLIENT) public List<BlockPos> getWireframesToDraw(EntityPlayer player, ItemStack stack) { if(getLokiRing(player) != stack) return ImmutableList.of(); RayTraceResult lookPos = Minecraft.getMinecraft().objectMouseOver; if(lookPos != null && lookPos.getBlockPos() != null && !player.world.isAirBlock(lookPos.getBlockPos()) && lookPos.entityHit == null) { List<BlockPos> list = getCursorList(stack); BlockPos origin = getOriginPos(stack); for (int i = 0; i < list.size(); i++) { if (origin.getY() != -1) { list.set(i, list.get(i).add(origin)); } else { list.set(i, list.get(i).add(lookPos.getBlockPos())); } } return list; } return ImmutableList.of(); }
@Override protected void onImpact(RayTraceResult pos) { if (world.isRemote) return; EntityLivingBase thrower = getThrower(); if(pos.entityHit != null && thrower != null && pos.entityHit != thrower && !pos.entityHit.isDead) { if(thrower instanceof EntityPlayer) pos.entityHit.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) thrower), Math.random() < 0.25 ? 10 : 5); else pos.entityHit.attackEntityFrom(DamageSource.GENERIC, Math.random() < 0.25 ? 10 : 5); } if (pos.getBlockPos() != null) { IBlockState state = world.getBlockState(pos.getBlockPos()); if(ConfigHandler.blockBreakParticles && !state.getBlock().isAir(state, world, pos.getBlockPos())) world.playEvent(2001, pos.getBlockPos(), Block.getStateId(state)); } setDead(); }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); if(!entity.world.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit.getOpposite()); if(entity.world.isAirBlock(pos_) || entity.world.getBlockState(pos_).getBlock().isReplaceable(entity.world, pos_)) { IBlockState state = entity.world.getBlockState(pos.getBlockPos()); TileEntity tile = entity.world.getTileEntity(pos.getBlockPos()); if(state.getPushReaction() == EnumPushReaction.NORMAL && state.getBlock() != Blocks.OBSIDIAN && state.getBlockHardness(entity.world, pos_) >= 0 && tile == null) { entity.world.destroyBlock(pos.getBlockPos(), false); entity.world.setBlockState(pos_, state, 1 | 2); } } } return dead; }
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) { RayTraceResult mop = world.rayTraceBlocks(start.toVec3D(), end.toVec3D()); if(mop == null) return prevresistance; if(mop.typeOfHit == RayTraceResult.Type.BLOCK) { Block block = world.getBlockState(mop.getBlockPos()).getBlock(); if(world.isAirBlock(mop.getBlockPos())) return prevresistance; return prevresistance + block.getExplosionResistance(null) + 0.3F; } else return prevresistance; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(!entity.world.isRemote && !burst.isFake()) { BlockPos coords = burst.getBurstSourceBlockPos(); if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !pos.getBlockPos().equals(coords))) { ItemStack fireworkStack = generateFirework(burst.getColor()); EntityFireworkRocket rocket = new EntityFireworkRocket(entity.world, entity.posX, entity.posY, entity.posZ, fireworkStack); entity.world.spawnEntity(rocket); } } else dead = false; return dead; }
@Override protected void onImpact(@Nonnull RayTraceResult pos) { if(pos.getBlockPos() != null && !world.isRemote) { List<BlockPos> coordsList = getCoordsToPut(pos.getBlockPos()); world.playEvent(2002, new BlockPos(this), 8); for(BlockPos coords : coordsList) { world.setBlockState(coords, Blocks.END_STONE.getDefaultState()); if(Math.random() < 0.1) world.playEvent(2001, coords, Block.getStateId(Blocks.END_STONE.getDefaultState())); } setDead(); } }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { Botania.proxy.removeSextantMultiblock(); ItemStack stack = player.getHeldItem(hand); if(!player.isSneaking()) { RayTraceResult pos = ToolCommons.raytraceFromEntity(world, player, false, 128); if(pos != null && pos.entityHit == null && pos.getBlockPos() != null) { if(!world.isRemote) { ItemNBTHelper.setInt(stack, TAG_SOURCE_X, pos.getBlockPos().getX()); ItemNBTHelper.setInt(stack, TAG_SOURCE_Y, pos.getBlockPos().getY()); ItemNBTHelper.setInt(stack, TAG_SOURCE_Z, pos.getBlockPos().getZ()); } } else ItemNBTHelper.setInt(stack, TAG_SOURCE_Y, -1); player.setActiveHand(hand); } return ActionResult.newResult(EnumActionResult.SUCCESS, stack); }
@SubscribeEvent public static void onWorldRenderLast(RenderWorldLastEvent event) { Minecraft mc = Minecraft.getMinecraft(); if(mc.player != null && mc.objectMouseOver != null && mc.objectMouseOver.getBlockPos() != null && (!mc.player.isSneaking() || anchor != null)) { renderPlayerLook(mc.player, mc.objectMouseOver); } }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); if(!entity.world.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit); Block blockAt = entity.world.getBlockState(pos.getBlockPos()).getBlock(); Block blockAt_ = entity.world.getBlockState(pos_).getBlock(); if(blockAt == ModBlocks.manaFlame) entity.world.setBlockState(pos.getBlockPos(), Blocks.AIR.getDefaultState()); else if(blockAt_.isAir(entity.world.getBlockState(pos_), entity.world, pos_) || blockAt_.isReplaceable(entity.world, pos_)) { entity.world.setBlockState(pos_, ModBlocks.manaFlame.getDefaultState()); TileEntity tile = entity.world.getTileEntity(pos_); if(tile instanceof TileManaFlame) ((TileManaFlame) tile).setColor(burst.getColor()); } } return dead; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(burst.isFake() || pos.getBlockPos() == null) return dead; Block block = entity.world.getBlockState(pos.getBlockPos()).getBlock(); if(block == ModBlocks.pistonRelay) { BlockPistonRelay.DimWithPos key = ((BlockPistonRelay) ModBlocks.pistonRelay).mappedPositions.get(new BlockPistonRelay.DimWithPos(entity.world.provider.getDimension(), pos.getBlockPos())); if(key != null) { if(key.dim == entity.world.provider.getDimension()) { entity.setPosition(key.blockPos.getX() + 0.5, key.blockPos.getY() + 0.5, key.blockPos.getZ() + 0.5); burst.setCollidedAt(key.blockPos); entity.getEntityData().setBoolean(TAG_WARPED, true); return false; } } } return dead; }
@Override protected void onImpact(@Nonnull RayTraceResult pos) { switch (pos.typeOfHit) { case BLOCK: { Block block = world.getBlockState(pos.getBlockPos()).getBlock(); if(!(block instanceof BlockBush) && !(block instanceof BlockLeaves)) setDead(); break; } case ENTITY: { if (pos.entityHit == getTargetEntity()) setDead(); break; } default: { setDead(); break; } } }
@Override public BlockPos getBinding(ItemStack stack) { BlockPos bound = getBoundTile(stack); if(bound.getY() != -1) return bound; RayTraceResult pos = Minecraft.getMinecraft().objectMouseOver; if(pos != null && pos.typeOfHit == RayTraceResult.Type.BLOCK) { TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(pos.getBlockPos()); if(tile != null && tile instanceof ITileBound) { BlockPos coords = ((ITileBound) tile).getBinding(); return coords; } } return null; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(!isManaBlock && pos.entityHit == null && pos.getBlockPos() != null) { BlockPos coords = burst.getBurstSourceBlockPos(); if(!coords.equals(pos.getBlockPos())) { Vector3 currentMovementVec = new Vector3(entity.motionX, entity.motionY, entity.motionZ); EnumFacing dir = pos.sideHit; Vector3 normalVector = new Vector3(dir.getXOffset(), dir.getYOffset(), dir.getZOffset()).normalize(); Vector3 movementVec = normalVector.multiply(-2 * currentMovementVec.dotProduct(normalVector)).add(currentMovementVec); burst.setMotion(movementVec.x, movementVec.y, movementVec.z); dead = false; } } return dead; }
@Override public String getBlockName(World world, RayTraceResult pos, EntityPlayer player) { BlockPos bPos = pos.getBlockPos(); IBlockState state = world.getBlockState(bPos); ItemStack stack = state.getBlock().getPickBlock(state, pos, world, bPos, player); if(stack.isEmpty()) stack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); if(stack.isEmpty()) return null; String name = stack.getDisplayName(); if(name == null || name.isEmpty()) return null; return name; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { if(!entity.world.isRemote && !burst.isFake() && pos.getBlockPos() != null) { int harvestLevel = ConfigHandler.harvestLevelWeight; BlockPos bPos = pos.getBlockPos(); Block block = entity.world.getBlockState(bPos).getBlock(); IBlockState state = entity.world.getBlockState(bPos); int neededHarvestLevel = block.getHarvestLevel(state); if(entity.world.isAirBlock(bPos.down()) && state.getBlockHardness(entity.world, bPos) != -1 && neededHarvestLevel <= harvestLevel && entity.world.getTileEntity(bPos) == null && block.canSilkHarvest(entity.world, bPos, state, null)) { state = TECHNICAL_BLOCK_REMAP.getOrDefault(state, state); EntityFallingBlock falling = new EntityFallingBlock(entity.world, bPos.getX() + 0.5, bPos.getY(), bPos.getZ() + 0.5, state); falling.fallTime = 1; entity.world.setBlockToAir(bPos); ((WorldServer) entity.world).spawnParticle(EnumParticleTypes.FALLING_DUST, bPos.getX() + 0.5, bPos.getY() + 0.5, bPos.getZ() + 0.5, 10, 0.45, 0.45, 0.45, 5, new int[] {Block.getStateId(state)}); entity.world.spawnEntity(falling); } } return dead; }
@Override protected void onImpact(@Nonnull RayTraceResult var1) { if(!world.isRemote) { if(var1 != null) { EnumFacing dir = var1.sideHit; if(dir != null && dir.getAxis() != EnumFacing.Axis.Y) { BlockPos pos = var1.getBlockPos().offset(dir); while(pos.getY() > 0) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block.isAir(state, world, pos)) { IBlockState stateSet = ModBlocks.solidVines.getDefaultState().withProperty(propMap.get(dir.getOpposite()), true); world.setBlockState(pos, stateSet, 1 | 2); world.playEvent(2001, pos, Block.getStateId(stateSet)); pos = pos.down(); } else break; } } } this.world.setEntityState(this, (byte)3); setDead(); } }
@Override public void onBlockClicked( World worldIn, BlockPos pos, EntityPlayer playerIn ) { if( Platform.isClient() ) { final RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver; if( rtr != null && rtr.typeOfHit == Type.BLOCK && pos.equals( rtr.getBlockPos() ) ) { final Vec3d hitVec = rtr.hitVec.subtract( new Vec3d( pos ) ); if( this.cb( worldIn, pos ).clicked( playerIn, EnumHand.MAIN_HAND, hitVec ) ) { NetworkHandler.instance() .sendToServer( new PacketClick( pos, rtr.sideHit, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, EnumHand.MAIN_HAND, true ) ); } } } }