Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the wired charger #172

Merged
merged 11 commits into from
Jul 25, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- Better multismelting support for the alloy smelter
- Wired Charger

### Changed
- Conduits are now placed in your inventory when shift right clicked with the Yeta Wrench
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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
}
}
}
8 changes: 8 additions & 0 deletions src/generated/resources/assets/enderio/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,14 @@
"block.enderio.void_chassis": "sıssɐɥƆ pıoΛ",
"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
1 change: 1 addition & 0 deletions src/generated/resources/assets/enderio/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@
"block.enderio.vibrant_capacitor_bank": "Vibrant Capacitor Bank",
"block.enderio.vibrant_photovoltaic_cell": "Vibrant Photovoltaic Cell",
"block.enderio.void_chassis": "Void Chassis",
"block.enderio.wired_charger": "Wired Charger",
"block.enderio.xp_juice": "Xp Juice",
"block.enderio.xp_vacuum": "Xp Vacuum",
"description.enderio.enchantment.auto_smelt": "Automatically smelts whatever is mined",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"parent": "minecraft:block/block",
"children": {
"frame": {
"parent": "enderio:block/machine_frame"
},
"front": {
"parent": "enderio:block/wired_charger_front"
},
"overlay": {
"parent": "enderio:block/io_overlay"
}
},
"item_render_order": [
"frame",
"overlay",
"front"
],
"loader": "forge:composite",
"textures": {
"particle": "enderio:block/machine_side"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "enderio:block/wired_charger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_ingredient": {
"conditions": {
"items": [
{
"items": [
"enderio:void_chassis"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "enderio:wired_charger"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_ingredient",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"enderio:wired_charger"
]
},
"sends_telemetry_event": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "",
"target": "BlockEntityTag"
}
],
"source": "block_entity"
}
],
"name": "enderio:wired_charger"
}
],
"rolls": 1.0
}
],
"random_sequence": "enderio:blocks/wired_charger"
}
21 changes: 21 additions & 0 deletions src/generated/resources/data/enderio/recipes/wired_charger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"D": {
"item": "enderio:dark_steel_ingot"
},
"V": {
"item": "enderio:void_chassis"
}
},
"pattern": [
"DDD",
"DVD",
"DDD"
],
"result": {
"item": "enderio:wired_charger"
},
"show_notification": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.enderio.machines.client.gui.screen;

import com.enderio.EnderIO;
import com.enderio.api.misc.Vector2i;
import com.enderio.base.common.lang.EIOLang;
import com.enderio.core.client.gui.screen.EIOScreen;
import com.enderio.core.client.gui.widgets.EnumIconWidget;
import com.enderio.machines.client.gui.widget.CapacitorEnergyWidget;
import com.enderio.machines.client.gui.widget.EnergyWidget;
import com.enderio.machines.client.gui.widget.ProgressWidget;
import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton;
import com.enderio.machines.common.menu.WiredChargerMenu;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public class WiredChargerScreen extends EIOScreen<WiredChargerMenu> {

private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/wired_charger.png");
public WiredChargerScreen(WiredChargerMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
super(pMenu, pPlayerInventory, pTitle);
}

@Override
protected void init() {
super.init();

addRenderableOnly(new ProgressWidget.BottomUp(this, () -> menu.getBlockEntity().getProgress(), getGuiLeft() + 103, getGuiTop() + 18, 12, 36, 242, 1));

addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, menu.getBlockEntity()::isCapacitorInstalled, 37 + leftPos, 14 + topPos, 9, 42));

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));
}

@Override
public ResourceLocation getBackgroundImage() {
return BG_TEXTURE;
}

@Override
protected Vector2i getBackgroundImageSize() {
return new Vector2i(195, 166);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.enderio.machines.common.blockentity;

import com.enderio.api.capacitor.CapacitorModifier;
import com.enderio.api.capacitor.QuadraticScalable;
import com.enderio.api.io.energy.EnergyIOMode;
import com.enderio.core.common.network.slot.FloatNetworkDataSlot;
import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity;
import com.enderio.machines.common.config.MachinesConfig;
import com.enderio.machines.common.io.item.MachineInventoryLayout;
import com.enderio.machines.common.io.item.SingleSlotAccess;
import com.enderio.machines.common.menu.WiredChargerMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.energy.IEnergyStorage;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class WiredChargerBlockEntity extends PoweredMachineBlockEntity {

public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, MachinesConfig.COMMON.ENERGY.WIRED_CHARGER_CAPACITY);
public static final QuadraticScalable USAGE = new QuadraticScalable(CapacitorModifier.ENERGY_USE, MachinesConfig.COMMON.ENERGY.WIRED_CHARGER_USAGE);

public static final SingleSlotAccess ITEM_TO_CHARGE = new SingleSlotAccess();
public static final SingleSlotAccess ITEM_CHARGED = new SingleSlotAccess();

private float progress = 0;

public WiredChargerBlockEntity(BlockEntityType<?> type, BlockPos worldPosition, BlockState blockState) {
super(EnergyIOMode.Input, CAPACITY, USAGE, type, worldPosition, blockState);
addDataSlot(new FloatNetworkDataSlot(this::getProgress, p -> progress = p));
}

Trytoon marked this conversation as resolved.
Show resolved Hide resolved
@Override
public MachineInventoryLayout getInventoryLayout() {
return MachineInventoryLayout
.builder()
.capacitor()
.inputSlot((slot, stack) -> acceptItem(stack))
.slotAccess(ITEM_TO_CHARGE)
.outputSlot()
.slotAccess(ITEM_CHARGED)
.build();
}

@Nullable
@Override
public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
return new WiredChargerMenu(this, pPlayerInventory, pContainerId);
}

