Skip to content

Commit

Permalink
Merge pull request #9 from heisluft/speedup
Browse files Browse the repository at this point in the history
Add Speed Upgrades and Downgrades
  • Loading branch information
ThePansmith authored May 17, 2024
2 parents 30a831e + 71bd1fa commit 122da6a
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.enderio.conduits.common.blockentity.connection.DynamicConnectionState;
import com.enderio.conduits.common.blockentity.connection.IConnectionState;
import com.enderio.conduits.common.blockentity.connection.StaticConnectionStates;
import com.enderio.conduits.common.init.ConduitItems;
import com.enderio.conduits.common.menu.ConduitMenu;
import com.enderio.conduits.common.network.ConduitSavedData;
import com.enderio.core.common.blockentity.EnderBlockEntity;
Expand All @@ -28,6 +29,7 @@
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.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -566,8 +568,9 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
}

ItemStack existing = getStackInSlot(slot);

int limit = Math.min(getSlotLimit(slot), stack.getMaxStackSize());
int limit = stack.getItem().equals(ConduitItems.SPEED_UPGRADE.asItem()) ? 15
: stack.getItem().equals(ConduitItems.SPEED_DOWNGRADE.asItem()) ? 3
: Math.min(getSlotLimit(slot), stack.getMaxStackSize());

