Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class EIOMetaTileEntities {

public static GTESimpleMachineMetaTileEntity[] VIAL_EXTRACTOR = new GTESimpleMachineMetaTileEntity[V.length - 1];
public static GTESimpleMachineMetaTileEntity[] SLICE_N_SPLICE = new GTESimpleMachineMetaTileEntity[V.length - 1];
public static MetaTileEntitySliceNSplice[] SLICE_N_SPLICE = new MetaTileEntitySliceNSplice[V.length - 1];
public static GTESimpleMachineMetaTileEntity[] SOUL_BINDER = new GTESimpleMachineMetaTileEntity[V.length - 1];
public static MetaTileEntityElectricSpawner[] ELECTRIC_SPAWNER = new MetaTileEntityElectricSpawner[V.length - 1];

Expand All @@ -26,9 +26,12 @@ public static void init() {
GTETextures.VIAL_EXTRACTOR_OVERLAY, true, GTEUtility::gteId, GTUtility.hvCappedTankSizeFunction);

// SLICE_N_SPLICE 11023~11035
registerGTESimpleMetaTileEntity(SLICE_N_SPLICE, 11023, "slice_n_splice",
EnderIORecipeMaps.SLICE_N_SPLICE_RECIPES,
GTETextures.SLICE_N_SPLICE_OVERLAY, true, GTEUtility::gteId, GTUtility.defaultTankSizeFunction);

registerMetaTileEntities(SLICE_N_SPLICE, 11023, "slice_n_splice",
(tier, voltageName) -> new MetaTileEntitySliceNSplice(
gteId(String.format("%s.%s", "slice_n_splice", voltageName)),
EnderIORecipeMaps.SLICE_N_SPLICE_RECIPES,
GTETextures.SLICE_N_SPLICE_OVERLAY, tier, true, GTUtility.defaultTankSizeFunction));

// SOUL_BINDER 11036~11048
registerGTESimpleMetaTileEntity(SOUL_BINDER, 11036, "soul_binder", EnderIORecipeMaps.SOUL_BINDER_RECIPES,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.github.gtexpert.core.integration.eio.metatileentities;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.impl.ItemHandlerProxy;
import gregtech.api.capability.impl.NotifiableItemStackHandler;
import gregtech.api.capability.impl.RecipeLogicEnergy;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.ingredients.GTRecipeInput;
import gregtech.api.util.ItemStackHashStrategy;
import gregtech.client.renderer.ICubeRenderer;

import com.github.gtexpert.core.client.GTETextures;
import com.github.gtexpert.core.common.metatileentities.GTESimpleMachineMetaTileEntity;
import com.github.gtexpert.core.integration.eio.EnderIORecipeMaps;

public class MetaTileEntitySliceNSplice extends GTESimpleMachineMetaTileEntity {

public MetaTileEntitySliceNSplice(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, ICubeRenderer renderer,
int tier, boolean hasFrontFacing,
Function<Integer, Integer> tankScalingFunction) {
super(metaTileEntityId, recipeMap, renderer, tier, hasFrontFacing, tankScalingFunction);
}

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
return new MetaTileEntitySliceNSplice(this.metaTileEntityId, EnderIORecipeMaps.SLICE_N_SPLICE_RECIPES,
GTETextures.SLICE_N_SPLICE_OVERLAY, this.getTier(), this.hasFrontFacing(),
this.getTankScalingFunction());
}

@Override
protected RecipeLogicEnergy createWorkable(RecipeMap<?> recipeMap) {
return new SliceNSpliceRecipeLogic(this, recipeMap, () -> energyContainer);
}

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

this.importItems = new AmountLimitedItemStackHandler(this, 6, this);
this.itemInventory = new ItemHandlerProxy(this.importItems, this.exportItems);
}

protected boolean checkRecipe(@NotNull Recipe recipe) {
List<GTRecipeInput> inputs = recipe.getInputs();
for (int i = 0; i < inputs.size(); i++) {
if (!inputs.get(i).acceptsStack(this.importItems.getStackInSlot(i))) {
return false;
}
}
return true;
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
tooltip.add(I18n.format("gtexpert.machine.slice_n_splice.slot.1"));
tooltip.add(I18n.format("gtexpert.machine.slice_n_splice.slot.2"));
tooltip.add(I18n.format("gtexpert.machine.slice_n_splice.ordered"));
super.addInformation(stack, player, tooltip, advanced);
}

private static class AmountLimitedItemStackHandler extends NotifiableItemStackHandler {

private final Collection<Recipe> recipes;

public AmountLimitedItemStackHandler(MetaTileEntity metaTileEntity, int slots, MetaTileEntity entityToNotify) {
super(metaTileEntity, slots, entityToNotify, false);
this.recipes = EnderIORecipeMaps.SLICE_N_SPLICE_RECIPES.getRecipeList();
}

// === Copied from MetaTileEntityMachineHatch.LimitedImportHandler#insertItem ===
@NotNull
@Override
// Insert item returns the remainder stack that was not inserted
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
// If the item was not valid, nothing from the stack can be inserted
if (!isItemValid(slot, stack)) {
return stack;
}

// Return Empty if passed Empty
if (stack.isEmpty()) {
return ItemStack.EMPTY;
}

// If the stacks do not match, nothing can be inserted
if (!ItemStackHashStrategy.comparingAllButCount().equals(stack, this.getStackInSlot(slot)) &&
!this.getStackInSlot(slot).isEmpty()) {
return stack;
}

int amountInSlot = this.getStackInSlot(slot).getCount();
int slotLimit = getSlotLimit(slot);

// If the current stack size in the slot is greater than the limit of the Multiblock, nothing can be
// inserted
if (amountInSlot >= slotLimit) {
return stack;
}

// This will always be positive and greater than zero if reached
int spaceAvailable = slotLimit - amountInSlot;

// Insert the minimum amount between the amount of space available and the amount being inserted
int amountToInsert = Math.min(spaceAvailable, stack.getCount());

// The remainder that was not inserted
int remainderAmount = stack.getCount() - amountToInsert;

// Handle any remainder
ItemStack remainder = ItemStack.EMPTY;

if (remainderAmount > 0) {
remainder = stack.copy();
remainder.setCount(remainderAmount);
}

if (!simulate) {
// Perform the actual insertion
ItemStack temp = stack.copy();
temp.setCount(amountInSlot + amountToInsert);
this.setStackInSlot(slot, temp);
}

return remainder;
}

@Override
// Determine whether the item is used in the recipe
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
for (Recipe recipe : this.recipes) {
List<GTRecipeInput> inputs = recipe.getInputs();

if (slot < 0 || slot >= inputs.size()) continue;

if (inputs.get(slot).acceptsStack(stack)) {
return true;
}
}
return false;
}

