use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Tropicraft by Tropicraft.
the class SinkInGroundProcessor method process.
@SuppressWarnings("deprecation")
@Override
public StructureBlockInfo process(LevelReader world, BlockPos worldPos, BlockPos sourcePos, StructureBlockInfo sourceInfo, StructureBlockInfo worldInfo, StructurePlaceSettings placement, @Nullable StructureTemplate template) {
worldPos = worldInfo.pos;
if (sourceInfo.pos.getY() == 0) {
if (!isAirOrWater(world, worldPos)) {
return null;
}
return worldInfo;
}
// Get height of the ground at this spot
BlockPos groundCheck = world.getHeightmapPos(Heightmap.Types.WORLD_SURFACE, worldPos);
// y == 2, we're above the path, remove fence blocks that are above sea level or next to some other block
if (sourceInfo.pos.getY() == 2 && sourceInfo.state.getBlock() == TropicraftBlocks.BAMBOO_FENCE.get()) {
if (groundCheck.getY() > 127 || !isAirOrWater(world, worldPos.below(2))) {
return null;
}
for (int i = 0; i < 4; i++) {
if (!world.isEmptyBlock(worldPos.relative(Direction.from2DDataValue(i)))) {
return null;
}
}
}
// If above sea level, sink into the ground by one block
if (groundCheck.getY() > 127) {
// Convert slabs to bundles when they are over land
if (!isAirOrWater(world, worldPos.below()) && sourceInfo.state.getBlock() == TropicraftBlocks.THATCH_SLAB.get()) {
worldInfo = new StructureBlockInfo(worldPos, TropicraftBlocks.THATCH_BUNDLE.get().defaultBlockState(), null);
}
// Only sink solid blocks, or blocks that are above air/water -- delete all others
if (Block.isShapeFullBlock(worldInfo.state.getShape(world, worldPos.below())) || isAirOrWater(world, worldPos.below())) {
return new StructureBlockInfo(worldPos.below(), worldInfo.state, worldInfo.nbt);
}
}
return worldInfo;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class Contraption method writeNBT.
public CompoundTag writeNBT(boolean spawnPacket) {
CompoundTag nbt = new CompoundTag();
nbt.putString("Type", getType().id);
CompoundTag blocksNBT = writeBlocksCompound();
ListTag actorsNBT = new ListTag();
for (MutablePair<StructureBlockInfo, MovementContext> actor : getActors()) {
CompoundTag compound = new CompoundTag();
compound.put("Pos", NbtUtils.writeBlockPos(actor.left.pos));
AllMovementBehaviours.of(actor.left.state).writeExtraData(actor.right);
actor.right.writeToNBT(compound);
actorsNBT.add(compound);
}
ListTag superglueNBT = new ListTag();
ListTag storageNBT = new ListTag();
if (!spawnPacket) {
for (Pair<BlockPos, Direction> glueEntry : superglue) {
CompoundTag c = new CompoundTag();
c.put("Pos", NbtUtils.writeBlockPos(glueEntry.getKey()));
c.putByte("Direction", (byte) glueEntry.getValue().get3DDataValue());
superglueNBT.add(c);
}
for (BlockPos pos : storage.keySet()) {
CompoundTag c = new CompoundTag();
MountedStorage mountedStorage = storage.get(pos);
if (!mountedStorage.isValid())
continue;
c.put("Pos", NbtUtils.writeBlockPos(pos));
c.put("Data", mountedStorage.serialize());
storageNBT.add(c);
}
}
ListTag fluidStorageNBT = new ListTag();
for (BlockPos pos : fluidStorage.keySet()) {
CompoundTag c = new CompoundTag();
MountedFluidStorage mountedStorage = fluidStorage.get(pos);
if (!mountedStorage.isValid())
continue;
c.put("Pos", NbtUtils.writeBlockPos(pos));
c.put("Data", mountedStorage.serialize());
fluidStorageNBT.add(c);
}
ListTag interactorNBT = new ListTag();
for (BlockPos pos : interactors.keySet()) {
CompoundTag c = new CompoundTag();
c.put("Pos", NbtUtils.writeBlockPos(pos));
interactorNBT.add(c);
}
nbt.put("Seats", NBTHelper.writeCompoundList(getSeats(), NbtUtils::writeBlockPos));
nbt.put("Passengers", NBTHelper.writeCompoundList(getSeatMapping().entrySet(), e -> {
CompoundTag tag = new CompoundTag();
tag.put("Id", NbtUtils.createUUID(e.getKey()));
tag.putInt("Seat", e.getValue());
return tag;
}));
nbt.put("SubContraptions", NBTHelper.writeCompoundList(stabilizedSubContraptions.entrySet(), e -> {
CompoundTag tag = new CompoundTag();
tag.putUUID("Id", e.getKey());
tag.put("Location", e.getValue().serializeNBT());
return tag;
}));
nbt.put("Blocks", blocksNBT);
nbt.put("Actors", actorsNBT);
nbt.put("Interactors", interactorNBT);
nbt.put("Superglue", superglueNBT);
nbt.put("Storage", storageNBT);
nbt.put("FluidStorage", fluidStorageNBT);
nbt.put("Anchor", NbtUtils.writeBlockPos(anchor));
nbt.putBoolean("Stalled", stalled);
nbt.putBoolean("BottomlessSupply", hasUniversalCreativeCrate);
if (bounds != null) {
ListTag bb = NBTHelper.writeAABB(bounds);
nbt.put("BoundsFront", bb);
}
return nbt;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class Contraption method readBlocksCompound.
private void readBlocksCompound(Tag compound, Level world, boolean usePalettedDeserialization) {
HashMapPalette<BlockState> palette = null;
ListTag blockList;
if (usePalettedDeserialization) {
CompoundTag c = ((CompoundTag) compound);
palette = new HashMapPalette<>(GameData.getBlockStateIDMap(), 16, (i, s) -> {
throw new IllegalStateException("Palette Map index exceeded maximum");
});
ListTag list = c.getList("Palette", 10);
palette.values.clear();
for (int i = 0; i < list.size(); ++i) palette.values.add(NbtUtils.readBlockState(list.getCompound(i)));
blockList = c.getList("BlockList", 10);
} else {
blockList = (ListTag) compound;
}
HashMapPalette<BlockState> finalPalette = palette;
blockList.forEach(e -> {
CompoundTag c = (CompoundTag) e;
StructureBlockInfo info = usePalettedDeserialization ? readStructureBlockInfo(c, finalPalette) : legacyReadStructureBlockInfo(c);
this.blocks.put(info.pos, info);
if (world.isClientSide) {
Block block = info.state.getBlock();
CompoundTag tag = info.nbt;
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block);
if (tag == null)
return;
tag.putInt("x", info.pos.getX());
tag.putInt("y", info.pos.getY());
tag.putInt("z", info.pos.getZ());
BlockEntity te = BlockEntity.loadStatic(info.pos, info.state, tag);
if (te == null)
return;
te.setLevel(world);
if (te instanceof KineticTileEntity)
((KineticTileEntity) te).setSpeed(0);
te.getBlockState();
if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering())
maybeInstancedTileEntities.add(te);
if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity())
return;
presentTileEntities.put(info.pos, te);
specialRenderedTileEntities.add(te);
}
});
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class TranslatingContraption method getColliders.
public Set<BlockPos> getColliders(Level world, Direction movementDirection) {
if (getBlocks() == null)
return Collections.emptySet();
if (cachedColliders == null || cachedColliderDirection != movementDirection) {
cachedColliders = new HashSet<>();
cachedColliderDirection = movementDirection;
for (StructureBlockInfo info : getBlocks().values()) {
BlockPos offsetPos = info.pos.relative(movementDirection);
if (info.state.getCollisionShape(world, offsetPos).isEmpty())
continue;
if (getBlocks().containsKey(offsetPos) && !getBlocks().get(offsetPos).state.getCollisionShape(world, offsetPos).isEmpty())
continue;
cachedColliders.add(info.pos);
}
}
return cachedColliders;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo in project Create by Creators-of-Create.
the class ContraptionHandlerClient method rightClickingOnContraptionsGetsHandledLocally.
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void rightClickingOnContraptionsGetsHandledLocally(ClickInputEvent event) {
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
if (player == null)
return;
if (player.isPassenger())
return;
if (mc.level == null)
return;
if (!event.isUseItem())
return;
Vec3 origin = RaycastHelper.getTraceOrigin(player);
double reach = mc.gameMode.getPickRange();
if (mc.hitResult != null && mc.hitResult.getLocation() != null)
reach = Math.min(mc.hitResult.getLocation().distanceTo(origin), reach);
Vec3 target = RaycastHelper.getTraceTarget(player, reach, origin);
for (AbstractContraptionEntity contraptionEntity : mc.level.getEntitiesOfClass(AbstractContraptionEntity.class, new AABB(origin, target))) {
Vec3 localOrigin = contraptionEntity.toLocalVector(origin, 1);
Vec3 localTarget = contraptionEntity.toLocalVector(target, 1);
Contraption contraption = contraptionEntity.getContraption();
MutableObject<BlockHitResult> mutableResult = new MutableObject<>();
PredicateTraceResult predicateResult = RaycastHelper.rayTraceUntil(localOrigin, localTarget, p -> {
StructureBlockInfo blockInfo = contraption.getBlocks().get(p);
if (blockInfo == null)
return false;
BlockState state = blockInfo.state;
VoxelShape raytraceShape = state.getShape(Minecraft.getInstance().level, BlockPos.ZERO.below());
if (raytraceShape.isEmpty())
return false;
BlockHitResult rayTrace = raytraceShape.clip(localOrigin, localTarget, p);
if (rayTrace != null) {
mutableResult.setValue(rayTrace);
return true;
}
return false;
});
if (predicateResult == null || predicateResult.missed())
return;
BlockHitResult rayTraceResult = mutableResult.getValue();
InteractionHand hand = event.getHand();
Direction face = rayTraceResult.getDirection();
BlockPos pos = rayTraceResult.getBlockPos();
if (!contraptionEntity.handlePlayerInteraction(player, pos, face, hand))
return;
AllPackets.channel.sendToServer(new ContraptionInteractionPacket(contraptionEntity, hand, pos, face));
event.setCanceled(true);
event.setSwingHand(false);
}
}
Aggregations