if (!existing.isEmpty()) {
if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) {
Expand Down Expand Up @@ -629,8 +632,7 @@ public int getSlotLimit(int slot) {

@Override
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
//TODO implement
return slot < getSlots();
return slot < getSlots() && SlotData.of(slot).slotType().acceptsItem(stack.getItem());
}

@Override
Expand All @@ -647,8 +649,7 @@ public void setStackInSlot(int slot, @NotNull ItemStack stack) {
ConduitConnection connection = bundle.getConnection(data.direction());
ConduitMenuData conduitData = bundle.getTypes().get(data.conduitIndex()).getMenuData();

if ((data.slotType() == SlotType.FILTER_EXTRACT && conduitData.hasFilterExtract()) || (data.slotType() == SlotType.FILTER_INSERT
&& conduitData.hasFilterInsert()) || (data.slotType() == SlotType.UPGRADE_EXTRACT && conduitData.hasUpgrade())) {
if (data.slotType().isAvailableFor(conduitData)) {
connection.setItem(data.slotType(), data.conduitIndex(), stack);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.enderio.conduits.common.blockentity;

import com.enderio.api.conduit.ConduitMenuData;
import com.enderio.conduits.common.init.ConduitItems;
import net.minecraft.world.item.Item;

public enum SlotType {
FILTER_EXTRACT,
FILTER_INSERT,
UPGRADE_EXTRACT;

public static final int Y_POSITION = 71;

public boolean acceptsItem(Item item) {
return switch (this) {
case FILTER_INSERT, FILTER_EXTRACT -> item.equals(ConduitItems.BASIC_ITEM_FILTER.asItem()) || item.equals(ConduitItems.BIG_ITEM_FILTER.asItem());
case UPGRADE_EXTRACT -> item.equals(ConduitItems.SPEED_DOWNGRADE.asItem()) || item.equals(ConduitItems.SPEED_UPGRADE.asItem());
};
}

public int getX() {
return switch (this) {
case FILTER_EXTRACT -> 113;
Expand All @@ -27,4 +37,5 @@ public boolean isAvailableFor(ConduitMenuData data) {
case UPGRADE_EXTRACT -> data.hasUpgrade();
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.tterrag.registrate.Registrate;
import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.util.entry.ItemEntry;
import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraft.world.item.Item;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -26,6 +27,8 @@ public class ConduitItems {

public static final ItemEntry<FilterItem> BASIC_ITEM_FILTER = filterItemBasic("basic_item_filter").register();
public static final ItemEntry<FilterItem> BIG_ITEM_FILTER = filterItemBig("big_item_filter").register();
public static final ItemEntry<Item> SPEED_UPGRADE = REGISTRATE.item("extract_speed_upgrade", Item::new).tab(EIOCreativeTabs.MAIN).register();
public static final ItemEntry<Item> SPEED_DOWNGRADE = REGISTRATE.item("extract_speed_downgrade", Item::new).tab(EIOCreativeTabs.MAIN).register();

private static ItemEntry<Item> createConduitItem(Supplier<? extends ConduitType<?>> type, String itemName) {
return REGISTRATE.item(itemName + "_conduit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ public Slot setBackground(ResourceLocation atlas, ResourceLocation sprite) {

@Override
public boolean mayPlace(ItemStack stack) {
if (slotType == SlotType.UPGRADE_EXTRACT) {
return false;
}

// TODO check slot type, fluid filter for fluid etc...
return isVisible() && super.mayPlace(stack) && (
stack.is(ConduitItems.BASIC_ITEM_FILTER.asItem()))
|| stack.is(ConduitItems.BIG_ITEM_FILTER.asItem());
|| stack.is(ConduitItems.BIG_ITEM_FILTER.asItem())
|| stack.is(ConduitItems.SPEED_UPGRADE.asItem())
|| stack.is(ConduitItems.SPEED_DOWNGRADE.asItem());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.enderio.conduits.common.blockentity.ConduitBlockEntity;
import com.enderio.conduits.common.blockentity.SlotData;
import com.enderio.conduits.common.blockentity.SlotType;
import com.enderio.conduits.common.init.ConduitItems;
import dev.gigaherz.graph3.Graph;
import dev.gigaherz.graph3.Mergeable;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -35,7 +36,6 @@ public void tickGraph(ConduitType<?> type, List<NodeIdentifier<?>> loadedNodes,
var conduitItemHandler = conduitBlockEntity.getConduitItemHandler();

for (var slotType: SlotType.values()) {
if (slotType == SlotType.UPGRADE_EXTRACT) continue; // not implemented
for (var dir: Direction.values()) {
var extendedData = node.getExtendedConduitData().castTo(ItemExtendedData.class).compute(dir);
var item = conduitItemHandler.getStackInSlot(new SlotData(dir, conduitBlockEntity.getBundle().getTypes().indexOf(type), slotType).slotIndex());
Expand All @@ -46,6 +46,9 @@ public void tickGraph(ConduitType<?> type, List<NodeIdentifier<?>> loadedNodes,
if (slotType == SlotType.FILTER_INSERT) {
extendedData.insertFilter = item;
}
if (slotType == SlotType.UPGRADE_EXTRACT) {
extendedData.extractRate = item.isEmpty() ? 4 : item.getItem().equals(ConduitItems.SPEED_DOWNGRADE.asItem()) ? item.getCount() : 4 + 4 * item.getCount();
}
}
}
}
Expand All @@ -57,13 +60,13 @@ protected void tickCapabilityGraph(ConduitType<?> type, List<CapabilityConnectio
for (CapabilityConnection extract : extracts) {
IItemHandler extractHandler = extract.cap;
for (int i = 0; i < extractHandler.getSlots(); i++) {
ItemStack extractedItem = extractHandler.extractItem(i, 4, true);
ItemExtendedData.ItemSidedData sidedExtractData = extract.data.castTo(ItemExtendedData.class).compute(extract.direction);

ItemStack extractedItem = extractHandler.extractItem(i, sidedExtractData.extractRate, true);
if (extractedItem.isEmpty()) {
continue;
}

ItemExtendedData.ItemSidedData sidedExtractData = extract.data.castTo(ItemExtendedData.class).compute(extract.direction);

var insertFilterCap = sidedExtractData.extractFilter.getCapability(EIOCapabilities.ITEM_FILTER);
if (insertFilterCap.isPresent() && !insertFilterCap.resolve().get().testItem(extractedItem)) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static class ItemSidedData {
public int priority = 0;
public ItemStack insertFilter = ItemStack.EMPTY;
public ItemStack extractFilter = ItemStack.EMPTY;
public int extractRate = 4;

// region Serialization
private static final String KEY_ROTATING_INDEX = "RotatingIndex";
Expand All @@ -70,10 +71,12 @@ public static class ItemSidedData {
private static final String KEY_PRIORITY = "Priority";
private static final String KEY_INSERT_FILTER = "InsertFilter";
private static final String KEY_EXTRACT_FILTER = "ExtractFilter";
private static final String KEY_EXTRACT_RATE = "ExtractRate";

private CompoundTag toNbt() {
CompoundTag nbt = toGuiNbt();
nbt.putInt(KEY_ROTATING_INDEX, rotatingIndex);
nbt.putInt(KEY_EXTRACT_RATE, extractRate);
nbt.put(KEY_INSERT_FILTER, insertFilter.save(new CompoundTag()));
nbt.put(KEY_EXTRACT_FILTER, extractFilter.save(new CompoundTag()));
return nbt;
Expand All @@ -91,7 +94,8 @@ private static ItemSidedData fromNbt(CompoundTag nbt) {
ItemSidedData sidedData = new ItemSidedData();
sidedData.roundRobin = nbt.getBoolean(KEY_ROUND_ROBIN);
sidedData.selfFeed = nbt.getBoolean(KEY_SELF_FEED);
sidedData.priority= nbt.getInt(KEY_PRIORITY);
sidedData.priority = nbt.getInt(KEY_PRIORITY);
sidedData.extractRate = nbt.getInt(KEY_EXTRACT_RATE);
if (nbt.contains(KEY_ROTATING_INDEX)) {
sidedData.rotatingIndex= nbt.getInt(KEY_ROTATING_INDEX);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/generated/resources/assets/enderio/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@
"item.enderio.energy_conduit": "ʇınpuoƆ ʎbɹǝuƎ",
"item.enderio.enticing_crystal": "ןɐʇsʎɹƆ buıɔıʇuƎ",
"item.enderio.experience_rod": "poᴚ ǝɔuǝıɹǝdxƎ",
"item.enderio.extract_speed_downgrade": "ǝpɐɹbuʍoᗡ pǝǝdS ʇɔɐɹʇxƎ",
"item.enderio.extract_speed_upgrade": "ǝpɐɹbd∩ pǝǝdS ʇɔɐɹʇxƎ",
"item.enderio.filled_soul_vial": "ןɐıΛ ןnoS pǝןןıℲ",
"item.enderio.fire_water_bucket": "ʇǝʞɔnᗺ ɹǝʇɐM ǝɹıℲ",
"item.enderio.flour": "ɹnoןℲ",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/enderio/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@
"item.enderio.energy_conduit": "Energy Conduit",
"item.enderio.enticing_crystal": "Enticing Crystal",
"item.enderio.experience_rod": "Experience Rod",
"item.enderio.extract_speed_downgrade": "Extract Speed Downgrade",
"item.enderio.extract_speed_upgrade": "Extract Speed Upgrade",
"item.enderio.filled_soul_vial": "Filled Soul Vial",
"item.enderio.fire_water_bucket": "Fire Water Bucket",
"item.enderio.flour": "Flour",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "enderio:item/extract_speed_downgrade"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "enderio:item/extract_speed_upgrade"
}
}

0 comments on commit 122da6a

Please sign in to comment.