Search in sources :

Example 1 with Sided

use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided in project Create by Creators-of-Create.

the class FilteringHandler method onScroll.

@OnlyIn(Dist.CLIENT)
public static boolean onScroll(double delta) {
    HitResult objectMouseOver = Minecraft.getInstance().hitResult;
    if (!(objectMouseOver instanceof BlockHitResult))
        return false;
    BlockHitResult result = (BlockHitResult) objectMouseOver;
    Minecraft mc = Minecraft.getInstance();
    ClientLevel world = mc.level;
    BlockPos blockPos = result.getBlockPos();
    FilteringBehaviour filtering = TileEntityBehaviour.get(world, blockPos, FilteringBehaviour.TYPE);
    if (filtering == null)
        return false;
    if (mc.player.isShiftKeyDown())
        return false;
    if (!mc.player.mayBuild())
        return false;
    if (!filtering.isCountVisible())
        return false;
    if (!filtering.isActive())
        return false;
    if (filtering.slotPositioning instanceof ValueBoxTransform.Sided)
        ((Sided) filtering.slotPositioning).fromSide(result.getDirection());
    if (!filtering.testHit(objectMouseOver.getLocation()))
        return false;
    ItemStack filterItem = filtering.getFilter();
    filtering.ticksUntilScrollPacket = 10;
    int maxAmount = (filterItem.getItem() instanceof FilterItem) ? 64 : filterItem.getMaxStackSize();
    int prev = filtering.scrollableValue;
    filtering.scrollableValue = (int) Mth.clamp(filtering.scrollableValue + delta * (AllKeys.ctrlDown() ? 16 : 1), 0, maxAmount);
    if (prev != filtering.scrollableValue) {
        float pitch = (filtering.scrollableValue) / (float) (maxAmount);
        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) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with Sided

use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided in project Create by Creators-of-Create.

the class FilteringRenderer method tick.

public static void tick() {
    Minecraft mc = Minecraft.getInstance();
    HitResult target = mc.hitResult;
    if (target == null || !(target instanceof BlockHitResult))
        return;
    BlockHitResult result = (BlockHitResult) target;
    ClientLevel world = mc.level;
    BlockPos pos = result.getBlockPos();
    BlockState state = world.getBlockState(pos);
    FilteringBehaviour behaviour = TileEntityBehaviour.get(world, pos, FilteringBehaviour.TYPE);
    if (mc.player.isShiftKeyDown())
        return;
    if (behaviour == null)
        return;
    if (behaviour instanceof SidedFilteringBehaviour) {
        behaviour = ((SidedFilteringBehaviour) behaviour).get(result.getDirection());
        if (behaviour == null)
            return;
    }
    if (!behaviour.isActive())
        return;
    if (behaviour.slotPositioning instanceof ValueBoxTransform.Sided)
        ((Sided) behaviour.slotPositioning).fromSide(result.getDirection());
    if (!behaviour.slotPositioning.shouldRender(state))
        return;
    ItemStack filter = behaviour.getFilter();
    boolean isFilterSlotted = filter.getItem() instanceof FilterItem;
    boolean showCount = behaviour.isCountVisible();
    boolean fluids = behaviour.fluidFilter;
    Component label = isFilterSlotted ? TextComponent.EMPTY : Lang.translate(behaviour.recipeFilter ? "logistics.recipe_filter" : fluids ? "logistics.fluid_filter" : "logistics.filter");
    boolean hit = behaviour.slotPositioning.testHit(state, target.getLocation().subtract(Vec3.atLowerCornerOf(pos)));
    AABB emptyBB = new AABB(Vec3.ZERO, Vec3.ZERO);
    AABB bb = isFilterSlotted ? emptyBB.inflate(.45f, .31f, .2f) : emptyBB.inflate(.25f);
    ValueBox box = showCount ? new ItemValueBox(label, bb, pos, filter, behaviour.scrollableValue) : new ValueBox(label, bb, pos);
    box.offsetLabel(behaviour.textShift).withColors(fluids ? 0x407088 : 0x7A6A2C, fluids ? 0x70adb5 : 0xB79D64).scrollTooltip(showCount && !isFilterSlotted ? new TextComponent("[").append(Lang.translate("action.scroll")).append("]") : TextComponent.EMPTY).passive(!hit);
    CreateClient.OUTLINER.showValueBox(Pair.of("filter", pos), box.transform(behaviour.slotPositioning)).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(result.getDirection());
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Minecraft(net.minecraft.client.Minecraft) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) BlockState(net.minecraft.world.level.block.state.BlockState) ValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox) ItemValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox.ItemValueBox) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) AABB(net.minecraft.world.phys.AABB) ItemValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox.ItemValueBox)

