下面列出了net.minecraft.util.math.BlockPos#distanceSq ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public float getManaInfluence(World world, BlockPos pos) {
ChunkPos chunkPos = new ChunkPos(pos);
float mana = 0.0f;
for (int dx = -4 ; dx <= 4 ; dx++) {
for (int dz = -4 ; dz <= 4 ; dz++) {
ChunkPos cp = new ChunkPos(chunkPos.x + dx, chunkPos.z + dz);
ManaSphere sphere = getOrCreateSphereAt(world, cp);
if (sphere.getRadius() > 0) {
double distanceSq = pos.distanceSq(sphere.getCenter());
if (distanceSq < sphere.getRadius() * sphere.getRadius()) {
double distance = Math.sqrt(distanceSq);
mana += (sphere.getRadius() - distance) / sphere.getRadius();
}
}
}
}
return mana;
}
public float getManaStrength(World world, BlockPos pos) {
ChunkPos chunkPos = new ChunkPos(pos);
float mana = 0.0f;
for (int dx = -4 ; dx <= 4 ; dx++) {
for (int dz = -4 ; dz <= 4 ; dz++) {
ChunkPos cp = new ChunkPos(chunkPos.x + dx, chunkPos.z + dz);
ManaSphere sphere = getOrCreateSphereAt(world, cp);
if (sphere.getRadius() > 0) {
double distanceSq = pos.distanceSq(sphere.getCenter());
if (distanceSq < sphere.getRadius() * sphere.getRadius()) {
double distance = Math.sqrt(distanceSq);
double influence = (sphere.getRadius() - distance) / sphere.getRadius();
mana += influence * sphere.getCurrentMana();
}
}
}
}
return mana;
}
private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) {
IBlockState blockHere = getWorld().getBlockState(checkPos);
boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos);
if (blockHere.getBlock() instanceof BlockLiquid ||
blockHere.getBlock() instanceof IFluidBlock) {
IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), checkPos, null);
FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
if (drainStack != null && drainStack.amount > 0) {
this.fluidSourceBlocks.add(checkPos);
}
shouldCheckNeighbours = true;
}
if (shouldCheckNeighbours) {
int maxPumpRange = getMaxPumpRange();
for (EnumFacing facing : EnumFacing.VALUES) {
BlockPos offsetPos = checkPos.offset(facing);
if (offsetPos.distanceSq(pumpHeadPos) > maxPumpRange * maxPumpRange)
continue; //do not add blocks outside bounds
if (!fluidSourceBlocks.contains(offsetPos) &&
!blocksToCheck.contains(offsetPos)) {
this.blocksToCheck.add(offsetPos);
}
}
}
}
public float extractMana(World world, BlockPos pos) {
float manaInfluence = getManaInfluence(world, pos);
if (manaInfluence <= 0) {
return 0;
}
ChunkPos chunkPos = new ChunkPos(pos);
float extracted = 0.0f;
for (int dx = -4 ; dx <= 4 ; dx++) {
for (int dz = -4 ; dz <= 4 ; dz++) {
ChunkPos cp = new ChunkPos(chunkPos.x + dx, chunkPos.z + dz);
ManaSphere sphere = getOrCreateSphereAt(world, cp);
if (sphere.getRadius() > 0) {
double distanceSq = pos.distanceSq(sphere.getCenter());
if (distanceSq < sphere.getRadius() * sphere.getRadius()) {
double distance = Math.sqrt(distanceSq);
double influence = (sphere.getRadius() - distance) / sphere.getRadius();
float currentMana = sphere.getCurrentMana();
if (influence > currentMana) {
influence = currentMana;
}
currentMana -= influence;
extracted += influence;
sphere.setCurrentMana(currentMana);
markDirty();
}
}
}
}
return extracted;
}
@Override
public int compare(BlockPos pos1, BlockPos pos2)
{
double dist1 = pos1.distanceSq(this.posReference);
double dist2 = pos2.distanceSq(this.posReference);
if (dist1 == dist2)
{
return 0;
}
return dist1 < dist2 == this.closestFirst ? -1 : 1;
}
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
Entity targetEntity = spell.getVictim(world);
BlockPos targetPos = spell.getTargetPos();
Entity caster = spell.getCaster(world);
double range = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell) / 2;
double time = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 10;
if (!spellRing.taxCaster(world, spell, true)) return false;
if (targetEntity != null) {
world.playSound(null, targetEntity.getPosition(), ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
targetEntity.extinguish();
if (targetEntity instanceof EntityLivingBase) {
((EntityLivingBase) targetEntity).addPotionEffect(new PotionEffect(ModPotions.SLIPPERY, (int) time, 0, true, false));
}
}
if (targetPos != null) {
world.playSound(null, targetPos, ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
for (BlockPos pos : BlockPos.getAllInBox(targetPos.add(-range, -range, -range), targetPos.add(range + 1, range + 1, range + 1))) {
double dist = pos.distanceSq(targetPos);
if (dist > range) continue;
for (EnumFacing facing : EnumFacing.VALUES) {
IBlockState state = world.getBlockState(pos.offset(facing));
if (state.getBlock() == Blocks.FIRE) {
BlockUtils.breakBlock(world, pos.offset(facing), state, BlockUtils.makeBreaker(world, pos, caster));
}
}
BlockPos up = pos.offset(EnumFacing.UP);
if (world.getBlockState(pos).isSideSolid(world, pos, EnumFacing.UP) && world.isAirBlock(up)) {
int layerSize = (int) (Math.max(1, Math.min(8, Math.max(1, (dist / range) * 6.0))));
layerSize = Math.max(1, Math.min(layerSize + RandUtil.nextInt(-1, 1), 8));
BlockUtils.placeBlock(world, up, Blocks.SNOW_LAYER.getDefaultState().withProperty(BlockSnow.LAYERS, layerSize), BlockUtils.makePlacer(world, up, caster));
}
if (world.getBlockState(pos).getBlock() == Blocks.WATER) {
BlockUtils.placeBlock(world, pos, Blocks.ICE.getDefaultState(), BlockUtils.makePlacer(world, pos, caster));
}
}
}
return true;
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos,
EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState clickedState = worldIn.getBlockState(pos);
Block block = clickedState.getBlock();
TileEntity currentTile = worldIn.getTileEntity(pos);
ItemStack stack = player.getHeldItem(hand);
if (currentTile instanceof IVSNodeProvider && !worldIn.isRemote) {
ICapabilityLastRelay inst = stack
.getCapability(ValkyrienSkiesControl.lastRelayCapability, null);
if (inst != null) {
if (!inst.hasLastRelay()) {
inst.setLastRelay(pos);
// Draw a wire in the player's hand after this
} else {
BlockPos lastPos = inst.getLastRelay();
double distanceSq = lastPos.distanceSq(pos);
TileEntity lastPosTile = worldIn.getTileEntity(lastPos);
// System.out.println(lastPos.toString());
if (!lastPos.equals(pos) && lastPosTile != null && currentTile != null) {
if (distanceSq < VSConfig.relayWireLength * VSConfig.relayWireLength) {
IVSNode lastPosNode = ((IVSNodeProvider) lastPosTile).getNode();
IVSNode currentPosNode = ((IVSNodeProvider) currentTile).getNode();
if (lastPosNode != null && currentPosNode != null) {
if (currentPosNode.isLinkedToNode(lastPosNode)) {
player.sendMessage(
new TextComponentString("These nodes are already linked!"));
} else if (currentPosNode.canLinkToOtherNode(lastPosNode)) {
currentPosNode.makeConnection(lastPosNode);
stack.damageItem(1, player);
} else {
// Tell the player what they did wrong
player.sendMessage(new TextComponentString(TextFormatting.RED +
I18n.format("message.vs_control.error_relay_wire_limit", VSConfig.networkRelayLimit)));
}
inst.setLastRelay(null);
}
} else {
player.sendMessage(
new TextComponentString(TextFormatting.RED +
I18n.format("message.vs_control.error_relay_wire_length")));
inst.setLastRelay(null);
}
} else {
inst.setLastRelay(pos);
}
}
}
}
if (currentTile instanceof IVSNodeProvider) {
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
@Override
protected TreeReturn gen(Random random, World world, Center c, IslandMap m, String wood)
{
tsm = TreeRegistry.instance.managerFromString(wood);
tc = TreeRegistry.instance.treeFromString(wood);
if(tsm == null || tc.equals(""))
{
TFC.log.info("Can't locate :" + wood);
return new TreeReturn(TreeReturnEnum.None, 0);
}
BlockPos genPos = centerPos.add(-20+random.nextInt(41), 0, -20+random.nextInt(41));
if(genPos.distanceSq(centerPos) > 400)//20*20
return new TreeReturn(TreeReturnEnum.None, 0);
genPos = genPos.add(0, map.convertHeightToMC(c.getElevation())+Global.SEALEVEL-1, 0);
int y = world.getTopSolidOrLiquidBlock(genPos).getY();
int growthStage = 0;
if(m.getParams().getIslandMoisture().isGreaterThan(Moisture.LOW) && !m.getParams().hasFeature(Feature.Desert))
{
if(c.getMoisture().isGreaterThan(Moisture.MEDIUM) && m.getParams().getIslandMoisture().isGreaterThan(Moisture.MEDIUM))
{
growthStage = random.nextInt(3);
}
else if(c.getMoisture().isGreaterThan(Moisture.LOW))
{
growthStage = random.nextInt(2);
}
}
TreeReturnEnum grown = TreeReturnEnum.None;
for(;growthStage >= 0 && grown == TreeReturnEnum.None; growthStage--)
{
schem = tsm.getRandomSchematic(random, growthStage);
BlockPos treePos = genPos.add(-(schem.getCenterX()-1), 0, -(schem.getCenterZ()-1));
IBlockState s = world.getBlockState(treePos);
if( schem != null && canGrowHere(world, treePos, schem, Math.max(growthStage, 1)))
{
if(buildTree(schem, tc, world, random, treePos, c))
{
grown = TreeReturnEnum.fromSize(growthStage);
}
}
}
return new TreeReturn(grown, schem.getBaseCount());
}
protected TreeReturn gen(Random random, World world, Center c, IslandMap m, String wood)
{
tsm = TreeRegistry.instance.managerFromString(wood);
tc = TreeRegistry.instance.treeFromString(wood);
if(tsm == null || tc.equals(""))
{
TFC.log.info("Can't locate :" + wood);
return new TreeReturn(TreeReturnEnum.None, 0);
}
BlockPos genPos = centerPos.add(-20+random.nextInt(41), 0, -20+random.nextInt(41));
if(genPos.distanceSq(centerPos) > 400)//20*20
return new TreeReturn(TreeReturnEnum.None, 0);
genPos = world.getTopSolidOrLiquidBlock(genPos);
int growthStage = 0;
if(m.getParams().getIslandMoisture().isGreaterThan(Moisture.LOW) && !m.getParams().hasFeature(Feature.Desert))
{
if(c.getMoisture().isGreaterThan(Moisture.MEDIUM) && m.getParams().getIslandMoisture().isGreaterThan(Moisture.MEDIUM))
{
growthStage = random.nextInt(3);
}
else if(c.getMoisture().isGreaterThan(Moisture.LOW))
{
growthStage = random.nextInt(2);
}
}
TreeReturnEnum grown = TreeReturnEnum.None;
for(;growthStage >= 0 && grown == TreeReturnEnum.None; growthStage--)
{
schem = tsm.getRandomSchematic(random, growthStage);
if( schem != null && canGrowHere(world, genPos.down(), schem, Math.max(growthStage, 1)))
{
if(buildTree(schem, tc, world, random, genPos, c))
{
grown = TreeReturnEnum.fromSize(growthStage);
}
}
}
return new TreeReturn(grown, schem.getBaseCount());
}
public double getDistance(BlockPos a, BlockPos b)
{
return a.distanceSq(b.getX(), b.getY(), b.getZ());
}