use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method offer.
@Override
public DataTransactionResult offer(int x, int y, int z, DataManipulator<?, ?> manipulator, MergeFunction function) {
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
final ImmutableDataManipulator<?, ?> immutableDataManipulator = manipulator.asImmutable();
if (blockState.supports((Class) immutableDataManipulator.getClass())) {
final List<ImmutableValue<?>> old = new ArrayList<>(blockState.getValues());
final BlockState newState = blockState.with(immutableDataManipulator).get();
old.removeAll(newState.getValues());
setBlock(x, y, z, newState);
return DataTransactionResult.successReplaceResult(old, manipulator.getValues());
}
return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(manipulator, function)).orElseGet(() -> DataTransactionResult.failResult(manipulator.getValues()));
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinWorldGenBigMushroom method populate.
@Override
public void populate(org.spongepowered.api.world.World worldIn, Extent extent, Random random) {
Vector3i min = extent.getBlockMin();
Vector3i size = extent.getBlockSize();
World world = (World) worldIn;
BlockPos chunkPos = new BlockPos(min.getX(), min.getY(), min.getZ());
int x;
int z;
int n = this.mushroomsPerChunk.getFlooredAmount(random);
PopulatorObject type = MushroomTypes.BROWN.getPopulatorObject();
List<PopulatorObject> result;
for (int i = 0; i < n; ++i) {
x = random.nextInt(size.getX());
z = random.nextInt(size.getZ());
BlockPos pos = world.getHeight(chunkPos.add(x, 0, z));
if (this.override != null) {
Location<Extent> pos2 = new Location<>(extent, VecHelper.toVector3i(pos));
type = this.override.apply(pos2);
} else {
result = this.types.get(random);
if (result.isEmpty()) {
continue;
}
type = result.get(0);
}
if (type.canPlaceAt((org.spongepowered.api.world.World) world, pos.getX(), pos.getY(), pos.getZ())) {
type.placeObject((org.spongepowered.api.world.World) world, random, pos.getX(), pos.getY(), pos.getZ());
}
}
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinWorldGenFlowers method populate.
@Override
public void populate(org.spongepowered.api.world.World worldIn, Extent extent, Random random) {
Vector3i min = extent.getBlockMin();
Vector3i size = extent.getBlockSize();
World world = (World) worldIn;
BlockPos chunkPos = new BlockPos(min.getX(), min.getY(), min.getZ());
int x, y, z;
BlockPos blockpos;
// TODO should we actually do this division or let the x64 just be part
// of the contract
// The generate method makes 64 attempts, so divide the count by 64
int n = (int) Math.ceil(this.count.getFlooredAmount(random) / 64f);
PlantType type = PlantTypes.DANDELION;
List<PlantType> result;
for (int i = 0; i < n; ++i) {
x = random.nextInt(size.getX());
z = random.nextInt(size.getZ());
y = nextInt(random, world.getHeight(chunkPos.add(x, 0, z)).getY() + 32);
blockpos = chunkPos.add(x, y, z);
if (this.override != null) {
Location<Extent> pos = new Location<>(extent, VecHelper.toVector3i(blockpos));
type = this.override.apply(pos);
} else {
result = this.flowers.get(random);
if (result.isEmpty()) {
continue;
}
type = result.get(0);
}
BlockFlower.EnumFlowerType enumflowertype = (BlockFlower.EnumFlowerType) (Object) type;
BlockFlower blockflower = enumflowertype.getBlockType().getBlock();
if (enumflowertype != null && blockflower.getDefaultState().getMaterial() != Material.AIR) {
setGeneratedBlock(blockflower, enumflowertype);
generate(world, random, blockpos);
}
}
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinBlockDynamicLiquid method beforeSetBlockState.
// Capture Lava falling on Water forming Stone
@Inject(method = "updateTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z"))
private void beforeSetBlockState(net.minecraft.world.World worldIn, BlockPos sourcePos, IBlockState state, Random rand, CallbackInfo ci) {
Location<org.spongepowered.api.world.World> loc = new Location<>(((org.spongepowered.api.world.World) worldIn), sourcePos.getX(), sourcePos.getY(), sourcePos.getZ());
LocatableBlock source = LocatableBlock.builder().location(loc).build();
IBlockState newState = Blocks.STONE.getDefaultState();
ChangeBlockEvent.Modify event = SpongeCommonEventFactory.callChangeBlockEventModifyLiquidMix(worldIn, sourcePos, newState, source);
Transaction<BlockSnapshot> transaction = event.getTransactions().get(0);
if (event.isCancelled() || !transaction.isValid()) {
ci.cancel();
return;
}
if (!worldIn.setBlockState(sourcePos.down(), BlockUtil.toNative(transaction.getFinal().getState()))) {
ci.cancel();
}
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class DamageEventHandler method findFirstMatchingBlock.
public static Location<World> findFirstMatchingBlock(Entity entity, AxisAlignedBB bb, Predicate<IBlockState> predicate) {
int i = MathHelper.floor(bb.minX);
int j = MathHelper.floor(bb.maxX + 1.0D);
int k = MathHelper.floor(bb.minY);
int l = MathHelper.floor(bb.maxY + 1.0D);
int i1 = MathHelper.floor(bb.minZ);
int j1 = MathHelper.floor(bb.maxZ + 1.0D);
final IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) entity.world.getChunkProvider();
for (int k1 = i; k1 < j; ++k1) {
for (int l1 = k; l1 < l; ++l1) {
for (int i2 = i1; i2 < j1; ++i2) {
BlockPos blockPos = new BlockPos(k1, l1, i2);
final Chunk chunk = spongeChunkProvider.getLoadedChunkWithoutMarkingActive(blockPos.getX() >> 4, blockPos.getZ() >> 4);
if (chunk == null) {
continue;
}
if (predicate.test(chunk.getBlockState(blockPos))) {
return new Location<>((World) entity.world, k1, l1, i2);
}
}
}
}
// Entity is source of fire
return ((org.spongepowered.api.entity.Entity) entity).getLocation();
}
Aggregations