Search in sources :

Example 1 with BlueprintSection

use of com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection in project Create by Creators-of-Create.

the class BlueprintRenderer method render.

@Override
public void render(BlueprintEntity entity, float yaw, float pt, PoseStack ms, MultiBufferSource buffer, int light) {
    PartialModel partialModel = entity.size == 3 ? AllBlockPartials.CRAFTING_BLUEPRINT_3x3 : entity.size == 2 ? AllBlockPartials.CRAFTING_BLUEPRINT_2x2 : AllBlockPartials.CRAFTING_BLUEPRINT_1x1;
    SuperByteBuffer sbb = CachedBufferer.partial(partialModel, Blocks.AIR.defaultBlockState());
    sbb.rotateY(-yaw).rotateX(90.0F + entity.getXRot()).translate(-.5, -1 / 32f, -.5);
    if (entity.size == 2)
        sbb.translate(.5, 0, -.5);
    sbb.forEntityRender().light(light).renderInto(ms, buffer.getBuffer(Sheets.solidBlockSheet()));
    super.render(entity, yaw, pt, ms, buffer, light);
    ms.pushPose();
    float fakeNormalXRotation = -15;
    int bl = light >> 4 & 0xf;
    int sl = light >> 20 & 0xf;
    boolean vertical = entity.getXRot() != 0;
    if (entity.getXRot() == -90)
        fakeNormalXRotation = -45;
    else if (entity.getXRot() == 90 || yaw % 180 != 0) {
        bl /= 1.35;
        sl /= 1.35;
    }
    int itemLight = Mth.floor(sl + .5) << 20 | (Mth.floor(bl + .5) & 0xf) << 4;
    TransformStack.cast(ms).rotateY(vertical ? 0 : -yaw).rotateX(fakeNormalXRotation);
    Matrix3f copy = ms.last().normal().copy();
    ms.popPose();
    ms.pushPose();
    TransformStack.cast(ms).rotateY(-yaw).rotateX(entity.getXRot()).translate(0, 0, 1 / 32f + .001);
    if (entity.size == 3)
        ms.translate(-1, -1, 0);
    PoseStack squashedMS = new PoseStack();
    squashedMS.last().pose().multiply(ms.last().pose());
    for (int x = 0; x < entity.size; x++) {
        squashedMS.pushPose();
        for (int y = 0; y < entity.size; y++) {
            BlueprintSection section = entity.getSection(x * entity.size + y);
            Couple<ItemStack> displayItems = section.getDisplayItems();
            squashedMS.pushPose();
            squashedMS.scale(.5f, .5f, 1 / 1024f);
            displayItems.forEachWithContext((stack, primary) -> {
                if (stack.isEmpty())
                    return;
                squashedMS.pushPose();
                if (!primary) {
                    squashedMS.translate(0.325f, -0.325f, 1);
                    squashedMS.scale(.625f, .625f, 1);
                }
                squashedMS.last().normal().load(copy);
                Minecraft.getInstance().getItemRenderer().renderStatic(stack, TransformType.GUI, itemLight, OverlayTexture.NO_OVERLAY, squashedMS, buffer, 0);
                squashedMS.popPose();
            });
            squashedMS.popPose();
            squashedMS.translate(1, 0, 0);
        }
        squashedMS.popPose();
        squashedMS.translate(0, 1, 0);
    }
    ms.popPose();
}
Also used : BlueprintSection(com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Matrix3f(com.mojang.math.Matrix3f) ItemStack(net.minecraft.world.item.ItemStack) PartialModel(com.jozufozu.flywheel.core.PartialModel)

Example 2 with BlueprintSection

use of com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection in project Create by Creators-of-Create.

the class BlueprintContainer method createOnClient.

@Override
@OnlyIn(Dist.CLIENT)
protected BlueprintSection createOnClient(FriendlyByteBuf extraData) {
    int entityID = extraData.readVarInt();
    int section = extraData.readVarInt();
    Entity entityByID = Minecraft.getInstance().level.getEntity(entityID);
    if (!(entityByID instanceof BlueprintEntity))
        return null;
    BlueprintEntity blueprintEntity = (BlueprintEntity) entityByID;
    BlueprintSection blueprintSection = blueprintEntity.getSection(section);
    return blueprintSection;
}
Also used : BlueprintSection(com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection) Entity(net.minecraft.world.entity.Entity) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 3 with BlueprintSection

use of com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection in project Create by Creators-of-Create.

the class BlueprintOverlayRenderer method tick.

public static void tick() {
    Minecraft mc = Minecraft.getInstance();
    HitResult mouseOver = mc.hitResult;
    BlueprintSection last = lastTargetedSection;
    boolean sneak = mc.player.isShiftKeyDown();
    lastTargetedSection = null;
    active = false;
    if (mouseOver == null)
        return;
    if (mouseOver.getType() != Type.ENTITY)
        return;
    EntityHitResult entityRay = (EntityHitResult) mouseOver;
    if (!(entityRay.getEntity() instanceof BlueprintEntity))
        return;
    BlueprintEntity blueprintEntity = (BlueprintEntity) entityRay.getEntity();
    BlueprintSection sectionAt = blueprintEntity.getSectionAt(entityRay.getLocation().subtract(blueprintEntity.position()));
    lastTargetedSection = last;
    active = true;
    if (sectionAt != lastTargetedSection || AnimationTickHolder.getTicks() % 10 == 0 || lastSneakState != sneak)
        rebuild(sectionAt, sneak);
    lastTargetedSection = sectionAt;
    lastSneakState = sneak;
}
Also used : EntityHitResult(net.minecraft.world.phys.EntityHitResult) HitResult(net.minecraft.world.phys.HitResult) BlueprintSection(com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection) Minecraft(net.minecraft.client.Minecraft) EntityHitResult(net.minecraft.world.phys.EntityHitResult)

Example 4 with BlueprintSection

use of com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection in project Create by Creators-of-Create.

the class BlueprintOverlayRenderer method rebuild.

public static void rebuild(BlueprintSection sectionAt, boolean sneak) {
    cachedRenderedFilters.clear();
    ItemStackHandler items = sectionAt.getItems();
    boolean empty = true;
    for (int i = 0; i < 9; i++) {
        if (!items.getStackInSlot(i).isEmpty()) {
            empty = false;
            break;
        }
    }
    BlueprintOverlayRenderer.empty = empty;
    BlueprintOverlayRenderer.result = ItemStack.EMPTY;
    if (empty)
        return;
    boolean firstPass = true;
    boolean success = true;
    Minecraft mc = Minecraft.getInstance();
    ItemStackHandler playerInv = new ItemStackHandler(mc.player.getInventory().getContainerSize());
    for (int i = 0; i < playerInv.getSlots(); i++) playerInv.setStackInSlot(i, mc.player.getInventory().getItem(i).copy());
    int amountCrafted = 0;
    Optional<CraftingRecipe> recipe = Optional.empty();
    Map<Integer, ItemStack> craftingGrid = new HashMap<>();
    ingredients.clear();
    ItemStackHandler missingItems = new ItemStackHandler(64);
    ItemStackHandler availableItems = new ItemStackHandler(64);
    List<ItemStack> newlyAdded = new ArrayList<>();
    List<ItemStack> newlyMissing = new ArrayList<>();
    boolean invalid = false;
    do {
        craftingGrid.clear();
        newlyAdded.clear();
        newlyMissing.clear();
        Search: for (int i = 0; i < 9; i++) {
            ItemStack requestedItem = items.getStackInSlot(i);
            if (requestedItem.isEmpty()) {
                craftingGrid.put(i, ItemStack.EMPTY);
                continue;
            }
            for (int slot = 0; slot < playerInv.getSlots(); slot++) {
                if (!FilterItem.test(mc.level, playerInv.getStackInSlot(slot), requestedItem))
                    continue;
                ItemStack currentItem = playerInv.extractItem(slot, 1, false);
                craftingGrid.put(i, currentItem);
                newlyAdded.add(currentItem);
                continue Search;
            }
            success = false;
            newlyMissing.add(requestedItem);
        }
        if (success) {
            CraftingContainer craftingInventory = new BlueprintCraftingInventory(craftingGrid);
            if (!recipe.isPresent())
                recipe = mc.level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingInventory, mc.level);
            ItemStack resultFromRecipe = recipe.filter(r -> r.matches(craftingInventory, mc.level)).map(r -> r.assemble(craftingInventory)).orElse(ItemStack.EMPTY);
            if (resultFromRecipe.isEmpty()) {
                if (!recipe.isPresent())
                    invalid = true;
                success = false;
            } else if (resultFromRecipe.getCount() + amountCrafted > 64) {
                success = false;
            } else {
                amountCrafted += resultFromRecipe.getCount();
                if (result.isEmpty())
                    result = resultFromRecipe.copy();
                else
                    result.grow(resultFromRecipe.getCount());
                resultCraftable = true;
                firstPass = false;
            }
        }
        if (success || firstPass) {
            newlyAdded.forEach(s -> ItemHandlerHelper.insertItemStacked(availableItems, s, false));
            newlyMissing.forEach(s -> ItemHandlerHelper.insertItemStacked(missingItems, s, false));
        }
        if (!success) {
            if (firstPass) {
                result = invalid ? ItemStack.EMPTY : items.getStackInSlot(9);
                resultCraftable = false;
            }
            break;
        }
        if (!sneak)
            break;
    } while (success);
    for (int i = 0; i < 9; i++) {
        ItemStack available = availableItems.getStackInSlot(i);
        if (available.isEmpty())
            continue;
        ingredients.add(Pair.of(available, true));
    }
    for (int i = 0; i < 9; i++) {
        ItemStack missing = missingItems.getStackInSlot(i);
        if (missing.isEmpty())
            continue;
        ingredients.add(Pair.of(missing, false));
    }
}
Also used : Items(net.minecraft.world.item.Items) BlueprintSection(com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) Item(net.minecraft.world.item.Item) HashMap(java.util.HashMap) AllItems(com.simibubi.create.AllItems) BlueprintCraftingInventory(com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintCraftingInventory) IIngameOverlay(net.minecraftforge.client.gui.IIngameOverlay) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Ingredient(net.minecraft.world.item.crafting.Ingredient) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Minecraft(net.minecraft.client.Minecraft) ChatFormatting(net.minecraft.ChatFormatting) Map(java.util.Map) GuiGameElement(com.simibubi.create.foundation.gui.element.GuiGameElement) WhitelistMode(com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode) AnimationTickHolder(com.simibubi.create.foundation.utility.AnimationTickHolder) RecipeType(net.minecraft.world.item.crafting.RecipeType) IdentityHashMap(java.util.IdentityHashMap) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) ItemTags(net.minecraft.tags.ItemTags) EntityHitResult(net.minecraft.world.phys.EntityHitResult) ItemAttribute(com.simibubi.create.content.logistics.item.filter.ItemAttribute) Tag(net.minecraft.tags.Tag) Pair(com.simibubi.create.foundation.utility.Pair) AllGuiTextures(com.simibubi.create.foundation.gui.AllGuiTextures) HitResult(net.minecraft.world.phys.HitResult) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ForgeIngameGui(net.minecraftforge.client.gui.ForgeIngameGui) Optional(java.util.Optional) ItemStack(net.minecraft.world.item.ItemStack) Type(net.minecraft.world.phys.HitResult.Type) ListTag(net.minecraft.nbt.ListTag) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) Minecraft(net.minecraft.client.Minecraft) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) ItemStack(net.minecraft.world.item.ItemStack) BlueprintCraftingInventory(com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintCraftingInventory)

Aggregations

BlueprintSection (com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection)4 PoseStack (com.mojang.blaze3d.vertex.PoseStack)2 Minecraft (net.minecraft.client.Minecraft)2 ItemStack (net.minecraft.world.item.ItemStack)2 EntityHitResult (net.minecraft.world.phys.EntityHitResult)2 HitResult (net.minecraft.world.phys.HitResult)2 PartialModel (com.jozufozu.flywheel.core.PartialModel)1 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 Matrix3f (com.mojang.math.Matrix3f)1 AllItems (com.simibubi.create.AllItems)1 BlueprintCraftingInventory (com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintCraftingInventory)1 WhitelistMode (com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode)1 FilterItem (com.simibubi.create.content.logistics.item.filter.FilterItem)1 ItemAttribute (com.simibubi.create.content.logistics.item.filter.ItemAttribute)1 AllGuiTextures (com.simibubi.create.foundation.gui.AllGuiTextures)1 GuiGameElement (com.simibubi.create.foundation.gui.element.GuiGameElement)1 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)1 AnimationTickHolder (com.simibubi.create.foundation.utility.AnimationTickHolder)1 Pair (com.simibubi.create.foundation.utility.Pair)1 ArrayList (java.util.ArrayList)1