Search in sources :

Example 1 with SmartTileEntity

use of com.simibubi.create.foundation.tileEntity.SmartTileEntity in project Create_Aeronautics by Eriksonnaren.

the class AirshipContraptionEntity method handle.

public void handle(AirshipContraptionBlockUpdateInfo info) {
    fakeClientWorld.setBlock(info.pos, info.state, 1);
    if (info.tileEntityNBT != null) {
        TileEntity existingBE = fakeClientWorld.getBlockEntity(info.pos);
        if (existingBE != null) {
            // existingBE.setLevelAndPosition(fakeClientWorld, info.pos);
            // if(existingBE instanceof SmartTileEntity) {
            // ((SmartTileEntity) existingBE).readClientUpdate(info.state, info.tileEntityNBT);
            // } else {
            // existingBE.getUpdatePacket().handleUpdateTag(info.state, info.tileEntityNBT);
            // }
            // fakeClientWorld.setBlockEntity(info.pos, existingBE);
            addTileData(existingBE, info.pos.offset(0, -getPlotPos().getY(), 0), info.state);
        } else {
            TileEntityType<?> type = ForgeRegistries.TILE_ENTITIES.getValue(new ResourceLocation(info.tileEntityNBT.getString("id")));
            if (type == null)
                return;
            TileEntity te = type.create();
            if (te == null)
                return;
            te.setLevelAndPosition(fakeClientWorld, info.pos);
            te.handleUpdateTag(info.state, info.tileEntityNBT);
            te.load(info.state, info.tileEntityNBT);
            fakeClientWorld.setBlockEntity(info.pos, te);
            addTileData(te, info.pos.offset(0, -getPlotPos().getY(), 0), info.state);
        }
    }
}
Also used : AirshipAssemblerTileEntity(com.eriksonn.createaeronautics.blocks.airship_assembler.AirshipAssemblerTileEntity) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with SmartTileEntity

use of com.simibubi.create.foundation.tileEntity.SmartTileEntity in project Create by Creators-of-Create.

the class PonderWorld method onTEadded.

@Override
protected void onTEadded(BlockEntity tileEntity, BlockPos pos) {
    super.onTEadded(tileEntity, pos);
    if (!(tileEntity instanceof SmartTileEntity))
        return;
    SmartTileEntity smartTileEntity = (SmartTileEntity) tileEntity;
    smartTileEntity.markVirtual();
}
Also used : SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity)

Example 3 with SmartTileEntity

use of com.simibubi.create.foundation.tileEntity.SmartTileEntity in project Create by Creators-of-Create.

the class ScrollValueHandler method onScroll.

@OnlyIn(Dist.CLIENT)
public static boolean onScroll(double delta) {
    Minecraft mc = Minecraft.getInstance();
    HitResult objectMouseOver = mc.hitResult;
    if (!(objectMouseOver instanceof BlockHitResult))
        return false;
    BlockHitResult result = (BlockHitResult) objectMouseOver;
    ClientLevel world = mc.level;
    BlockPos blockPos = result.getBlockPos();
    ScrollValueBehaviour scrolling = TileEntityBehaviour.get(world, blockPos, ScrollValueBehaviour.TYPE);
    if (scrolling == null)
        return false;
    if (!scrolling.isActive())
        return false;
    if (!mc.player.mayBuild())
        return false;
    if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getMainHandItem()))
        return false;
    passiveScrollDirection = (float) -delta;
    wrenchCog.bump(3, -delta * 10);
    int prev = scrolling.scrollableValue;
    if (scrolling.slotPositioning instanceof Sided)
        ((Sided) scrolling.slotPositioning).fromSide(result.getDirection());
    if (!scrolling.testHit(objectMouseOver.getLocation()))
        return false;
    if (scrolling instanceof BulkScrollValueBehaviour && AllKeys.ctrlDown()) {
        BulkScrollValueBehaviour bulkScrolling = (BulkScrollValueBehaviour) scrolling;
        for (SmartTileEntity te : bulkScrolling.getBulk()) {
            ScrollValueBehaviour other = te.getBehaviour(ScrollValueBehaviour.TYPE);
            if (other != null)
                applyTo(delta, other);
        }
    } else
        applyTo(delta, scrolling);
    if (prev != scrolling.scrollableValue) {
        float pitch = (scrolling.scrollableValue - scrolling.min) / (float) (scrolling.max - scrolling.min);
        pitch = Mth.lerp(pitch, 1.5f, 2f);
        AllSoundEvents.SCROLL_VALUE.play(world, mc.player, blockPos, 1, pitch);
    }
    return true;
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) Minecraft(net.minecraft.client.Minecraft) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with SmartTileEntity

