Search in sources :

Example 1 with StructureBlockInfo

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;
}
Also used : BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)

Example 2 with StructureBlockInfo

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;
}
Also used : BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) Arrays(java.util.Arrays) AABB(net.minecraft.world.phys.AABB) SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) DebugPackets(net.minecraft.network.protocol.game.DebugPackets) Dist(net.minecraftforge.api.distmarker.Dist) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CombinedInvWrapper(net.minecraftforge.items.wrapper.CombinedInvWrapper) NbtUtils(net.minecraft.nbt.NbtUtils) ChestBlock(net.minecraft.world.level.block.ChestBlock) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) Set(java.util.Set) PoiType(net.minecraft.world.entity.ai.village.poi.PoiType) BooleanOp(net.minecraft.world.phys.shapes.BooleanOp) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) AllInteractionBehaviours(com.simibubi.create.AllInteractionBehaviours) WindmillBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock) MechanicalPistonHeadBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock) FluidState(net.minecraft.world.level.material.FluidState) PulleyBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) GantryShaftBlock(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock) ICoordinate(com.simibubi.create.foundation.utility.ICoordinate) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BlockState(net.minecraft.world.level.block.state.BlockState) CreativeCrateTileEntity(com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ArrayList(java.util.ArrayList) StickerBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock) BiConsumer(java.util.function.BiConsumer) BlockFace(com.simibubi.create.foundation.utility.BlockFace) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) Nullable(javax.annotation.Nullable) SeatEntity(com.simibubi.create.content.contraptions.components.actors.SeatEntity) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Iterate(com.simibubi.create.foundation.utility.Iterate) AllMovementBehaviours(com.simibubi.create.AllMovementBehaviours) MechanicalBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper) NBTHelper(com.simibubi.create.foundation.utility.NBTHelper) FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) ListTag(net.minecraft.nbt.ListTag) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) EmptyLighter(com.simibubi.create.content.contraptions.components.structureMovement.render.EmptyLighter) IMultiTileContainer(com.simibubi.create.foundation.tileEntity.IMultiTileContainer) Direction(net.minecraft.core.Direction) RedstoneContactBlock(com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock) PressurePlateBlock(net.minecraft.world.level.block.PressurePlateBlock) FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) GantryCarriageBlock(com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock) Rotation(net.minecraft.world.level.block.Rotation) MutablePair(org.apache.commons.lang3.tuple.MutablePair) GameData(net.minecraftforge.registries.GameData) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock) MechanicalPistonBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock) AllConfigs(com.simibubi.create.foundation.config.AllConfigs) PulleyTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity) UniqueLinkedList(com.simibubi.create.foundation.utility.UniqueLinkedList) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) NBTProcessors(com.simibubi.create.foundation.utility.NBTProcessors) UUID(java.util.UUID) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption) MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.world.level.block.Blocks) Objects(java.util.Objects) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) PistonExtensionPoleBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) HashMapPalette(net.minecraft.world.level.chunk.HashMapPalette) Entry(java.util.Map.Entry) Optional(java.util.Optional) LevelAccessor(net.minecraft.world.level.LevelAccessor) IFluidTank(net.minecraftforge.fluids.IFluidTank) Queue(java.util.Queue) Shapes(net.minecraft.world.phys.shapes.Shapes) Level(net.minecraft.world.level.Level) Tag(net.minecraft.nbt.Tag) PistonType(net.minecraft.world.level.block.state.properties.PistonType) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) FluidAction(net.minecraftforge.fluids.capability.IFluidHandler.FluidAction) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ServerLevel(net.minecraft.server.level.ServerLevel) HashSet(java.util.HashSet) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) Axis(net.minecraft.core.Direction.Axis) IRotate(com.simibubi.create.content.contraptions.base.IRotate) PushReaction(net.minecraft.world.level.material.PushReaction) ButtonBlock(net.minecraft.world.level.block.ButtonBlock) Fluids(net.minecraft.world.level.material.Fluids) AllBlocks(com.simibubi.create.AllBlocks) ChestType(net.minecraft.world.level.block.state.properties.ChestType) Iterator(java.util.Iterator) SuperGlueHandler(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueHandler) MechanicalPistonBlock.isPistonHead(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead) PistonState(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState) Entity(net.minecraft.world.entity.Entity) MechanicalPistonBlock.isExtensionPole(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole) ChassisTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisTileEntity) Vec3(net.minecraft.world.phys.Vec3) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) ListTag(net.minecraft.nbt.ListTag) Direction(net.minecraft.core.Direction) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 3 with StructureBlockInfo

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);
        }
    });
}
Also used : BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) Arrays(java.util.Arrays) AABB(net.minecraft.world.phys.AABB) SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) DebugPackets(net.minecraft.network.protocol.game.DebugPackets) Dist(net.minecraftforge.api.distmarker.Dist) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CombinedInvWrapper(net.minecraftforge.items.wrapper.CombinedInvWrapper) NbtUtils(net.minecraft.nbt.NbtUtils) ChestBlock(net.minecraft.world.level.block.ChestBlock) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) Set(java.util.Set) PoiType(net.minecraft.world.entity.ai.village.poi.PoiType) BooleanOp(net.minecraft.world.phys.shapes.BooleanOp) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) AllInteractionBehaviours(com.simibubi.create.AllInteractionBehaviours) WindmillBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock) MechanicalPistonHeadBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock) FluidState(net.minecraft.world.level.material.FluidState) PulleyBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) GantryShaftBlock(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock) ICoordinate(com.simibubi.create.foundation.utility.ICoordinate) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BlockState(net.minecraft.world.level.block.state.BlockState) CreativeCrateTileEntity(com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ArrayList(java.util.ArrayList) StickerBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock) BiConsumer(java.util.function.BiConsumer) BlockFace(com.simibubi.create.foundation.utility.BlockFace) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) Nullable(javax.annotation.Nullable) SeatEntity(com.simibubi.create.content.contraptions.components.actors.SeatEntity) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Iterate(com.simibubi.create.foundation.utility.Iterate) AllMovementBehaviours(com.simibubi.create.AllMovementBehaviours) MechanicalBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper) NBTHelper(com.simibubi.create.foundation.utility.NBTHelper) FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) ListTag(net.minecraft.nbt.ListTag) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) EmptyLighter(com.simibubi.create.content.contraptions.components.structureMovement.render.EmptyLighter) IMultiTileContainer(com.simibubi.create.foundation.tileEntity.IMultiTileContainer) Direction(net.minecraft.core.Direction) RedstoneContactBlock(com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock) PressurePlateBlock(net.minecraft.world.level.block.PressurePlateBlock) FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) GantryCarriageBlock(com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock) Rotation(net.minecraft.world.level.block.Rotation) MutablePair(org.apache.commons.lang3.tuple.MutablePair) GameData(net.minecraftforge.registries.GameData) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock) MechanicalPistonBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock) AllConfigs(com.simibubi.create.foundation.config.AllConfigs) PulleyTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity) UniqueLinkedList(com.simibubi.create.foundation.utility.UniqueLinkedList) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) NBTProcessors(com.simibubi.create.foundation.utility.NBTProcessors) UUID(java.util.UUID) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption) MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.world.level.block.Blocks) Objects(java.util.Objects) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) PistonExtensionPoleBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) HashMapPalette(net.minecraft.world.level.chunk.HashMapPalette) Entry(java.util.Map.Entry) Optional(java.util.Optional) LevelAccessor(net.minecraft.world.level.LevelAccessor) IFluidTank(net.minecraftforge.fluids.IFluidTank) Queue(java.util.Queue) Shapes(net.minecraft.world.phys.shapes.Shapes) Level(net.minecraft.world.level.Level) Tag(net.minecraft.nbt.Tag) PistonType(net.minecraft.world.level.block.state.properties.PistonType) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) FluidAction(net.minecraftforge.fluids.capability.IFluidHandler.FluidAction) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ServerLevel(net.minecraft.server.level.ServerLevel) HashSet(java.util.HashSet) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) Axis(net.minecraft.core.Direction.Axis) IRotate(com.simibubi.create.content.contraptions.base.IRotate) PushReaction(net.minecraft.world.level.material.PushReaction) ButtonBlock(net.minecraft.world.level.block.ButtonBlock) Fluids(net.minecraft.world.level.material.Fluids) AllBlocks(com.simibubi.create.AllBlocks) ChestType(net.minecraft.world.level.block.state.properties.ChestType) Iterator(java.util.Iterator) SuperGlueHandler(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueHandler) MechanicalPistonBlock.isPistonHead(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead) PistonState(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState) Entity(net.minecraft.world.entity.Entity) MechanicalPistonBlock.isExtensionPole(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole) ChassisTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisTileEntity) Vec3(net.minecraft.world.phys.Vec3) Block(net.minecraft.world.level.block.Block) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) ListTag(net.minecraft.nbt.ListTag) BlockState(net.minecraft.world.level.block.state.BlockState) BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) ChestBlock(net.minecraft.world.level.block.ChestBlock) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) WindmillBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock) MechanicalPistonHeadBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock) PulleyBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock) GantryShaftBlock(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock) StickerBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock) MechanicalBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock) RedstoneContactBlock(com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock) PressurePlateBlock(net.minecraft.world.level.block.PressurePlateBlock) GantryCarriageBlock(com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock) MechanicalPistonBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock) MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) PistonExtensionPoleBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock) ButtonBlock(net.minecraft.world.level.block.ButtonBlock) Block(net.minecraft.world.level.block.Block) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 4 with StructureBlockInfo

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;
}
Also used : BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)

