use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class TropicraftSpawnEgg method useOn.
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
if (world.isClientSide) {
return InteractionResult.SUCCESS;
} else {
ItemStack itemStack = context.getItemInHand();
BlockPos pos = context.getClickedPos();
Direction dir = context.getClickedFace();
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == Blocks.SPAWNER) {
BlockEntity te = world.getBlockEntity(pos);
if (te instanceof SpawnerBlockEntity) {
BaseSpawner spawner = ((SpawnerBlockEntity) te).getSpawner();
EntityType<?> spawnType = typeIn.get();
spawner.setEntityId(spawnType);
te.setChanged();
world.sendBlockUpdated(pos, state, state, 3);
itemStack.shrink(1);
return InteractionResult.SUCCESS;
}
}
BlockPos spawnPos;
if (state.getCollisionShape(world, pos).isEmpty()) {
spawnPos = pos;
} else {
spawnPos = pos.relative(dir);
}
EntityType<?> type3 = typeIn.get();
if (type3.spawn((ServerLevel) world, itemStack, context.getPlayer(), spawnPos, MobSpawnType.SPAWN_EGG, true, !Objects.equals(pos, spawnPos) && dir == Direction.UP) != null) {
itemStack.shrink(1);
}
return InteractionResult.SUCCESS;
}
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class BuildingMethods method getBedState.
public static Tuple<BlockState, BlockState> getBedState(BlockPos bedHeadPos, BlockPos bedFootPos, DyeColor bedColor) {
BlockState bedHead = null;
BlockState bedFoot = null;
switch(bedColor) {
case BLACK:
{
bedHead = Blocks.BLACK_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.BLACK_BED.defaultBlockState();
break;
}
case BLUE:
{
bedHead = Blocks.BLUE_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.BLUE_BED.defaultBlockState();
break;
}
case BROWN:
{
bedHead = Blocks.BROWN_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.BROWN_BED.defaultBlockState();
break;
}
case CYAN:
{
bedHead = Blocks.CYAN_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.CYAN_BED.defaultBlockState();
break;
}
case GRAY:
{
bedHead = Blocks.GRAY_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.GRAY_BED.defaultBlockState();
break;
}
case GREEN:
{
bedHead = Blocks.GREEN_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.GREEN_BED.defaultBlockState();
break;
}
case LIGHT_BLUE:
{
bedHead = Blocks.LIGHT_BLUE_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.LIGHT_BLUE_BED.defaultBlockState();
break;
}
case LIGHT_GRAY:
{
bedHead = Blocks.LIGHT_GRAY_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.LIGHT_GRAY_BED.defaultBlockState();
break;
}
case LIME:
{
bedHead = Blocks.LIME_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.LIME_BED.defaultBlockState();
break;
}
case MAGENTA:
{
bedHead = Blocks.MAGENTA_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.MAGENTA_BED.defaultBlockState();
break;
}
case ORANGE:
{
bedHead = Blocks.ORANGE_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.ORANGE_BED.defaultBlockState();
break;
}
case PINK:
{
bedHead = Blocks.PINK_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.PINK_BED.defaultBlockState();
break;
}
case PURPLE:
{
bedHead = Blocks.PURPLE_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.PURPLE_BED.defaultBlockState();
break;
}
case RED:
{
bedHead = Blocks.RED_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.RED_BED.defaultBlockState();
break;
}
case WHITE:
{
bedHead = Blocks.WHITE_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.WHITE_BED.defaultBlockState();
break;
}
case YELLOW:
{
bedHead = Blocks.YELLOW_BED.defaultBlockState().setValue(BedBlock.PART, BedPart.HEAD);
bedFoot = Blocks.YELLOW_BED.defaultBlockState();
break;
}
}
Direction direction = Direction.NORTH;
BlockPos tempPos = bedHeadPos.relative(Direction.NORTH);
while (tempPos.getX() != bedFootPos.getX() || tempPos.getZ() != bedFootPos.getZ()) {
direction = direction.getClockWise();
tempPos = bedHeadPos.relative(direction);
}
bedHead = bedHead.setValue(BedBlock.FACING, direction.getOpposite());
bedFoot = bedFoot.setValue(BedBlock.FACING, direction.getOpposite());
return new Tuple<>(bedHead, bedFoot);
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class BuildingMethods method PlaceMineShaft.
/**
* Places a mineshaft with ladder in the world.
*
* @param world - The world where the mineshaft will be added.
* @param pos - The starting position for the mineshaft.
* @param facing - The direction where the ladder will be placed.
* @param onlyGatherOres - Determines if vanilla non-ore blocks will be gathered.
*/
public static void PlaceMineShaft(ServerLevel world, BlockPos pos, Direction facing, boolean onlyGatherOres) {
// Keep track of all the items to add to the chest at the end of the
// shaft.
ArrayList<ItemStack> stacks = new ArrayList<>();
ArrayList<Item> blocksToNotAdd = new ArrayList<>();
if (onlyGatherOres) {
blocksToNotAdd.add(Item.byBlock(Blocks.SAND));
blocksToNotAdd.add(Item.byBlock(Blocks.SANDSTONE));
blocksToNotAdd.add(Item.byBlock(Blocks.COBBLESTONE));
blocksToNotAdd.add(Item.byBlock(Blocks.STONE));
blocksToNotAdd.add(Item.byBlock(Blocks.DIRT));
blocksToNotAdd.add(Item.byBlock(Blocks.GRANITE));
blocksToNotAdd.add(Item.byBlock(Blocks.ANDESITE));
blocksToNotAdd.add(Item.byBlock(Blocks.DIORITE));
blocksToNotAdd.add(Item.byBlock(Blocks.RED_SAND));
blocksToNotAdd.add(Item.byBlock(Blocks.RED_SANDSTONE));
blocksToNotAdd.add(Item.byBlock(Blocks.MOSSY_COBBLESTONE));
blocksToNotAdd.add(Item.byBlock(Blocks.MOSSY_STONE_BRICKS));
}
int minimumHeightForMineshaft = world.getMinBuildHeight() + 21;
Triple<ArrayList<ItemStack>, ArrayList<BlockPos>, ArrayList<BlockPos>> ladderShaftResults = BuildingMethods.CreateLadderShaft(world, pos, stacks, facing, blocksToNotAdd, minimumHeightForMineshaft);
ArrayList<BlockPos> blockPositions = new ArrayList<>(ladderShaftResults.getThird());
stacks = ladderShaftResults.getFirst();
ArrayList<BlockPos> torchPositions = ladderShaftResults.getSecond();
// Get 20 blocks above the void.
pos = pos.below(pos.getY() - minimumHeightForMineshaft);
ArrayList<ItemStack> tempStacks = new ArrayList<>();
BlockPos ceilingLevel = pos.above(4);
BuildingMethods.SetFloor(world, ceilingLevel.relative(facing, 2).relative(facing.getClockWise(), 2).relative(facing.getOpposite()), Blocks.STONE, 4, 4, tempStacks, facing.getOpposite(), blocksToNotAdd);
// After setting the floor, make sure to replace the ladder.
BuildingMethods.ReplaceBlock(world, ceilingLevel, Blocks.LADDER.defaultBlockState().setValue(LadderBlock.FACING, facing), 2);
blockPositions.add(ceilingLevel);
BlockState torchState = Blocks.TORCH.defaultBlockState();
// Place the torches at this point since the entire shaft has been set.
for (BlockPos torchPos : torchPositions) {
BlockState surroundingState = world.getBlockState(torchPos);
Block surroundingBlock = surroundingState.getBlock();
BuildingMethods.ConsolidateDrops(world, torchPos, surroundingState, tempStacks, blocksToNotAdd);
BuildingMethods.ReplaceBlock(world, torchPos, torchState, 2);
blockPositions.add(torchPos);
}
// The entire ladder has been created. Create a platform at this level
// and place a chest next to the ladder.
tempStacks.addAll(BuildingMethods.SetFloor(world, pos.relative(facing).relative(facing.getClockWise()), Blocks.STONE, 3, 4, tempStacks, facing.getOpposite(), blocksToNotAdd));
// Remove the ladder stack since they shouldn't be getting that.
for (int i = 0; i < tempStacks.size(); i++) {
ItemStack stack = tempStacks.get(i);
if (stack.getItem() == Item.byBlock(Blocks.LADDER)) {
tempStacks.remove(i);
i--;
}
}
// Now that the floor has been set, go up 1 block to star creating the
// walls.
pos = pos.above();
// Clear a space around the ladder pillar and make walls. The walls are
// necessary if there is a lot of lava down here.
// Make a wall of air then a wall of stone.
// South wall.
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 3, facing.getClockWise(), pos.relative(facing.getOpposite(), 2).relative(facing.getCounterClockWise()), Blocks.AIR, blocksToNotAdd));
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 3, facing.getClockWise(), pos.relative(facing.getOpposite(), 3).relative(facing.getCounterClockWise()), Blocks.STONE, blocksToNotAdd));
// East wall.
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 4, facing, pos.relative(facing.getOpposite(), 2).relative(facing.getClockWise()), Blocks.AIR, blocksToNotAdd));
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 4, facing, pos.relative(facing.getOpposite(), 2).relative(facing.getClockWise(), 2), Blocks.STONE, blocksToNotAdd));
// North wall.
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 3, facing.getCounterClockWise(), pos.relative(facing).relative(facing.getClockWise()), Blocks.AIR, blocksToNotAdd));
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 3, facing.getCounterClockWise(), pos.relative(facing, 2).relative(facing.getClockWise()), Blocks.STONE, blocksToNotAdd));
// West wall.
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 4, facing.getOpposite(), pos.relative(facing).relative(facing.getCounterClockWise()), Blocks.AIR, blocksToNotAdd));
tempStacks.addAll(BuildingMethods.CreateWall(world, 3, 4, facing.getOpposite(), pos.relative(facing, 1).relative(facing.getCounterClockWise(), 2), Blocks.STONE, blocksToNotAdd));
// Consolidate the stacks.
for (ItemStack tempStack : tempStacks) {
boolean foundStack = false;
for (ItemStack existingStack : stacks) {
if (ItemStack.isSame(existingStack, tempStack)) {
// the max.
if (existingStack.getCount() + tempStack.getCount() <= tempStack.getMaxStackSize()) {
existingStack.setCount(existingStack.getCount() + tempStack.getCount());
foundStack = true;
break;
}
}
}
if (!foundStack) {
stacks.add(tempStack);
}
}
// Place a torch to the left of the ladder.
BlockState blockState = Blocks.TORCH.defaultBlockState();
BuildingMethods.ReplaceBlock(world, pos.relative(facing.getCounterClockWise()), blockState);
if (CommonProxy.proxyConfiguration.serverConfiguration.includeMineshaftChest) {
// Place a chest to the right of the ladder.
BlockState chestState = Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, facing);
BuildingMethods.ReplaceBlock(world, pos.relative(facing.getClockWise()), chestState, 2);
blockPositions.add(pos.relative(facing.getClockWise()));
if (stacks.size() > 27) {
// Add another chest to south of the existing chest.
BuildingMethods.ReplaceBlock(world, pos.relative(facing.getClockWise()).relative(facing.getOpposite()), chestState, 2);
blockPositions.add(pos.relative(facing.getClockWise()).relative(facing.getOpposite()));
}
BlockEntity tileEntity = world.getBlockEntity(pos.relative(facing.getClockWise()));
BlockEntity tileEntity2 = world.getBlockEntity(pos.relative(facing.getClockWise()).relative(facing.getOpposite()));
if (tileEntity instanceof ChestBlockEntity) {
ChestBlockEntity chestTile = (ChestBlockEntity) tileEntity;
ChestBlockEntity chestTile2 = (ChestBlockEntity) tileEntity2;
int i = 0;
boolean fillSecond = false;
// All the stacks should be consolidated at this point.
for (ItemStack stack : stacks) {
if (i == 27 && !fillSecond) {
// Start filling the second chest.
fillSecond = true;
i = 0;
chestTile = chestTile2;
}
if (i >= 27 && fillSecond) {
// Too many items, discard the rest.
break;
} else {
chestTile.setItem(i, stack);
}
i++;
}
}
}
for (BlockPos currentPos : blockPositions) {
Block block = world.getBlockState(pos).getBlock();
world.blockUpdated(pos, block);
}
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class Structure method processedGlassBlock.
protected boolean processedGlassBlock(StructureConfiguration configuration, BuildBlock block, Level world, BlockPos originalPos, Block foundBlock) {
if (!this.hasGlassColor(configuration)) {
return false;
}
if (foundBlock.getRegistryName().getNamespace().equals(Blocks.WHITE_STAINED_GLASS.getRegistryName().getNamespace()) && foundBlock.getRegistryName().getPath().endsWith("glass")) {
BlockState blockState = BuildingMethods.getStainedGlassBlock(this.getGlassColor(configuration));
block.setBlockState(blockState);
return true;
} else if (foundBlock.getRegistryName().getNamespace().equals(Blocks.WHITE_STAINED_GLASS_PANE.getRegistryName().getNamespace()) && foundBlock.getRegistryName().getPath().endsWith("glass_pane")) {
BlockState blockState = BuildingMethods.getStainedGlassPaneBlock(this.getGlassColor(configuration));
BuildBlock.SetBlockState(configuration, originalPos, block, foundBlock, blockState, this.getClearSpace().getShape().getDirection());
return true;
}
return false;
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method removeWaterLogging.
private static void removeWaterLogging(Structure structure) {
if (structure.hasAirBlocks) {
for (BlockPos currentPos : structure.allBlockPositions) {
BlockState currentState = structure.world.getBlockState(currentPos);
if (currentState.hasProperty(BlockStateProperties.WATERLOGGED)) {
// This is a water loggable block and there were air blocks, make sure that it's no longer water logged.
currentState = currentState.setValue((BlockStateProperties.WATERLOGGED), false);
structure.world.setBlock(currentPos, currentState, 3);
} else if (currentState.getMaterial() == Material.WATER) {
structure.world.setBlock(currentPos, Blocks.AIR.defaultBlockState(), 3);
}
}
}
}
Aggregations