Example 3 with Sided

use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided in project Create by Creators-of-Create.

the class SidedFilteringBehaviour method testHit.

public boolean testHit(Direction direction, Vec3 hit) {
    ValueBoxTransform.Sided sidedPositioning = (Sided) slotPositioning;
    BlockState state = tileEntity.getBlockState();
    Vec3 localHit = hit.subtract(Vec3.atLowerCornerOf(tileEntity.getBlockPos()));
    return sidedPositioning.fromSide(direction).testHit(state, localHit);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) Vec3(net.minecraft.world.phys.Vec3) ValueBoxTransform(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided)

Example 4 with Sided

use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided 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 5 with Sided

use of com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided in project Create by Creators-of-Create.

the class FilteringHandler method onBlockActivated.

@SubscribeEvent
public static void onBlockActivated(PlayerInteractEvent.RightClickBlock event) {
    Level world = event.getWorld();
    BlockPos pos = event.getPos();
    Player player = event.getPlayer();
    InteractionHand hand = event.getHand();
    if (player.isShiftKeyDown() || player.isSpectator())
        return;
    FilteringBehaviour behaviour = TileEntityBehaviour.get(world, pos, FilteringBehaviour.TYPE);
    if (behaviour == null)
        return;
    BlockHitResult ray = RaycastHelper.rayTraceRange(world, player, 10);
    if (ray == null)
        return;
    if (behaviour instanceof SidedFilteringBehaviour) {
        behaviour = ((SidedFilteringBehaviour) behaviour).get(ray.getDirection());
        if (behaviour == null)
            return;
    }
    if (!behaviour.isActive())
        return;
    if (behaviour.slotPositioning instanceof ValueBoxTransform.Sided)
        ((Sided) behaviour.slotPositioning).fromSide(ray.getDirection());
    if (!behaviour.testHit(ray.getLocation()))
        return;
    ItemStack toApply = player.getItemInHand(hand).copy();
    if (AllItems.WRENCH.isIn(toApply))
        return;
    if (AllBlocks.MECHANICAL_ARM.isIn(toApply))
        return;
    if (event.getSide() != LogicalSide.CLIENT) {
        if (!player.isCreative()) {
            if (toApply.getItem() instanceof FilterItem)
                player.getItemInHand(hand).shrink(1);
            if (behaviour.getFilter().getItem() instanceof FilterItem)
                player.getInventory().placeItemBackInInventory(behaviour.getFilter());
        }
        if (toApply.getItem() instanceof FilterItem)
            toApply.setCount(1);
        behaviour.setFilter(toApply);
    } else {
        ItemStack filter = behaviour.getFilter();
        String feedback = "apply_click_again";
        if (toApply.getItem() instanceof FilterItem || !behaviour.isCountVisible())
            feedback = "apply";
        else if (ItemHandlerHelper.canItemStacksStack(toApply, filter))
            feedback = "apply_count";
        String translationKey = world.getBlockState(pos).getBlock().getDescriptionId();
        Component formattedText = new TranslatableComponent(translationKey);
        player.displayClientMessage(Lang.createTranslationTextComponent("logistics.filter." + feedback, formattedText).withStyle(ChatFormatting.WHITE), true);
    }
    event.setCanceled(true);
    event.setCancellationResult(InteractionResult.SUCCESS);
    world.playSound(null, pos, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, .25f, .1f);
}
Also used : Player(net.minecraft.world.entity.player.Player) InteractionHand(net.minecraft.world.InteractionHand) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

Sided (com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided)6 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)4 BlockPos (net.minecraft.core.BlockPos)4 ItemStack (net.minecraft.world.item.ItemStack)4 BlockHitResult (net.minecraft.world.phys.BlockHitResult)4 FilterItem (com.simibubi.create.content.logistics.item.filter.FilterItem)3 Minecraft (net.minecraft.client.Minecraft)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 HitResult (net.minecraft.world.phys.HitResult)3 SmartTileEntity (com.simibubi.create.foundation.tileEntity.SmartTileEntity)2 ValueBoxTransform (com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform)2 Component (net.minecraft.network.chat.Component)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2 ValueBox (com.simibubi.create.foundation.tileEntity.behaviour.ValueBox)1 ItemValueBox (com.simibubi.create.foundation.tileEntity.behaviour.ValueBox.ItemValueBox)1 Direction (net.minecraft.core.Direction)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 InteractionHand (net.minecraft.world.InteractionHand)1 Entity (net.minecraft.world.entity.Entity)1