Skip to content

Commit

Permalink
Added the armor display + some datagen + added insets to the IOConfig…
Browse files Browse the repository at this point in the history
…Widget
  • Loading branch information
Trytoon committed Jul 13, 2023
1 parent 14e536d commit cc2e931
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 49 deletions.
34 changes: 34 additions & 0 deletions src/core/java/com/enderio/core/common/menu/SyncedMenu.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.enderio.core.common.menu;

import com.enderio.core.common.blockentity.EnderBlockEntity;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

import static net.minecraft.world.inventory.InventoryMenu.*;
import static net.minecraft.world.inventory.InventoryMenu.EMPTY_ARMOR_SLOT_HELMET;

public abstract class SyncedMenu<T extends EnderBlockEntity> extends AbstractContainerMenu {

@Nullable
Expand All @@ -18,6 +27,9 @@ public abstract class SyncedMenu<T extends EnderBlockEntity> extends AbstractCon

private final List<Slot> playerInventorySlots = new ArrayList<>();
private boolean playerInvVisible = true;

private static final ResourceLocation[] ARMOR_SLOT_TEXTURES = new ResourceLocation[] { EMPTY_ARMOR_SLOT_BOOTS, EMPTY_ARMOR_SLOT_LEGGINGS, EMPTY_ARMOR_SLOT_CHESTPLATE, EMPTY_ARMOR_SLOT_HELMET };
private static final EquipmentSlot[] EQUIPMENT_SLOTS = new EquipmentSlot[] { EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET };
protected SyncedMenu(@Nullable T blockEntity, Inventory inventory, @Nullable MenuType<?> pMenuType, int pContainerId) {
super(pMenuType, pContainerId);
this.blockEntity = blockEntity;
Expand Down Expand Up @@ -48,6 +60,28 @@ public void addInventorySlots(int xPos, int yPos) {
}

}
public void addArmorSlots(int xPos, int Ypos) {
for (int i = 0; i < 4; i++) {
EquipmentSlot slot = EQUIPMENT_SLOTS[i];
this.addSlot(new Slot(inventory, 36 + (3 - i), xPos, Ypos + i * 18) {
@Override
public int getMaxStackSize() {
return 1;
}

@Override
public boolean mayPlace(ItemStack stack) {
return stack.canEquip(slot, inventory.player);
}

@Override
public boolean mayPickup(Player player) {
ItemStack itemstack = this.getItem();
return super.mayPickup(player) && !EnchantmentHelper.hasBindingCurse(itemstack);
}
}.setBackground(InventoryMenu.BLOCK_ATLAS, ARMOR_SLOT_TEXTURES[slot.getIndex()]));
}
}

public boolean getPlayerInvVisible() {
return playerInvVisible;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"variants": {
"facing=east,powered=false": {
"model": "enderio:block/wired_charger",
"y": 90
},
"facing=east,powered=true": {
"model": "enderio:block/wired_charger",
"y": 90
},
"facing=north,powered=false": {
"model": "enderio:block/wired_charger"
},
"facing=north,powered=true": {
"model": "enderio:block/wired_charger"
},
"facing=south,powered=false": {
"model": "enderio:block/wired_charger",
"y": 180
},
"facing=south,powered=true": {
"model": "enderio:block/wired_charger",
"y": 180
},
"facing=west,powered=false": {
"model": "enderio:block/wired_charger",
"y": 270
},
"facing=west,powered=true": {
"model": "enderio:block/wired_charger",
"y": 270
}
"variants": {
"facing=east,powered=false": {
"model": "enderio:block/wired_charger",
"y": 90
},
"facing=east,powered=true": {
"model": "enderio:block/wired_charger_on",
"y": 90
},
"facing=north,powered=false": {
"model": "enderio:block/wired_charger"
},
"facing=north,powered=true": {
"model": "enderio:block/wired_charger_on"
},
"facing=south,powered=false": {
"model": "enderio:block/wired_charger",
"y": 180
},
"facing=south,powered=true": {
"model": "enderio:block/wired_charger_on",
"y": 180
},
"facing=west,powered=false": {
"model": "enderio:block/wired_charger",
"y": 270
},
"facing=west,powered=true": {
"model": "enderio:block/wired_charger_on",
"y": 270
}
}
}
9 changes: 1 addition & 8 deletions src/generated/resources/assets/enderio/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,16 +816,9 @@
"block.enderio.vibrant_capacitor_bank": "ʞuɐᗺ ɹoʇıɔɐdɐƆ ʇuɐɹqıΛ",
"block.enderio.vibrant_photovoltaic_cell": "ןןǝƆ ɔıɐʇןoʌoʇoɥԀ ʇuɐɹqıΛ",
"block.enderio.void_chassis": "sıssɐɥƆ pıoΛ",
"block.enderio.wired_charger": "ɹǝbɹɐɥƆ pǝɹıM",
"block.enderio.xp_juice": "ǝɔınſ dX",
"block.enderio.xp_vacuum": "ɯnnɔɐΛ dX",
"block.enderio.wired_charger": "ʌɹıǝW ɹǝɔɔɐƃ",
"description.enderio.enchantment.auto_smelt": "pǝuıɯ sı ɹǝʌǝʇɐɥʍ sǝʇןǝɯs ʎןןɐɔıʇɐɯoʇnⱯ",
"description.enderio.enchantment.repellent": "ɹǝɥʇɹɐɟ puɐ uǝʇɟo ǝɹoɯ ʇɹodǝןǝʇ sןǝʌǝן ɹǝɥbıH\nʎɐʍɐ sɹǝʞɔɐʇʇɐ ʇɹodǝןǝʇ oʇ ǝɔuɐɥƆ",
"description.enderio.enchantment.shimmer": "˙ʍouʞ I\n˙ssǝןǝsn sı ʇı 'sǝʎ\n˙ǝɹoɯ buıɥʇoN\n˙ʎןןɐǝᴚ\n˙ןןɐ s,ʇɐɥ⟘\n˙pǝʇuɐɥɔuǝ sɐʍ ʇı ɟı sɐ ɹǝɯɯıɥs ɯǝʇı ǝɥʇ sǝʞɐW",
"description.enderio.enchantment.soulbound": "¡buıʞɹoʍ ɯoɹɟ sıɥʇ ʇuǝʌǝɹd puɐ pıdnʇs ǝɹɐ spoɯ ǝuoʇsǝʌɐɹb ʇsoW :ǝʇoN\n˙ɥʇɐǝp uo ʇsoן buıǝq ɯoɹɟ ɯǝʇı sʇuǝʌǝɹԀ",
"description.enderio.enchantment.withering_arrow": "˙sʍoq oʇ sǝıןddⱯ\nʇǝbɹɐʇ ǝɥʇ oʇ ɹǝɥʇıʍ sǝıןddⱯ",
"description.enderio.enchantment.withering_blade": "suodɐǝʍ pǝpɐןq oʇ sǝıןddⱯ\nʇǝbɹɐʇ ǝɥʇ oʇ ɹǝɥʇıʍ sǝıןddⱯ",
"description.enderio.enchantment.withering_bolt": "˙sʍoqssoɹɔ oʇ sǝıןddⱯ\nʇǝbɹɐʇ ǝɥʇ oʇ ɹǝɥʇıʍ sǝıןddⱯ",
"description.enderio.enchantment.auto_smelt": "pǝuıɯ sı ɹǝʌǝʇɐɥʍ sʇןǝɯs ʎןןɐɔıʇɐɯoʇnⱯ",
"description.enderio.enchantment.repellent1": "ʎɐʍɐ sɹǝʞɔɐʇʇɐ ʇɹodǝןǝʇ oʇ ǝɔuɐɥƆ",
"description.enderio.enchantment.repellent2": "ɹǝɥʇɹɐɟ puɐ uǝʇɟo ǝɹoɯ ʇɹodǝןǝʇ sןǝʌǝן ɹǝɥbıH",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "enderio:block/wired_charger_front",
"textures": {
"front": "enderio:block/wired_charger_front"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"parent": "minecraft:block/block",
"children": {
"frame": {
"parent": "enderio:block/machine_frame"
},
"front": {
"parent": "enderio:block/wired_charger_front",
"textures": {
"front": "enderio:block/wired_charger_front_on"
}
},
"overlay": {
"parent": "enderio:block/io_overlay"
}
},
"item_render_order": [
"frame",
"overlay",
"front"
],
"loader": "forge:composite",
"textures": {
"particle": "enderio:block/machine_side"
}
}
10 changes: 5 additions & 5 deletions src/generated/resources/data/enderio/recipes/wired_charger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"D": {
"item": "enderio:dark_steel_ingot"
"C": {
"item": "enderio:copper_alloy_ingot"
},
"V": {
"item": "enderio:void_chassis"
}
},
"pattern": [
"DDD",
"DVD",
"DDD"
"CCC",
"CVC",
"CCC"
],
"result": {
"item": "enderio:wired_charger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"enderio:primitive_alloy_smelter",
"enderio:alloy_smelter",
"enderio:painting_machine",
"enderio:wired_charger",
"enderio:stirling_generator",
"enderio:sag_mill",
"enderio:impulse_hopper",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"enderio:primitive_alloy_smelter",
"enderio:alloy_smelter",
"enderio:painting_machine",
"enderio:wired_charger",
"enderio:stirling_generator",
"enderio:sag_mill",
"enderio:impulse_hopper",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected void init() {
addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(),
control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE));

addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font));
var inset = new IOConfigButton.Inset(21,0, 0, 0);
addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font, inset));
}

