下面列出了net.minecraft.util.DefaultedList#net.minecraft.world.IWorld 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean generate(IWorld iWorld, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig defaultFeatureConfig) {
if (iWorld.getBlockState(pos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
setSpawner(iWorld, pos, EntityType.SPIDER);
for (int i = 0; i < 64; ++i) {
BlockPos pos_2 = pos.add(random.nextInt(6) - random.nextInt(6), random.nextInt(3) - random.nextInt(3), random.nextInt(6) - random.nextInt(6));
if (iWorld.isAir(pos_2) || iWorld.getBlockState(pos_2).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
iWorld.setBlockState(pos_2, Blocks.COBWEB.getDefaultState(), 2);
}
}
BlockPos chestPos = pos.add(random.nextInt(4) - random.nextInt(4), 0, random.nextInt(4) - random.nextInt(4));
iWorld.setBlockState(chestPos, StructurePiece.method_14916(iWorld, chestPos, Blocks.CHEST.getDefaultState()), 2);
LootableContainerBlockEntity.setLootTable(iWorld, random, chestPos, TheHallow.id("chests/spider_lair"));
return true;
} else {
return false;
}
}
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
for (int i = 0; i < 10; i++) {
BlockPos pos2 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
if (world.isAir(pos2)) {
int height = 1 + random.nextInt(random.nextInt(3) + 1);
for (int j = 0; j < height; j++) {
if (HallowedBlocks.RESTLESS_CACTUS.getDefaultState().canPlaceAt(world, pos2)) {
world.setBlockState(pos2.up(j), HallowedBlocks.RESTLESS_CACTUS.getDefaultState(), 2);
}
}
}
}
return true;
}
private void generateBarrowColumn(IWorld world, Random rand, int lowY, int heightOffset, BlockPos.Mutable pos, SurfaceConfig surfaceConfig) {
int upperY = lowY + heightOffset;
for (int y = upperY; y >= lowY; --y) {
pos.setY(y);
if (y == upperY) {
world.setBlockState(pos, surfaceConfig.getTopMaterial(), 19);
} else if (y > upperY - 3) {
world.setBlockState(pos, surfaceConfig.getUnderMaterial(), 19);
} else if (y == lowY + 2 && rand.nextInt(32) == 0) {
if (rand.nextInt(3) == 0) {
setLootChest(world, pos, LOOT_TABLE, rand);
} else {
setSpawner(world, pos, BARROW_WIGHT);
}
} else {
world.setBlockState(pos, y <= lowY + 1 ? STONE : AIR, 19);
}
}
}
private ActionResult tryEat(IWorld iWorld, BlockPos pos, BlockState state, PlayerEntity player) {
if (!player.canConsume(false)) {
return ActionResult.PASS;
}
float saturation = 0.1F;
TrinketComponent trinketPlayer = TrinketsApi.getTrinketComponent(player);
ItemStack mainHandStack = trinketPlayer.getStack("hand:ring");
ItemStack offHandStack = trinketPlayer.getStack("offhand:ring");
if (mainHandStack.getItem().equals(HallowedItems.PUMPKIN_RING) || offHandStack.getItem().equals(HallowedItems.PUMPKIN_RING)) {
saturation = 0.3F;
}
player.getHungerManager().add(2, saturation);
int bites = state.get(BITES);
if (bites > 1) {
iWorld.setBlockState(pos, state.with(BITES, bites - 1), 3);
} else {
iWorld.removeBlock(pos, false);
}
return ActionResult.SUCCESS;
}
@Override
public List<ItemStack> onSheared(ItemStack item, IWorld world, BlockPos pos, int fortune) {
List<ItemStack> drops = new java.util.ArrayList<>();
if (!this.world.isClient) {
this.setSheared(true);
int count = 1 + this.random.nextInt(3);
ItemConvertible wool = DROPS.get(this.getColor());
for (int i = 0; i < count; i++) {
drops.add(new ItemStack(wool));
}
}
this.playSound(SoundEvents.ENTITY_SHEEP_SHEAR, 1.0F, 1.0F);
return drops;
}
@Override
public boolean tryFillWithFluid(IWorld iWorld_1, BlockPos blockPos_1, BlockState blockState_1, FluidState fluidState_1) {
return ((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1).getComponent(
WrappingUtil.convert(iWorld_1),
(Position) blockPos_1,
Components.FLUID_COMPONENT
).map(container -> {
FluidStack filled = FluidStack.of(WrappingUtil.convert(fluidState_1.getFluid()), 1000);
FluidStack ret = container.insert(filled, true);
if (ret.isEmpty()) {
container.insert(filled);
return true;
} else {
return false;
}
}).orElse(false);
}
/**
* Re-colors this block in the world.
*
* @param state The current state
* @param world The world
* @param pos Block position
* @param facing ??? (this method has no usages)
* @param color Color to recolor to.
* @return if the block was affected
*/
@SuppressWarnings("unchecked")
default boolean recolorBlock(BlockState state, IWorld world, BlockPos pos, Direction facing, DyeColor color) {
for (Property<?> prop : state.getProperties()) {
if (prop.getName().equals("color") && prop.getType() == DyeColor.class) {
DyeColor current = (DyeColor) state.get(prop);
if (current != color && prop.getValues().contains(color)) {
world.setBlockState(pos, state.with(((Property<DyeColor>) prop), color), 3);
return true;
}
}
}
return false;
}
public <X> Mono<X> sbx$getComponent(WorldReader reader, Position position, BlockState state, Component<X> component, Mono<Direction> side) {
if (component == Components.INVENTORY_COMPONENT) {
if (this instanceof InventoryProvider) {
SidedInventory inventory = ((InventoryProvider) this).getInventory((net.minecraft.block.BlockState) state, (IWorld) reader, (BlockPos) position);
if (side.isPresent())
return Mono.of(new SidedRespective(inventory, side.get())).cast();
return Mono.of(new V2SInventory(inventory)).cast();
}
net.minecraft.block.entity.BlockEntity entity = ((BlockView) reader).getBlockEntity((BlockPos) position);
if (entity instanceof Inventory) {
if (side.isPresent() && entity instanceof SidedInventory)
return Mono.of(new SidedRespective((SidedInventory) entity, side.get())).cast();
return Mono.of(new V2SInventory((Inventory) entity)).cast();
}
}
if (component == Components.FLUID_COMPONENT) {
if (this instanceof Waterloggable) {
FluidLoggingContainer container = new FluidLoggingContainer((FluidLoggable) this, reader, position, state, side);
return Mono.of(container).cast();
}
}
return Mono.empty();
}
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
for (BlockState state1 = world.getBlockState(pos); (state1.isAir() || state1.matches(BlockTags.LEAVES)) && pos.getY() > 0; state1 = world.getBlockState(pos)) {
pos = pos.down();
}
for (int int_1 = 0; int_1 < 4; ++int_1) {
BlockPos pos2 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
if (world.isAir(pos2) && state.canPlaceAt(world, pos2)) {
world.setBlockState(pos2, state, 2);
}
}
return true;
}
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
int numCrop = 0;
for (int i = 0; i < 64; ++i) {
BlockPos randomBlockPos = blockPos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
if (world.isAir(randomBlockPos) && world.getBlockState(randomBlockPos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
world.setBlockState(randomBlockPos, this.crop, 2);
++numCrop;
}
}
return numCrop > 0;
}
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
int numCrop = 0;
for (int i = 0; i < 64; ++i) {
BlockPos randomBlockPos = blockPos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
if (world.isAir(randomBlockPos) && world.getBlockState(randomBlockPos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
world.setBlockState(randomBlockPos, this.choiceSelector.getSelection(random, randomBlockPos), 2);
++numCrop;
}
}
return numCrop > 0;
}
public static boolean hasWater(IWorld worldIn, BlockPos pos)
{
for (BlockPos blockpos$mutableblockpos : BlockPos.iterate(pos.add(-4, -4, -4), pos.add(4, 1, 4)))
{
if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
{
return true;
}
}
return false;
}
private boolean generate(IWorld world, Random rand, BlockPos pos, CoordinateFunction<SurfaceConfig> configFunction) {
int centreX = pos.getX() + rand.nextInt(16) - 8;
int centreZ = pos.getZ() + rand.nextInt(16) - 8;
int lowY = pos.getY() - 3;
int radius = rand.nextInt(6) + 7;
int height = rand.nextInt(4) + 6;
double radiusSquared = radius * radius;
Vec3d origin = new Vec3d(centreX, 0, centreZ);
BlockPos.Mutable posMutable = new BlockPos.Mutable();
for (int xOffset = -radius; xOffset <= radius; ++xOffset) {
int x = centreX + xOffset;
for (int zOffset = -radius; zOffset <= radius; ++zOffset) {
int z = centreZ + zOffset;
Vec3d position = new Vec3d(x, 0, z);
double sqrDistTo = position.squaredDistanceTo(origin);
if (sqrDistTo <= radiusSquared) {
double progress = MathHelper.perlinFade(sqrDistTo / radiusSquared);
int heightOffset = (int) MathHelper.lerp(progress, height, 0);
heightOffset += (int) MathHelper.lerp(progress, offsetNoise.sample(x, z), 0);
posMutable.setX(x);
posMutable.setZ(z);
this.generateBarrowColumn(world, rand, lowY, heightOffset, posMutable, configFunction.get(posMutable));
}
}
}
return true;
}
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, HallowedOreFeatureConfig oreFeatureConfig) {
float randomNumberFromZeroToPi = random.nextFloat() * 3.1415927F;
float dividedSize = (float) oreFeatureConfig.size / 8.0F;
int ceilSize = MathHelper.ceil(((float) oreFeatureConfig.size / 16.0F * 2.0F + 1.0F) / 2.0F);
double positiveX = (blockPos.getX() + MathHelper.sin(randomNumberFromZeroToPi) * dividedSize);
double negativeX = (blockPos.getX() - MathHelper.sin(randomNumberFromZeroToPi) * dividedSize);
double positiveZ = (blockPos.getZ() + MathHelper.cos(randomNumberFromZeroToPi) * dividedSize);
double negativeZ = (blockPos.getZ() - MathHelper.cos(randomNumberFromZeroToPi) * dividedSize);
double positiveY = (blockPos.getY() + random.nextInt(3) - 2);
double negativeY = (blockPos.getY() + random.nextInt(3) - 2);
int startX = blockPos.getX() - MathHelper.ceil(dividedSize) - ceilSize;
int y = blockPos.getY() - 2 - ceilSize;
int startZ = blockPos.getZ() - MathHelper.ceil(dividedSize) - ceilSize;
int xSize = 2 * (MathHelper.ceil(dividedSize) + ceilSize);
int int_7 = 2 * (2 + ceilSize);
for (int x = startX; x <= startX + xSize; ++x) {
for (int z = startZ; z <= startZ + xSize; ++z) {
if (y <= world.getTopY(Type.OCEAN_FLOOR_WG, x, z)) {
return this.generateVeinPart(world, random, oreFeatureConfig, positiveX, negativeX, positiveZ, negativeZ, positiveY, negativeY, startX, y, startZ, xSize, int_7);
}
}
}
return false;
}
default void setLootChest(IWorld world, BlockPos pos, Identifier lootTable, Random rand) {
world.setBlockState(pos, Blocks.CHEST.getDefaultState(), 2);
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof ChestBlockEntity) {
((ChestBlockEntity) entity).setLootTable(lootTable, rand.nextLong());
}
}
@Override
public boolean tryFillWithFluid(IWorld world, BlockPos pos, BlockState blockState, FluidState fluidState) {
if (blockState.contains(Properties.WATERLOGGED)) {
return Waterloggable.super.tryFillWithFluid(world, pos, blockState, fluidState);
} else {
return false;
}
}
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState state2, IWorld world, BlockPos pos, BlockPos pos2) {
if (!state.canPlaceAt(world, pos)) {
world.getBlockTickScheduler().schedule(pos, this, 1);
}
return super.getStateForNeighborUpdate(state, direction, state2, world, pos, pos2);
}
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction dir, BlockState state2, IWorld iworld, BlockPos pos1, BlockPos pos2) {
if (dir == Direction.UP && state2.getBlock() == HallowedBlocks.WITCH_WATER_BLOCK) {
iworld.getBlockTickScheduler().schedule(pos1, this, this.getTickRate(iworld));
}
return super.getStateForNeighborUpdate(state, dir, state2, iworld, pos1, pos2);
}
@Redirect( method = "method_15172", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/IWorld;updateNeighbors(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V"
))
private void skipUpdateNeighbours(IWorld iWorld, BlockPos var1, Block var2)
{
if (!CarpetSettings.impendingFillSkipUpdates)
iWorld.updateNeighbors(var1, var2);
}
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction dir, BlockState state2, IWorld world, BlockPos pos, BlockPos pos2) {
if (!state.canPlaceAt(world, pos)) {
return HallowedBlocks.WITCH_WATER_BLOCK.getDefaultState();
} else {
if (dir == Direction.DOWN) {
world.setBlockState(pos, HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN.getDefaultState().with(DRAG, calculateDrag(world, pos2)), 2);
} else if (dir == Direction.UP && state2.getBlock() != HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN && isStillWater(world, pos2)) {
world.getBlockTickScheduler().schedule(pos, this, this.getTickRate(world));
}
world.getFluidTickScheduler().schedule(pos, HallowedFluids.WITCH_WATER, HallowedFluids.WITCH_WATER.getTickRate(world));
return super.getStateForNeighborUpdate(state, dir, state2, world, pos, pos2);
}
}
public static void shearEntity(ItemStack stack, IWorld world, BlockPos pos, IShearable target) {
if (!(target instanceof Entity)) {
throw new IllegalArgumentException("Tried to call shearEntity on something that was not an entity!");
}
Entity entity = (Entity) target;
List<ItemStack> drops = target.onSheared(stack, world, pos, EnchantmentHelper.getLevel(Enchantments.FORTUNE, stack));
Random rand = world.getRandom();
for (ItemStack drop : drops) {
ItemEntity item = entity.dropStack(drop, 1.0F);
if (item == null) {
continue;
}
float accelerationX = (rand.nextFloat() - rand.nextFloat()) * 0.1F;
float accelerationY = rand.nextFloat() * 0.05F;
float accelerationZ = (rand.nextFloat() - rand.nextFloat()) * 0.1F;
item.setVelocity(item.getVelocity().add(accelerationX, accelerationY, accelerationZ));
}
if (stack.damage(1, world.getRandom(), null)) {
stack.setCount(0);
}
}
@Override
public List<ItemStack> onSheared(ItemStack item, IWorld world, BlockPos pos, int fortune) {
List<ItemStack> drops = new ArrayList<>();
this.world.addParticle(ParticleTypes.EXPLOSION, this.x, this.y + (double) (this.getHeight() / 2.0F), this.z, 0.0D, 0.0D, 0.0D);
if (!this.world.isClient) {
this.remove();
CowEntity cow = EntityType.COW.create(this.world);
cow.refreshPositionAndAngles(this.x, this.y, this.z, this.yaw, this.pitch);
cow.setHealth(this.getHealth());
cow.field_6283 = this.field_6283;
if (this.hasCustomName()) {
cow.setCustomName(this.getCustomName());
}
this.world.spawnEntity(cow);
Block mushroom = this.getMooshroomType().getMushroomState().getBlock();
// TODO: Fixes forge bug where shearing brown mooshrooms always drop red mushrooms (Fixed in 1.15)
for (int i = 0; i < 5; ++i) {
drops.add(new ItemStack(mushroom));
}
this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F);
}
return drops;
}
public LivingSpawnEvent(MobEntity entity, IWorld world, double x, double y, double z) {
super(entity);
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
@Inject(at = @At("HEAD"), method = "getStateForNeighborUpdate")
public void onGetStateForNeighborUpdate(Direction direction_1, BlockState blockState_1, IWorld iWorld_1, BlockPos blockPos_1, BlockPos blockPos_2, CallbackInfoReturnable<BlockState> info) {
FluidState state = getFluidState();
if (!state.isEmpty()) {
iWorld_1.getFluidTickScheduler().schedule(blockPos_1, state.getFluid(), state.getFluid().getTickRate(iWorld_1));
}
}
public static boolean canEntitySpawnNaturally(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType, double sqDistanceFromPlayer) {
Result result = canEntitySpawn(entity, world, x, y, z, spawner, spawnType);
if (result == Result.DEFAULT) {
// Vanilla logic, but inverted since we're checking if it CAN spawn instead of if it CAN'T
return !(sqDistanceFromPlayer > 16384.0D && entity.canImmediatelyDespawn(sqDistanceFromPlayer)) && entity.canSpawn(world, SpawnType.NATURAL) && entity.canSpawn(world);
} else {
return result == Result.ALLOW;
}
}
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"))
private static EntityData hookSpecialSpawn(MobEntity entity, IWorld world, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData data, CompoundTag tag) {
if (!EntityEvents.doSpecialSpawn(entity, world, entity.x, entity.y, entity.z, null, spawnType)) {
return entity.initialize(world, localDifficulty, spawnType, data, tag);
} else {
return data;
}
}
private StructureStart forceStructureStart(IWorld worldIn, ChunkGenerator <? extends ChunkGeneratorConfig > generator, Random rand, long packedChunkPos)
{
ChunkPos chunkpos = new ChunkPos(packedChunkPos);
StructureStart structurestart;
Chunk ichunk = worldIn.getChunk(chunkpos.x, chunkpos.z, ChunkStatus.STRUCTURE_STARTS, false);
if (ichunk != null)
{
structurestart = ichunk.getStructureStart(this.getName());
if (structurestart != null && structurestart != StructureStart.DEFAULT)
{
return structurestart;
}
}
Biome biome_1 = generator.getBiomeSource().getBiomeForNoiseGen((chunkpos.getStartX() + 9) >> 2, 0, (chunkpos.getStartZ() + 9) >> 2 );
StructureStart structurestart1 = getStructureStartFactory().create((StructureFeature)(Object)this, chunkpos.x, chunkpos.z, BlockBox.empty(),0,generator.getSeed());
structurestart1.initialize(generator, ((ServerWorld)worldIn).getStructureManager() , chunkpos.x, chunkpos.z, biome_1);
structurestart = structurestart1.hasChildren() ? structurestart1 : StructureStart.DEFAULT;
if (structurestart.hasChildren())
{
worldIn.getChunk(chunkpos.x, chunkpos.z).setStructureStart(this.getName(), structurestart);
}
//long2objectmap.put(packedChunkPos, structurestart);
return structurestart;
}
public PotentialSpawns(IWorld world, EntityCategory type, BlockPos pos, List<SpawnEntry> oldList) {
super(world);
this.pos = pos;
this.type = type;
if (oldList != null) {
this.list = new ArrayList<SpawnEntry>(oldList);
} else {
this.list = new ArrayList<SpawnEntry>();
}
}
public static List<Biome.SpawnEntry> getPotentialSpawns(IWorld world, EntityCategory type, BlockPos pos, List<Biome.SpawnEntry> oldSpawns) {
WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, pos, oldSpawns);
if (MinecraftForge.EVENT_BUS.post(event)) {
return Collections.emptyList();
}
return event.getList();
}
@Override
public void onBroken(IWorld iWorld_1, BlockPos blockPos_1, BlockState blockState_1) {
block.onBlockBroken(
(org.sandboxpowered.sandbox.api.world.World) iWorld_1.getWorld(),
(Position) blockPos_1,
(org.sandboxpowered.sandbox.api.state.BlockState) blockState_1
);
}