use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Tropicraft by Tropicraft.
the class SmoothingGravityProcessor method process.
@Override
public StructureBlockInfo process(LevelReader level, BlockPos seedPos, BlockPos pos2, StructureBlockInfo originalBlockInfo, StructureBlockInfo blockInfo, StructurePlaceSettings placementSettingsIn, StructureTemplate template) {
Axis pathDir = getPathDirection(level, seedPos, blockInfo, placementSettingsIn, template);
if (pathDir == null) {
// Better than nothing
pathDir = Axis.X;
}
BlockPos pos = blockInfo.pos;
BlockPos posForward = pos.relative(Direction.get(AxisDirection.POSITIVE, pathDir));
BlockPos posBackward = pos.relative(Direction.get(AxisDirection.NEGATIVE, pathDir));
int heightForward = level.getHeight(heightmap, posForward.getX(), posForward.getZ()) + offset;
int heightBackward = level.getHeight(heightmap, posBackward.getX(), posBackward.getZ()) + offset;
int height = level.getHeight(heightmap, pos.getX(), pos.getZ()) + offset;
if (heightForward > height && heightBackward > height) {
return new StructureBlockInfo(new BlockPos(pos.getX(), Math.min(heightForward, heightBackward), pos.getZ()), blockInfo.state, blockInfo.nbt);
}
return baseline.process(level, seedPos, pos2, originalBlockInfo, blockInfo, placementSettingsIn, template);
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class PistonContraption method collectExtensions.
private boolean collectExtensions(Level world, BlockPos pos, Direction direction) throws AssemblyException {
List<StructureBlockInfo> poles = new ArrayList<>();
BlockPos actualStart = pos;
BlockState nextBlock = world.getBlockState(actualStart.relative(direction));
int extensionsInFront = 0;
BlockState blockState = world.getBlockState(pos);
boolean sticky = isStickyPiston(blockState);
if (!isPiston(blockState))
return false;
if (blockState.getValue(MechanicalPistonBlock.STATE) == PistonState.EXTENDED) {
while (PistonExtensionPoleBlock.PlacementHelper.get().matchesAxis(nextBlock, direction.getAxis()) || isPistonHead(nextBlock) && nextBlock.getValue(FACING) == direction) {
actualStart = actualStart.relative(direction);
poles.add(new StructureBlockInfo(actualStart, nextBlock.setValue(FACING, direction), null));
extensionsInFront++;
if (isPistonHead(nextBlock))
break;
nextBlock = world.getBlockState(actualStart.relative(direction));
if (extensionsInFront > MechanicalPistonBlock.maxAllowedPistonPoles())
throw AssemblyException.tooManyPistonPoles();
}
}
if (extensionsInFront == 0)
poles.add(new StructureBlockInfo(pos, MECHANICAL_PISTON_HEAD.getDefaultState().setValue(FACING, direction).setValue(BlockStateProperties.PISTON_TYPE, sticky ? PistonType.STICKY : PistonType.DEFAULT), null));
else
poles.add(new StructureBlockInfo(pos, PISTON_EXTENSION_POLE.getDefaultState().setValue(FACING, direction), null));
BlockPos end = pos;
nextBlock = world.getBlockState(end.relative(direction.getOpposite()));
int extensionsInBack = 0;
while (PistonExtensionPoleBlock.PlacementHelper.get().matchesAxis(nextBlock, direction.getAxis())) {
end = end.relative(direction.getOpposite());
poles.add(new StructureBlockInfo(end, nextBlock.setValue(FACING, direction), null));
extensionsInBack++;
nextBlock = world.getBlockState(end.relative(direction.getOpposite()));
if (extensionsInFront + extensionsInBack > MechanicalPistonBlock.maxAllowedPistonPoles())
throw AssemblyException.tooManyPistonPoles();
}
anchor = pos.relative(direction, initialExtensionProgress + 1);
extensionLength = extensionsInBack + extensionsInFront;
initialExtensionProgress = extensionsInFront;
pistonExtensionCollisionBox = new AABB(BlockPos.ZERO.relative(direction, -1), BlockPos.ZERO.relative(direction, -extensionLength - 1)).expandTowards(1, 1, 1);
if (extensionLength == 0)
throw AssemblyException.noPistonPoles();
bounds = new AABB(0, 0, 0, 0, 0, 0);
for (StructureBlockInfo pole : poles) {
BlockPos relPos = pole.pos.relative(direction, -extensionsInFront);
BlockPos localPos = relPos.subtract(anchor);
getBlocks().put(localPos, new StructureBlockInfo(localPos, pole.state, null));
// pistonExtensionCollisionBox = pistonExtensionCollisionBox.union(new AABB(localPos));
}
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class DoorMovingInteraction method handle.
@Override
protected BlockState handle(Player player, Contraption contraption, BlockPos pos, BlockState currentState) {
SoundEvent sound = currentState.getValue(DoorBlock.OPEN) ? SoundEvents.WOODEN_DOOR_CLOSE : SoundEvents.WOODEN_DOOR_OPEN;
BlockPos otherPos = currentState.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER ? pos.above() : pos.below();
StructureBlockInfo info = contraption.getBlocks().get(otherPos);
if (info.state.hasProperty(DoorBlock.OPEN))
setContraptionBlockData(contraption.entity, otherPos, new StructureBlockInfo(info.pos, info.state.cycle(DoorBlock.OPEN), info.nbt));
float pitch = player.level.random.nextFloat() * 0.1F + 0.9F;
playSound(player, sound, pitch);
return currentState.cycle(DoorBlock.OPEN);
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class DeployerMovingInteraction method handlePlayerInteraction.
@Override
public boolean handlePlayerInteraction(Player player, InteractionHand activeHand, BlockPos localPos, AbstractContraptionEntity contraptionEntity) {
StructureBlockInfo info = contraptionEntity.getContraption().getBlocks().get(localPos);
if (info == null)
return false;
MovementContext ctx = null;
int index = -1;
for (MutablePair<StructureBlockInfo, MovementContext> pair : contraptionEntity.getContraption().getActors()) {
if (info.equals(pair.left)) {
ctx = pair.right;
index = contraptionEntity.getContraption().getActors().indexOf(pair);
break;
}
}
if (ctx == null)
return false;
ItemStack heldStack = player.getItemInHand(activeHand);
if (heldStack.getItem().equals(AllItems.WRENCH.get())) {
DeployerTileEntity.Mode mode = NBTHelper.readEnum(ctx.tileData, "Mode", DeployerTileEntity.Mode.class);
NBTHelper.writeEnum(ctx.tileData, "Mode", mode == DeployerTileEntity.Mode.PUNCH ? DeployerTileEntity.Mode.USE : DeployerTileEntity.Mode.PUNCH);
} else {
if (ctx.world.isClientSide)
// we'll try again on the server side
return true;
DeployerFakePlayer fake = null;
if (!(ctx.temporaryData instanceof DeployerFakePlayer) && ctx.world instanceof ServerLevel) {
DeployerFakePlayer deployerFakePlayer = new DeployerFakePlayer((ServerLevel) ctx.world);
deployerFakePlayer.getInventory().load(ctx.tileData.getList("Inventory", Tag.TAG_COMPOUND));
ctx.temporaryData = fake = deployerFakePlayer;
ctx.tileData.remove("Inventory");
} else
fake = (DeployerFakePlayer) ctx.temporaryData;
if (fake == null)
return false;
ItemStack deployerItem = fake.getMainHandItem();
player.setItemInHand(activeHand, deployerItem.copy());
fake.setItemInHand(InteractionHand.MAIN_HAND, heldStack.copy());
ctx.tileData.put("HeldItem", heldStack.serializeNBT());
ctx.data.put("HeldItem", heldStack.serializeNBT());
}
if (index >= 0)
setContraptionActorData(contraptionEntity, index, info, ctx);
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class Contraption method readNBT.
public void readNBT(Level world, CompoundTag nbt, boolean spawnData) {
blocks.clear();
presentTileEntities.clear();
specialRenderedTileEntities.clear();
Tag blocks = nbt.get("Blocks");
// used to differentiate between the 'old' and the paletted serialization
boolean usePalettedDeserialization = blocks != null && blocks.getId() == 10 && ((CompoundTag) blocks).contains("Palette");
readBlocksCompound(blocks, world, usePalettedDeserialization);
actors.clear();
nbt.getList("Actors", 10).forEach(c -> {
CompoundTag comp = (CompoundTag) c;
StructureBlockInfo info = this.blocks.get(NbtUtils.readBlockPos(comp.getCompound("Pos")));
MovementContext context = MovementContext.readNBT(world, info, comp, this);
getActors().add(MutablePair.of(info, context));
});
superglue.clear();
NBTHelper.iterateCompoundList(nbt.getList("Superglue", Tag.TAG_COMPOUND), c -> superglue.add(Pair.of(NbtUtils.readBlockPos(c.getCompound("Pos")), Direction.from3DDataValue(c.getByte("Direction")))));
seats.clear();
NBTHelper.iterateCompoundList(nbt.getList("Seats", Tag.TAG_COMPOUND), c -> seats.add(NbtUtils.readBlockPos(c)));
seatMapping.clear();
NBTHelper.iterateCompoundList(nbt.getList("Passengers", Tag.TAG_COMPOUND), c -> seatMapping.put(NbtUtils.loadUUID(NBTHelper.getINBT(c, "Id")), c.getInt("Seat")));
stabilizedSubContraptions.clear();
NBTHelper.iterateCompoundList(nbt.getList("SubContraptions", Tag.TAG_COMPOUND), c -> stabilizedSubContraptions.put(c.getUUID("Id"), BlockFace.fromNBT(c.getCompound("Location"))));
storage.clear();
NBTHelper.iterateCompoundList(nbt.getList("Storage", Tag.TAG_COMPOUND), c -> storage.put(NbtUtils.readBlockPos(c.getCompound("Pos")), MountedStorage.deserialize(c.getCompound("Data"))));
fluidStorage.clear();
NBTHelper.iterateCompoundList(nbt.getList("FluidStorage", Tag.TAG_COMPOUND), c -> fluidStorage.put(NbtUtils.readBlockPos(c.getCompound("Pos")), MountedFluidStorage.deserialize(c.getCompound("Data"))));
interactors.clear();
NBTHelper.iterateCompoundList(nbt.getList("Interactors", Tag.TAG_COMPOUND), c -> {
BlockPos pos = NbtUtils.readBlockPos(c.getCompound("Pos"));
MovingInteractionBehaviour behaviour = AllInteractionBehaviours.of(getBlocks().get(pos).state.getBlock());
if (behaviour != null)
interactors.put(pos, behaviour);
});
if (spawnData)
fluidStorage.forEach((pos, mfs) -> {
BlockEntity tileEntity = presentTileEntities.get(pos);
if (!(tileEntity instanceof FluidTankTileEntity))
return;
FluidTankTileEntity tank = (FluidTankTileEntity) tileEntity;
IFluidTank tankInventory = tank.getTankInventory();
if (tankInventory instanceof FluidTank)
((FluidTank) tankInventory).setFluid(mfs.tank.getFluid());
tank.getFluidLevel().start(tank.getFillState());
mfs.assignTileEntity(tank);
});
IItemHandlerModifiable[] handlers = new IItemHandlerModifiable[storage.size()];
int index = 0;
for (MountedStorage mountedStorage : storage.values()) handlers[index++] = mountedStorage.getItemHandler();
IFluidHandler[] fluidHandlers = new IFluidHandler[fluidStorage.size()];
index = 0;
for (MountedFluidStorage mountedStorage : fluidStorage.values()) fluidHandlers[index++] = mountedStorage.getFluidHandler();
inventory = new ContraptionInvWrapper(handlers);
fluidInventory = new CombinedTankWrapper(fluidHandlers);
if (nbt.contains("BoundsFront"))
bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5));
stalled = nbt.getBoolean("Stalled");
hasUniversalCreativeCrate = nbt.getBoolean("BottomlessSupply");
anchor = NbtUtils.readBlockPos(nbt.getCompound("Anchor"));
}
Aggregations