@Override
public void serverTick() {
super.serverTick();
if (canAct()) {
chargeItem();
} else {
this.progress = 0;
}
}

@Override
protected boolean isActive() {
return canAct();
}

public boolean acceptItem(ItemStack item) {
Optional<IEnergyStorage> energyHandlerCap = item.getCapability(ForgeCapabilities.ENERGY).resolve();
return energyHandlerCap.isPresent();
}

@Override
public boolean canAct() {
ItemStack inputItem = ITEM_TO_CHARGE.getItemStack(this);
ItemStack outputItem = ITEM_CHARGED.getItemStack(this);
return !inputItem.isEmpty() && outputItem.isEmpty() && acceptItem(inputItem) && super.canAct();
}

public void chargeItem() {
ItemStack chargeable = ITEM_TO_CHARGE.getItemStack(this);
Optional<IEnergyStorage> energyHandlerCap = chargeable.getCapability(ForgeCapabilities.ENERGY).resolve();

if (energyHandlerCap.isPresent()) {
IEnergyStorage itemEnergyStorage = energyHandlerCap.get();
if (itemEnergyStorage.getEnergyStored() == itemEnergyStorage.getMaxEnergyStored()) {
ITEM_CHARGED.setStackInSlot(this, chargeable);
ITEM_TO_CHARGE.setStackInSlot(this, ItemStack.EMPTY);
} 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());

if (this.energyStorage.getEnergyStored() >= energyExtracted) {
itemEnergyStorage.receiveEnergy(energyExtracted, false);
this.energyStorage.takeEnergy(energyExtracted);
this.progress = (float)itemEnergyStorage.getEnergyStored()/itemEnergyStorage.getMaxEnergyStored();
}
}
}
}

public float getProgress() {
return this.progress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class EnergyConfig {
public final ForgeConfigSpec.ConfigValue<Integer> BASIC_SOLAR_PANEL_MAX_PRODUCTION;
public final ForgeConfigSpec.ConfigValue<Integer> ADVANCED_SOLAR_PANEL_MAX_PRODUCTION;
public final ForgeConfigSpec.ConfigValue<Integer> VIBRANT_SOLAR_PANEL_MAX_PRODUCTION;
public final ForgeConfigSpec.ConfigValue<Integer> WIRED_CHARGER_CAPACITY;
public final ForgeConfigSpec.ConfigValue<Integer> WIRED_CHARGER_USAGE;

public EnergyConfig(ForgeConfigSpec.Builder builder) {
builder.push("energy");
Expand Down Expand Up @@ -87,6 +89,11 @@ public EnergyConfig(ForgeConfigSpec.Builder builder) {
VIBRANT_SOLAR_PANEL_MAX_PRODUCTION = builder.defineInRange("vibrant", 160, 1, Integer.MAX_VALUE);
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_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 100, 1, Integer.MAX_VALUE);
builder.pop();

builder.pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class MachineBlockEntities {

public static final BlockEntityEntry<SoulBinderBlockEntity> SOUL_BINDER = register("soul_binder", SoulBinderBlockEntity::new, MachineBlocks.SOUL_BINDER);

public static final BlockEntityEntry<WiredChargerBlockEntity> WIRED_CHARGER = register("wired_charger",
WiredChargerBlockEntity::new, MachineBlocks.WIRED_CHARGER);

public static final BlockEntityEntry<PaintingMachineBlockEntity> PAINTING_MACHINE = register("painting_machine", PaintingMachineBlockEntity::new, MachineBlocks.PAINTING_MACHINE);

public static final BlockEntityEntry<PoweredSpawnerBlockEntity> POWERED_SPAWNER = register("powered_spawner", PoweredSpawnerBlockEntity::new, MachineBlocks.POWERED_SPAWNER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public class MachineBlocks {
public static final BlockEntry<ProgressMachineBlock> PAINTING_MACHINE = standardMachine("painting_machine", () -> MachineBlockEntities.PAINTING_MACHINE)
.register();

public static final BlockEntry<ProgressMachineBlock> WIRED_CHARGER = standardMachine("wired_charger", () -> MachineBlockEntities.WIRED_CHARGER)
.register();

public static final BlockEntry<MachineBlock> CREATIVE_POWER = REGISTRATE
.block("creative_power", props -> new MachineBlock(props, MachineBlockEntities.CREATIVE_POWER))
.item()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private MachineMenus() {}
public static final MenuEntry<VacuumChestMenu> VACUUM_CHEST = REGISTRATE.menu("vacuum_chest", VacuumChestMenu::factory, () -> VacuumChestScreen::new).register();
public static final MenuEntry<XPVacuumMenu> XP_VACUUM = REGISTRATE.menu("xp_vacuum", XPVacuumMenu::factory, () -> XPVacuumScreen::new).register();
public static final MenuEntry<CrafterMenu> CRAFTER = REGISTRATE.menu("crafter", CrafterMenu::factory, () -> CrafterScreen::new).register();
public static final MenuEntry<WiredChargerMenu> WIRED_CHARGER = REGISTRATE.menu("wired_charger", WiredChargerMenu::factory, () -> WiredChargerScreen::new).register();
public static final MenuEntry<PaintingMachineMenu> PAINTING_MACHINE = REGISTRATE.menu("painting_machine", PaintingMachineMenu::factory, () -> PaintingMachineScreen::new).register();
public static final MenuEntry<CapacitorBankMenu> CAPACITOR_BANK = REGISTRATE.menu("capacitor_bank", CapacitorBankMenu::factory, () -> CapacitorBankScreen::new).register();

Expand Down