Search in sources :

Example 1 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.

the class TorsionSpringTileEntity method tick.

public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
    TileEntity te = worldIn.getBlockEntity(pos);
    if (te != null && te instanceof KineticTileEntity) {
        externalChange = false;
        KineticTileEntity kte = (KineticTileEntity) te;
        RotationPropagator.handleAdded(worldIn, pos, kte);
    }
}
Also used : SplitShaftTileEntity(com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity)

Example 2 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.

the class TorsionSpringTileEntity method detachKinetics.

public void detachKinetics(World worldIn, BlockPos pos, boolean reAttachNextTick) {
    TileEntity te = worldIn.getBlockEntity(pos);
    if (te != null && te instanceof KineticTileEntity) {
        RotationPropagator.handleRemoved(worldIn, pos, (KineticTileEntity) te);
        if (reAttachNextTick) {
            externalChange = false;
            worldIn.getBlockTicks().scheduleTick(pos, getBlockState().getBlock(), 0, TickPriority.EXTREMELY_HIGH);
        }
    }
}
Also used : SplitShaftTileEntity(com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity)

Example 3 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.

the class RotationPropagatorMixin method propagateNewSource.

/**
 * @author Eriksonn
 * @reason Allows generator blocks to have different rotation speeds on different output sides
 */
@Overwrite(remap = false)
private static void propagateNewSource(KineticTileEntity currentTE) {
    BlockPos pos = currentTE.getBlockPos();
    World world = currentTE.getLevel();
    Iterator var3 = getConnectedNeighbours(currentTE).iterator();
    while (true) {
        KineticTileEntity neighbourTE;
        float speedOfCurrent;
        float speedOfNeighbour;
        float newSpeed;
        float oppositeSpeed;
        do {
            if (!var3.hasNext()) {
                return;
            }
            neighbourTE = (KineticTileEntity) var3.next();
            speedOfCurrent = currentTE.getTheoreticalSpeed();
            speedOfNeighbour = neighbourTE.getTheoreticalSpeed();
            newSpeed = getConveyedSpeed(currentTE, neighbourTE);
            oppositeSpeed = getConveyedSpeed(neighbourTE, currentTE);
        } while (newSpeed == 0.0F && oppositeSpeed == 0.0F);
        boolean incompatible = Math.signum(newSpeed) != Math.signum(speedOfNeighbour) && newSpeed != 0.0F && speedOfNeighbour != 0.0F;
        boolean tooFast = Math.abs(newSpeed) > (float) (Integer) AllConfigs.SERVER.kinetics.maxRotationSpeed.get();
        boolean speedChangedTooOften = currentTE.getFlickerScore() > 128;
        if (tooFast || speedChangedTooOften) {
            world.destroyBlock(pos, true);
            return;
        }
        if (incompatible) {
            world.destroyBlock(pos, true);
            return;
        }
        float prevSpeed;
        if (Math.abs(oppositeSpeed) > Math.abs(speedOfCurrent)) {
            prevSpeed = currentTE.getSpeed();
            currentTE.setSource(neighbourTE.getBlockPos());
            currentTE.setSpeed(getConveyedSpeed(neighbourTE, currentTE));
            currentTE.onSpeedChanged(prevSpeed);
            currentTE.sendData();
            propagateNewSource(currentTE);
            return;
        }
        if (Math.abs(newSpeed) >= Math.abs(speedOfNeighbour)) {
            if (currentTE.hasNetwork() && !currentTE.network.equals(neighbourTE.network)) {
                if (currentTE.hasSource() && currentTE.source.equals(neighbourTE.getBlockPos())) {
                    currentTE.removeSource();
                }
                prevSpeed = neighbourTE.getSpeed();
                neighbourTE.setSource(currentTE.getBlockPos());
                neighbourTE.setSpeed(getConveyedSpeed(currentTE, neighbourTE));
                neighbourTE.onSpeedChanged(prevSpeed);
                neighbourTE.sendData();
                propagateNewSource(neighbourTE);
            } else {
                prevSpeed = Math.abs(speedOfNeighbour) / 256.0F / 256.0F;
                if (Math.abs(newSpeed) > Math.abs(speedOfNeighbour) + prevSpeed) {
                    world.destroyBlock(pos, true);
                }
            }
        } else if (neighbourTE.getTheoreticalSpeed() != newSpeed) {
            prevSpeed = neighbourTE.getSpeed();
            neighbourTE.setSpeed(newSpeed);
            neighbourTE.setSource(currentTE.getBlockPos());
            neighbourTE.onSpeedChanged(prevSpeed);
            neighbourTE.sendData();
            propagateNewSource(neighbourTE);
        }
    }
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.

the class RotationPropagatorMixin method getConnectedNeighbours.

private static List<KineticTileEntity> getConnectedNeighbours(KineticTileEntity te) {
    List<KineticTileEntity> neighbours = new LinkedList();
    Iterator var2 = getPotentialNeighbourLocations(te).iterator();
    while (var2.hasNext()) {
        BlockPos neighbourPos = (BlockPos) var2.next();
        KineticTileEntity neighbourTE = findConnectedNeighbour(te, neighbourPos);
        if (neighbourTE != null) {
            neighbours.add(neighbourTE);
        }
    }
    return neighbours;
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos) LinkedList(java.util.LinkedList)

Example 5 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity 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)

Aggregations

KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)23 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 BlockPos (net.minecraft.core.BlockPos)8 BlockState (net.minecraft.world.level.block.state.BlockState)7 Level (net.minecraft.world.level.Level)5 IRotate (com.simibubi.create.content.contraptions.base.IRotate)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SplitShaftTileEntity (com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity)3 Iterator (java.util.Iterator)3 Axis (net.minecraft.core.Direction.Axis)3 LinkedList (java.util.LinkedList)2 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)2 Direction (net.minecraft.core.Direction)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3 (net.minecraft.world.phys.Vec3)2 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllInteractionBehaviours (com.simibubi.create.AllInteractionBehaviours)1 AllMovementBehaviours (com.simibubi.create.AllMovementBehaviours)1 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)1