@Override
Expand All @@ -42,6 +43,6 @@ public ResourceLocation getBackgroundImage() {

@Override
protected Vector2i getBackgroundImageSize() {
return new Vector2i(195, 166);
return new Vector2i(197, 166);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void chargeItem() {
} else {
//todo energy balancing
// The energyExtracted per tick should increase if the charged item has more energy and with the tier of the capacitor installed
int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / (1000-this.energyStorage.getMaxEnergyUse());
int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / ((int)getCapacitorData().getModifier(CapacitorModifier.ENERGY_USE)*333 -this.energyStorage.getMaxEnergyUse());

if (this.energyStorage.getEnergyStored() >= energyExtracted) {
itemEnergyStorage.receiveEnergy(energyExtracted, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public EnergyConfig(ForgeConfigSpec.Builder builder) {
builder.pop();

builder.push("wiredCharger");
WIRED_CHARGER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 100000, 1, Integer.MAX_VALUE);
WIRED_CHARGER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 1000000, 1, Integer.MAX_VALUE);
WIRED_CHARGER_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 100, 1, Integer.MAX_VALUE);
builder.pop();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.enderio.machines.common.menu;

import com.enderio.EnderIO;
import com.enderio.machines.common.blockentity.WiredChargerBlockEntity;
import com.enderio.machines.common.init.MachineMenus;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.Nullable;

public class WiredChargerMenu extends MachineMenu<WiredChargerBlockEntity>{

public class WiredChargerMenu extends MachineMenu<WiredChargerBlockEntity> {

public WiredChargerMenu(WiredChargerBlockEntity blockEntity, Inventory inventory, int pContainerId) {
super(blockEntity, inventory, MachineMenus.WIRED_CHARGER.get(), pContainerId);
Expand All @@ -19,6 +26,11 @@ public WiredChargerMenu(WiredChargerBlockEntity blockEntity, Inventory inventory
addSlot(new MachineSlot(blockEntity.getInventory(), WiredChargerBlockEntity.ITEM_CHARGED, 126, 28));

addInventorySlots(29,84);
addArmorSlots(6,12);

//Add offhand slot
addSlot(new Slot(inventory, 40, 6, 84)
.setBackground(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD));
}

public static WiredChargerMenu factory(@Nullable MenuType<WiredChargerMenu> pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ protected void buildRecipes(Consumer<FinishedRecipe> finishedRecipeConsumer) {
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOBlocks.ENSOULED_CHASSIS.get()))
.save(finishedRecipeConsumer);

ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.WIRED_CHARGER.get())
.define('C', EIOItems.COPPER_ALLOY_INGOT.get())
.define('V', EIOBlocks.VOID_CHASSIS.get())
.pattern("CCC")
.pattern("CVC")
.pattern("CCC")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOBlocks.VOID_CHASSIS.get()))
.save(finishedRecipeConsumer);

ShapedEntityStorageRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.POWERED_SPAWNER)
.define('I', EIOItems.SOULARIUM_INGOT) //TODO Maybe also soulchains?
Expand Down Expand Up @@ -279,6 +289,7 @@ protected void buildRecipes(Consumer<FinishedRecipe> finishedRecipeConsumer) {
.pattern("CDC")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PHOTOVOLTAIC_PLATE.get()))
.save(finishedRecipeConsumer);

ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.BASIC))
.define('E', EIOItems.ENERGETIC_ALLOY_INGOT)
Expand All @@ -291,6 +302,7 @@ protected void buildRecipes(Consumer<FinishedRecipe> finishedRecipeConsumer) {
.pattern("CDC")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.SIMPLE)))
.save(finishedRecipeConsumer, EnderIO.loc(RecipeBuilder.getDefaultRecipeId(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.BASIC)).getPath() + "_upgrade"));

ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.ADVANCED))
.define('I', EIOItems.PULSATING_ALLOY_INGOT)
Expand All @@ -303,6 +315,7 @@ protected void buildRecipes(Consumer<FinishedRecipe> finishedRecipeConsumer) {
.pattern("CDC")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PHOTOVOLTAIC_PLATE))
.save(finishedRecipeConsumer);

ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.ADVANCED))
.define('I', EIOItems.PULSATING_ALLOY_INGOT)
Expand All @@ -316,6 +329,7 @@ protected void buildRecipes(Consumer<FinishedRecipe> finishedRecipeConsumer) {
.pattern("CSC")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.BASIC)))
.save(finishedRecipeConsumer, EnderIO.loc(RecipeBuilder.getDefaultRecipeId(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.ADVANCED)).getPath() + "_upgrade"));

ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.VIBRANT))
.define('I', EIOItems.VIBRANT_ALLOY_INGOT)
Expand All @@ -328,6 +342,7 @@ protected void buildRecipes(Consumer<FinishedRecipe> finishedRecipeConsumer) {
.pattern("CDC")
.unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PHOTOVOLTAIC_PLATE))
.save(finishedRecipeConsumer);

ShapedRecipeBuilder
.shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.VIBRANT))
.define('I', EIOItems.VIBRANT_ALLOY_INGOT)
Expand Down

0 comments on commit cc2e931

Please sign in to comment.