Skip to content

Commit

Permalink
Begin adding recipe modification addons
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Mar 18, 2024
1 parent 0cbda8a commit 224116e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,13 @@ public void handleNetworkEntry(NetworkContent.MachineSyncPacket message) {
this.setInventoryInputMode(message.inputMode());
}

public List<ItemStack> getCraftingResults(OritechRecipe activeRecipe) {
return activeRecipe.getResults();
}

private void craftItem(OritechRecipe activeRecipe, List<ItemStack> outputInventory, List<ItemStack> inputInventory) {

var results = activeRecipe.getResults();
var results = getCraftingResults(activeRecipe);
var inputs = activeRecipe.getInputs();

// create outputs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package rearth.oritech.block.entity.machines.processing;

import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import rearth.oritech.block.base.entity.MultiblockMachineEntity;
import rearth.oritech.client.init.ModScreens;
import rearth.oritech.init.BlockContent;
import rearth.oritech.init.BlockEntitiesContent;
import rearth.oritech.init.recipes.OritechRecipe;
import rearth.oritech.init.recipes.OritechRecipeType;
import rearth.oritech.init.recipes.RecipeContent;
import rearth.oritech.util.InventorySlotAssignment;

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

public class FragmentForgeBlockEntity extends MultiblockMachineEntity {

private boolean hasByproductAddon;

public FragmentForgeBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntitiesContent.FRAGMENT_FORGE_ENTITY, pos, state, 50);
}
Expand All @@ -24,9 +31,57 @@ protected OritechRecipeType getOwnRecipeType() {
return RecipeContent.GRINDER;
}

@Override
public void getAdditionalStatFromAddon(AddonBlock addonBlock) {
if (addonBlock.state().getBlock().equals(BlockContent.MACHINE_ACCEPTOR_ADDON)) {
System.out.println("found desired addon");
hasByproductAddon = true;
}
}

@Override
public void resetAddons() {
super.resetAddons();
hasByproductAddon = false;
}

@Override
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);
nbt.putBoolean("byproductAddon", hasByproductAddon);
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);
hasByproductAddon = nbt.getBoolean("byproductAddon");
}

@Override
public List<ItemStack> getCraftingResults(OritechRecipe activeRecipe) {
if (hasByproductAddon) {
var result = new ArrayList<ItemStack>(activeRecipe.getResults().size());
List<ItemStack> source = activeRecipe.getResults();
for (int i = 0; i < source.size(); i++) {
var item = source.get(i);
if (i == 0) {
result.add(item);
} else {
var newCount = item.getCount() * 2;
var newItem = new ItemStack(item.getItem(), newCount);
result.add(newItem);
}
}
System.out.println(result);
return result;
} else {
return super.getCraftingResults(activeRecipe);
}
}

@Override
public InventorySlotAssignment getSlots() {
return new InventorySlotAssignment(0, 4, 4, 1);
return new InventorySlotAssignment(0, 4, 4, 2);
}

@Override
Expand All @@ -36,7 +91,8 @@ public List<GuiSlot> getGuiSlots() {
new GuiSlot(1, 100, 11),
new GuiSlot(2, 120, 11),
new GuiSlot(3, 140, 11),
new GuiSlot(4, 80, 59));
new GuiSlot(4, 80, 59),
new GuiSlot(5, 100, 59));
}

@Override
Expand All @@ -46,7 +102,7 @@ public ScreenHandlerType<?> getScreenHandlerType() {

@Override
public int getInventorySize() {
return 5;
return 6;
}

// x = back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public abstract class GenericPipeInterfaceEntity extends BlockEntity implements BlockEntityTicker<GenericPipeInterfaceEntity> {

public static final int MAX_SEARCH_COUNT = 128;
public static final int MAX_SEARCH_COUNT = 256;

public GenericPipeInterfaceEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/rearth/oritech/util/MachineAddonController.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,19 @@ default void gatherAddonStats(List<AddonBlock> addons) {
energyAmount += capacitorBlock.getAddedCapacity();
energyInsert += capacitorBlock.getAddedInsert();
}

getAdditionalStatFromAddon(addon);
}

var baseData = new BaseAddonData(speed, efficiency, energyAmount, energyInsert);
setBaseAddonData(baseData);
}

// used to check for specific addons, or do something if a specific addon has been found
default void getAdditionalStatFromAddon(AddonBlock addonBlock) {

}

// update state of the found addons
default void writeAddons(List<AddonBlock> addons) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
"id": "minecraft:emerald",
"Count": 2
},
{
"id": "minecraft:iron_nugget",
"Count": 1
}
],
"time": 40
Expand Down

0 comments on commit 224116e

Please sign in to comment.