Search in sources :

Example 1 with GunTableRecipe

use of mod.azure.doom.util.recipes.GunTableRecipe in project MCDoom by AzureDoom.

the class GunTableScreenHandler method switchTo.

public void switchTo(int recipeIndex) {
    // index out of bounds
    if (this.getRecipes().size() > recipeIndex) {
        GunTableRecipe gunTableRecipe = getRecipes().get(recipeIndex);
        for (int i = 0; i < 5; i++) {
            ItemStack slotStack = gunTableInventory.getStack(i);
            if (!slotStack.isEmpty()) {
                // if all positions can't be filled, transfer nothing
                if (!this.insertItem(slotStack, 6, 39, false)) {
                    return;
                }
                gunTableInventory.setStack(i, slotStack);
            }
        }
        for (int i = 0; i < 5; i++) {
            Ingredient ingredient = gunTableRecipe.getIngredientForSlot(i);
            if (!ingredient.isEmpty()) {
                ItemStack[] possibleItems = ((IngredientAccess) (Object) ingredient).getMatchingStacksMod();
                if (possibleItems != null) {
                    ItemStack first = new ItemStack(possibleItems[0].getItem(), gunTableRecipe.countRequired(i));
                    autofill(i, first);
                }
            }
        }
    }
}
Also used : Ingredient(net.minecraft.recipe.Ingredient) IngredientAccess(mod.azure.doom.mixin.IngredientAccess) GunTableRecipe(mod.azure.doom.util.recipes.GunTableRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 2 with GunTableRecipe

use of mod.azure.doom.util.recipes.GunTableRecipe in project MCDoom by AzureDoom.

the class GunTableOutputSlot method onTakeItem.

public void onTakeItem(PlayerEntity player, ItemStack stack) {
    this.onCrafted(stack);
    Optional<GunTableRecipe> optionalGunTableRecipe = player.world.getRecipeManager().getFirstMatch(Type.INSTANCE, gunTableInventory, player.world);
    if (optionalGunTableRecipe.isPresent()) {
        GunTableRecipe gunTableRecipe = optionalGunTableRecipe.get();
        DefaultedList<ItemStack> defaultedList = gunTableRecipe.getRemainder(gunTableInventory);
        for (int i = 0; i < defaultedList.size(); ++i) {
            ItemStack itemStack = this.gunTableInventory.getStack(i);
            ItemStack itemStack2 = defaultedList.get(i);
            if (!itemStack.isEmpty()) {
                this.gunTableInventory.removeStack(i, gunTableRecipe.countRequired(i));
                itemStack = this.gunTableInventory.getStack(i);
            }
            if (!itemStack2.isEmpty()) {
                if (itemStack.isEmpty()) {
                    this.gunTableInventory.setStack(i, itemStack2);
                } else if (ItemStack.areItemsEqualIgnoreDamage(itemStack, itemStack2) && ItemStack.areNbtEqual(itemStack, itemStack2)) {
                    itemStack2.increment(itemStack.getCount());
                    this.gunTableInventory.setStack(i, itemStack2);
                } else if (!this.player.getInventory().insertStack(itemStack2)) {
                    this.player.dropItem(itemStack2, false);
                }
            }
        }
    }
    this.markDirty();
}
Also used : GunTableRecipe(mod.azure.doom.util.recipes.GunTableRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 3 with GunTableRecipe

use of mod.azure.doom.util.recipes.GunTableRecipe in project MCDoom by AzureDoom.

the class GunTableScreen method render.

public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    this.renderBackground(matrices);
    super.render(matrices, mouseX, mouseY, delta);
    List<GunTableRecipe> tradeOfferList = this.handler.getRecipes();
    if (!tradeOfferList.isEmpty()) {
        int i = (this.width - this.backgroundWidth) / 2;
        int j = (this.height - this.backgroundHeight) / 2;
        int yPos = j + 17;
        int xPos = i + 3;
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderTexture(0, TEXTURE);
        this.renderScrollbar(matrices, i, j, tradeOfferList);
        int m = 0;
        while (true) {
            for (GunTableRecipe gunTableRecipe : tradeOfferList) if (this.canScroll(tradeOfferList.size()) && (m < this.indexStartOffset || m >= 7 + this.indexStartOffset)) {
                ++m;
            } else {
                ItemStack output = gunTableRecipe.getOutput();
                this.itemRenderer.zOffset = 100.0F;
                int n = yPos + 2;
                this.renderIngredients(matrices, gunTableRecipe, xPos, n);
                this.renderArrow(matrices, gunTableRecipe, i + 22, n);
                this.itemRenderer.renderInGui(output, i + 24 + 68, n);
                this.itemRenderer.renderGuiItemOverlay(this.textRenderer, output, i + 24 + 68, n);
                this.itemRenderer.zOffset = 0.0F;
                yPos += 20;
                ++m;
            }
            for (WidgetButtonPage widgetButtonPage : this.offers) {
                if (widgetButtonPage.isHovered()) {
                    widgetButtonPage.renderToolTip(matrices, mouseX, mouseY);
                }
                widgetButtonPage.visible = widgetButtonPage.index < this.handler.getRecipes().size();
            }
            RenderSystem.enableDepthTest();
            break;
        }
    }
    this.drawMouseoverTooltip(matrices, mouseX, mouseY);
}
Also used : GunTableRecipe(mod.azure.doom.util.recipes.GunTableRecipe) GameRenderer(net.minecraft.client.render.GameRenderer) ItemStack(net.minecraft.item.ItemStack)

Example 4 with GunTableRecipe

use of mod.azure.doom.util.recipes.GunTableRecipe in project MCDoom by AzureDoom.

the class GunTableScreenHandler method updateResult.

protected static void updateResult(int syncId, World world, PlayerEntity player, GunTableInventory craftingInventory) {
    if (!world.isClient) {
        ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) player;
        ItemStack itemStack = ItemStack.EMPTY;
        Optional<GunTableRecipe> optional = world.getServer().getRecipeManager().getFirstMatch(Type.INSTANCE, craftingInventory, world);
        if (optional.isPresent()) {
            GunTableRecipe craftingRecipe = optional.get();
            itemStack = craftingRecipe.craft(craftingInventory);
        }
        craftingInventory.setStack(5, itemStack);
        serverPlayerEntity.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(syncId, 0, 5, itemStack));
    }
}
Also used : ScreenHandlerSlotUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket) GunTableRecipe(mod.azure.doom.util.recipes.GunTableRecipe) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack)

Aggregations

GunTableRecipe (mod.azure.doom.util.recipes.GunTableRecipe)4 ItemStack (net.minecraft.item.ItemStack)4 IngredientAccess (mod.azure.doom.mixin.IngredientAccess)1 GameRenderer (net.minecraft.client.render.GameRenderer)1 ScreenHandlerSlotUpdateS2CPacket (net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket)1 Ingredient (net.minecraft.recipe.Ingredient)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1