use of com.simibubi.create.foundation.tileEntity.SmartTileEntity in project Create by Creators-of-Create.

the class FilteringRenderer method renderOnTileEntity.

public static void renderOnTileEntity(SmartTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (te == null || te.isRemoved())
        return;
    Entity cameraEntity = Minecraft.getInstance().cameraEntity;
    float max = AllConfigs.CLIENT.filterItemRenderDistance.getF();
    if (!te.isVirtual() && cameraEntity != null && cameraEntity.position().distanceToSqr(VecHelper.getCenterOf(te.getBlockPos())) > (max * max))
        return;
    FilteringBehaviour behaviour = te.getBehaviour(FilteringBehaviour.TYPE);
    if (behaviour == null)
        return;
    if (!behaviour.isActive())
        return;
    if (behaviour.getFilter().isEmpty() && !(behaviour instanceof SidedFilteringBehaviour))
        return;
    ValueBoxTransform slotPositioning = behaviour.slotPositioning;
    BlockState blockState = te.getBlockState();
    if (slotPositioning instanceof ValueBoxTransform.Sided) {
        ValueBoxTransform.Sided sided = (ValueBoxTransform.Sided) slotPositioning;
        Direction side = sided.getSide();
        for (Direction d : Iterate.directions) {
            ItemStack filter = behaviour.getFilter(d);
            if (filter.isEmpty())
                continue;
            sided.fromSide(d);
            if (!slotPositioning.shouldRender(blockState))
                continue;
            ms.pushPose();
            slotPositioning.transform(blockState, ms);
            ValueBoxRenderer.renderItemIntoValueBox(filter, ms, buffer, light, overlay);
            ms.popPose();
        }
        sided.fromSide(side);
        return;
    } else if (slotPositioning.shouldRender(blockState)) {
        ms.pushPose();
        slotPositioning.transform(blockState, ms);
        ValueBoxRenderer.renderItemIntoValueBox(behaviour.getFilter(), ms, buffer, light, overlay);
        ms.popPose();
    }
}
Also used : SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) Entity(net.minecraft.world.entity.Entity) BlockState(net.minecraft.world.level.block.state.BlockState) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) ValueBoxTransform(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided)

Example 5 with SmartTileEntity

use of com.simibubi.create.foundation.tileEntity.SmartTileEntity in project Create by Creators-of-Create.

the class LinkRenderer method renderOnTileEntity.

public static void renderOnTileEntity(SmartTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (te == null || te.isRemoved())
        return;
    Entity cameraEntity = Minecraft.getInstance().cameraEntity;
    float max = AllConfigs.CLIENT.filterItemRenderDistance.getF();
    if (!te.isVirtual() && cameraEntity != null && cameraEntity.position().distanceToSqr(VecHelper.getCenterOf(te.getBlockPos())) > (max * max))
        return;
    LinkBehaviour behaviour = te.getBehaviour(LinkBehaviour.TYPE);
    if (behaviour == null)
        return;
    for (boolean first : Iterate.trueAndFalse) {
        ValueBoxTransform transform = first ? behaviour.firstSlot : behaviour.secondSlot;
        ItemStack stack = first ? behaviour.frequencyFirst.getStack() : behaviour.frequencyLast.getStack();
        ms.pushPose();
        transform.transform(te.getBlockState(), ms);
        ValueBoxRenderer.renderItemIntoValueBox(stack, ms, buffer, light, overlay);
        ms.popPose();
    }
}
Also used : SmartTileEntity(com.simibubi.create.foundation.tileEntity.SmartTileEntity) Entity(net.minecraft.world.entity.Entity) ValueBoxTransform(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

SmartTileEntity (com.simibubi.create.foundation.tileEntity.SmartTileEntity)6 ValueBoxTransform (com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform)2 Sided (com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided)2 Minecraft (net.minecraft.client.Minecraft)2 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)2 BlockPos (net.minecraft.core.BlockPos)2 Direction (net.minecraft.core.Direction)2 Entity (net.minecraft.world.entity.Entity)2 ItemStack (net.minecraft.world.item.ItemStack)2 BlockHitResult (net.minecraft.world.phys.BlockHitResult)2 HitResult (net.minecraft.world.phys.HitResult)2 AirshipAssemblerTileEntity (com.eriksonn.createaeronautics.blocks.airship_assembler.AirshipAssemblerTileEntity)1 ITickableTileEntity (net.minecraft.tileentity.ITickableTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1