@Override
public int getSlotLimit(int slot) {
return 1;
}
}

private static class SliceNSpliceRecipeLogic extends RecipeLogicEnergy {

public SliceNSpliceRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap,
Supplier<IEnergyContainer> energyContainer) {
super(tileEntity, recipeMap, energyContainer);
}

@Override
public boolean checkRecipe(@NotNull Recipe recipe) {
return ((MetaTileEntitySliceNSplice) metaTileEntity).checkRecipe(recipe) && super.checkRecipe(recipe);
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/gtexpert/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ gtexpert.machine.slice_n_splice.zpm.name=Elite Slice'N'Splice III
gtexpert.machine.slice_n_splice.zpm.tooltip=Slices heads and splices in all sorts of useful things/n§dAuthor:§f @MrKono
gtexpert.machine.slice_n_splice.uv.name=Ultimate Slice'N'Splice
gtexpert.machine.slice_n_splice.uv.tooltip=Slices heads and splices in all sorts of useful things/n§dAuthor:§f @MrKono
gtexpert.machine.slice_n_splice.slot.1=Only one item can be placed in each slot.
gtexpert.machine.slice_n_splice.slot.2=Only items related to the recipe can be placed.
gtexpert.machine.slice_n_splice.ordered=§fItems§7 must be in the correct order to run.


# Soul Binder
gtexpert.machine.soul_binder.lv.name=Basic Soul Binder
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/gtexpert/lang/ja_jp.lang
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ gtexpert.machine.slice_n_splice.zpm.name=精鋭型頭顱調整機 III
gtexpert.machine.slice_n_splice.zpm.tooltip=スライスした頭と様々な便利品を接合/n§d作者:§f @MrKono
gtexpert.machine.slice_n_splice.uv.name=究極型頭顱調整機
gtexpert.machine.slice_n_splice.uv.tooltip=スライスした頭と様々な便利品を接合/n§d作者:§f @MrKono
gtexpert.machine.slice_n_splice.slot.1=各スロットは1個しか配置できません
gtexpert.machine.slice_n_splice.slot.2=レシピに関係のあるアイテムのみしか配置できません
gtexpert.machine.slice_n_splice.ordered=§fアイテム§7がレシピ通りの順番で並んでいないと動作しません

# Soul Binder
gtexpert.machine.soul_binder.lv.name=基本型魂拘束器
Expand Down