Example 5 with StructureBlockInfo

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);
    }
}
Also used : ContraptionInteractionPacket(com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionInteractionPacket) LocalPlayer(net.minecraft.client.player.LocalPlayer) InteractionHand(net.minecraft.world.InteractionHand) Minecraft(net.minecraft.client.Minecraft) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) Vec3(net.minecraft.world.phys.Vec3) PredicateTraceResult(com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) AABB(net.minecraft.world.phys.AABB) MutableObject(org.apache.commons.lang3.mutable.MutableObject) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)23 BlockPos (net.minecraft.core.BlockPos)16 BlockState (net.minecraft.world.level.block.state.BlockState)13 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)9 AABB (net.minecraft.world.phys.AABB)8 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)7 Axis (net.minecraft.core.Direction.Axis)7 MagnetBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock)6 RopeBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock)6 Direction (net.minecraft.core.Direction)6 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)5 SeatEntity (com.simibubi.create.content.contraptions.components.actors.SeatEntity)5 MechanicalBearingBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock)5 WindmillBearingBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock)5 AbstractChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock)5 StickerBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock)5 GantryCarriageBlock (com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock)5 MechanicalPistonBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock)5 MechanicalPistonHeadBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock)5 PistonExtensionPoleBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock)5