♻️ Docs, build & some refactor
This commit is contained in:
10
README.md
10
README.md
@@ -1,10 +1,11 @@
|
|||||||
Trading Station
|
Trading Station
|
||||||
---------------
|
=============
|
||||||
|
|
||||||
Made for modpacks. It doesn't add any recipe.
|
Made for modpacks. It doesn't add any recipe.
|
||||||
|
|
||||||
Features
|
Features
|
||||||
========
|
--------
|
||||||
|
|
||||||
- Basic station with no power requirements.
|
- Basic station with no power requirements.
|
||||||
- Powered station with RF power requirements.
|
- Powered station with RF power requirements.
|
||||||
- Custom *Trading recipe*
|
- Custom *Trading recipe*
|
||||||
@@ -13,7 +14,8 @@ Features
|
|||||||
- Mechanical station available with companion mod.
|
- Mechanical station available with companion mod.
|
||||||
-
|
-
|
||||||
Trading recipe
|
Trading recipe
|
||||||
==============
|
---------------
|
||||||
|
|
||||||
- `ingredients` (required). An array/list of 1 or 2 ingredients.
|
- `ingredients` (required). An array/list of 1 or 2 ingredients.
|
||||||
- `result` (required). Single output item/block
|
- `result` (required). Single output item/block
|
||||||
- `processingTime` (optional). Ticks required to process. Default to 1. Powered machine has a 5x speed.
|
- `processingTime` (optional). Ticks required to process. Default to 1. Powered machine has a 5x speed.
|
||||||
@@ -30,7 +32,7 @@ Trading recipe
|
|||||||
|
|
||||||
|
|
||||||
KubeJS 6.1 Integration
|
KubeJS 6.1 Integration
|
||||||
======================
|
----------------------
|
||||||
```
|
```
|
||||||
ServerEvents.recipes(event => {
|
ServerEvents.recipes(event => {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ apply plugin: 'maven-publish'
|
|||||||
jarJar.enable()
|
jarJar.enable()
|
||||||
|
|
||||||
group = "com.${author}.${modid}"
|
group = "com.${author}.${modid}"
|
||||||
version = "${mod_version}"
|
version = "${minecraft_version}-${mod_version}"
|
||||||
archivesBaseName = "${modid}-${minecraft_version}"
|
archivesBaseName = "${modid}"
|
||||||
|
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ tasks.jarJar {
|
|||||||
}
|
}
|
||||||
void addLicense(jarTask) {
|
void addLicense(jarTask) {
|
||||||
jarTask.from('LICENSE.txt') {
|
jarTask.from('LICENSE.txt') {
|
||||||
rename { "${it}_${project.archivesBaseName}" }
|
rename { "${it}" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addLicense(jar)
|
addLicense(jar)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
@@ -28,8 +29,6 @@ public interface ITradingStationBlockEntity {
|
|||||||
|
|
||||||
ItemStack getTargetItemStack();
|
ItemStack getTargetItemStack();
|
||||||
|
|
||||||
Level getLevel();
|
|
||||||
|
|
||||||
BlockPos getBlockPos();
|
BlockPos getBlockPos();
|
||||||
|
|
||||||
void setPreferedItem(ItemStack itemStack);
|
void setPreferedItem(ItemStack itemStack);
|
||||||
@@ -63,19 +62,11 @@ public interface ITradingStationBlockEntity {
|
|||||||
boolean canProcess(ItemStack stack);
|
boolean canProcess(ItemStack stack);
|
||||||
void resetProgress();
|
void resetProgress();
|
||||||
|
|
||||||
default int getProcessingTime(){
|
int getProcessingTime();
|
||||||
return getRecipe().map(TradingRecipe::getProcessingTime).orElse(1);
|
|
||||||
}
|
|
||||||
default int getProgressPercent() {
|
default int getProgressPercent() {
|
||||||
return progress * 100 / maxProgress;
|
return progress * 100 / maxProgress;
|
||||||
}
|
}
|
||||||
default Optional<TradingRecipe> getRecipe(){
|
|
||||||
Level level = this.getLevel();
|
|
||||||
SimpleContainer inputInventory = getInputInventory();
|
|
||||||
if(!getTargetItemHandler().getStackInSlot(0).isEmpty())
|
|
||||||
return ModRecipes.findByOutput(level,getTargetItemHandler().getStackInSlot(0));
|
|
||||||
return ModRecipes.find(inputInventory,level, getBiome(), getTraderType());
|
|
||||||
};
|
|
||||||
default SimpleContainer getInputInventory(){
|
default SimpleContainer getInputInventory(){
|
||||||
int containerSize = 0;
|
int containerSize = 0;
|
||||||
for(int index = 0; index < getInputItems().getSlots(); index++) {
|
for(int index = 0; index < getInputItems().getSlots(); index++) {
|
||||||
@@ -93,28 +84,7 @@ public interface ITradingStationBlockEntity {
|
|||||||
});
|
});
|
||||||
return inputInventory;
|
return inputInventory;
|
||||||
}
|
}
|
||||||
default void craftItem() {
|
void craftItem();
|
||||||
SimpleContainer inputInventory = getInputInventory();
|
|
||||||
|
|
||||||
Optional<TradingRecipe> recipe = getRecipe();
|
|
||||||
|
|
||||||
if(recipe.isPresent()){
|
|
||||||
for (int i = 0; i < recipe.get().getIngredients().size(); i++) {
|
|
||||||
Ingredient ingredient = recipe.get().getIngredients().get(i);
|
|
||||||
|
|
||||||
for (int slot = 0; slot < getInputItems().getSlots(); slot++) {
|
|
||||||
ItemStack itemStack = getInputItems().getStackInSlot(slot);
|
|
||||||
if(ingredient.test(itemStack)){
|
|
||||||
getInputItems().extractItem(slot,ingredient.getItems()[0].getCount(),false);
|
|
||||||
inputInventory.setChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getOutputItems().insertItem(0, recipe.get().getResultItem(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resetProgress();
|
|
||||||
}
|
|
||||||
ItemStackHandler getInputItems();
|
ItemStackHandler getInputItems();
|
||||||
ItemStackHandler getOutputItems();
|
ItemStackHandler getOutputItems();
|
||||||
|
|
||||||
@@ -122,7 +92,5 @@ public interface ITradingStationBlockEntity {
|
|||||||
byte getCurrentRedstoneMode();
|
byte getCurrentRedstoneMode();
|
||||||
boolean isPowered();
|
boolean isPowered();
|
||||||
|
|
||||||
default Biome getBiome(){
|
Biome getBiome();
|
||||||
return this.getLevel().getBiome(getBlockPos()).get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import net.minecraft.world.inventory.ContainerData;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.AbstractFurnaceBlock;
|
import net.minecraft.world.level.block.AbstractFurnaceBlock;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
@@ -290,16 +291,9 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
isWorking = value;
|
isWorking = value;
|
||||||
BlockState pState = getBlockState().setValue(AbstractFurnaceBlock.LIT, Boolean.valueOf(isWorking()));
|
BlockState pState = getBlockState().setValue(AbstractFurnaceBlock.LIT, Boolean.valueOf(isWorking()));
|
||||||
|
|
||||||
// if(lastBlockState.getValue(BlockStateProperties.LIT) != pState.getValue(BlockStateProperties.LIT)){
|
|
||||||
// lastBlockState = pState;
|
|
||||||
getLevel().setBlock(getBlockPos(), pState, 3);
|
getLevel().setBlock(getBlockPos(), pState, 3);
|
||||||
setChanged(getLevel(), getBlockPos(), pState);
|
setChanged(getLevel(), getBlockPos(), pState);
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isWorking() {
|
private boolean isWorking() {
|
||||||
@@ -386,6 +380,30 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
return this.progress * 100 / this.maxProgress;
|
return this.progress * 100 / this.maxProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void craftItem() {
|
||||||
|
SimpleContainer inputInventory = getInputInventory();
|
||||||
|
|
||||||
|
Optional<TradingRecipe> recipe = getRecipe();
|
||||||
|
|
||||||
|
if(recipe.isPresent()){
|
||||||
|
for (int i = 0; i < recipe.get().getIngredients().size(); i++) {
|
||||||
|
Ingredient ingredient = recipe.get().getIngredients().get(i);
|
||||||
|
|
||||||
|
for (int slot = 0; slot < getInputItems().getSlots(); slot++) {
|
||||||
|
ItemStack itemStack = getInputItems().getStackInSlot(slot);
|
||||||
|
if(ingredient.test(itemStack)){
|
||||||
|
getInputItems().extractItem(slot,ingredient.getItems()[0].getCount(),false);
|
||||||
|
inputInventory.setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getOutputItems().insertItem(0, recipe.get().getResultItem(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.resetProgress();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStackHandler getInputItems() {
|
public ItemStackHandler getInputItems() {
|
||||||
return inputItems;
|
return inputItems;
|
||||||
@@ -480,4 +498,19 @@ public class TradingStationBlockEntity extends BlockEntity implements MenuProvi
|
|||||||
}
|
}
|
||||||
return targetedRecipe.get().getId().toString();
|
return targetedRecipe.get().getId().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Biome getBiome() {
|
||||||
|
return this.getLevel().getBiome(getBlockPos()).get();
|
||||||
|
}
|
||||||
|
protected Optional<TradingRecipe> getRecipe(){
|
||||||
|
SimpleContainer inputInventory = getInputInventory();
|
||||||
|
if(!getTargetItemHandler().getStackInSlot(0).isEmpty())
|
||||||
|
return ModRecipes.findByOutput(level,getTargetItemHandler().getStackInSlot(0));
|
||||||
|
return ModRecipes.find(inputInventory,level, getBiome(), getTraderType());
|
||||||
|
};
|
||||||
|
|
||||||
|
public int getProcessingTime(){
|
||||||
|
return getRecipe().map(TradingRecipe::getProcessingTime).orElse(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class TradingStationTargetSelectScreen extends Screen {
|
|||||||
this.blockEntity = pBlockEntity;
|
this.blockEntity = pBlockEntity;
|
||||||
this.blockPos = pBlockPos;
|
this.blockPos = pBlockPos;
|
||||||
//this.allPossibleRecipes = ModRecipes.getAllOutputs(pBlockEntity.getLevel(),pBlockEntity.getBiome(),pBlockEntity.getTraderType());
|
//this.allPossibleRecipes = ModRecipes.getAllOutputs(pBlockEntity.getLevel(),pBlockEntity.getBiome(),pBlockEntity.getTraderType());
|
||||||
this.allPossibleRecipes = ModRecipes.getAllRecipesForMachine(pBlockEntity.getLevel(),pBlockEntity.getBiome(),pBlockEntity.getTraderType());
|
this.allPossibleRecipes = ModRecipes.getAllRecipesForMachine(Minecraft.getInstance().level,pBlockEntity.getBiome(),pBlockEntity.getTraderType());
|
||||||
resetDisplayedTargets();
|
resetDisplayedTargets();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class PoweredTradingStationConfig {
|
|||||||
.defineInRange("energyTransfer", 2000, 1, Integer.MAX_VALUE);
|
.defineInRange("energyTransfer", 2000, 1, Integer.MAX_VALUE);
|
||||||
ENERGY_PER_TICK = COMMON_BUILDER
|
ENERGY_PER_TICK = COMMON_BUILDER
|
||||||
.comment("How much energy consumens per tick")
|
.comment("How much energy consumens per tick")
|
||||||
.defineInRange("energyPerTick", 1000, 1, Integer.MAX_VALUE);
|
.defineInRange("energyPerTick", 500, 1, Integer.MAX_VALUE);
|
||||||
COMMON_BUILDER.pop();
|
COMMON_BUILDER.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,4 +142,7 @@ public abstract class AbstractTradingMenu extends AbstractContainerMenu {
|
|||||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, HOTBAR_Y));
|
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, HOTBAR_Y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public Level getLevel(){
|
||||||
|
return level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public abstract class AbstractTradingScreen<MENU extends AbstractTradingMenu> ex
|
|||||||
|
|
||||||
|
|
||||||
if(!menu.blockEntity.getTargetItemStack().isEmpty()){
|
if(!menu.blockEntity.getTargetItemStack().isEmpty()){
|
||||||
Optional<TradingRecipe> recipe = ModRecipes.findByOutput(menu.blockEntity.getLevel(),menu.blockEntity.getTargetItemStack());
|
Optional<TradingRecipe> recipe = ModRecipes.findByOutput(menu.getLevel(),menu.blockEntity.getTargetItemStack());
|
||||||
if(recipe.isPresent()){
|
if(recipe.isPresent()){
|
||||||
renderFakeRecipe(recipe.get(), pPoseStack);
|
renderFakeRecipe(recipe.get(), pPoseStack);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.oierbravo.trading_station.registrate;
|
|||||||
import com.oierbravo.trading_station.TradingStation;
|
import com.oierbravo.trading_station.TradingStation;
|
||||||
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
import com.oierbravo.trading_station.content.trading_recipe.TradingRecipe;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.SimpleContainer;
|
import net.minecraft.world.SimpleContainer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
@@ -54,6 +55,8 @@ public class ModRecipes {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public static List<TradingRecipe> getAllRecipesForMachine(Level pLevel, Biome biome, String machineType) {
|
public static List<TradingRecipe> getAllRecipesForMachine(Level pLevel, Biome biome, String machineType) {
|
||||||
|
if(pLevel.isClientSide())
|
||||||
|
return NonNullList.create();
|
||||||
return pLevel.getRecipeManager().getAllRecipesFor(TradingRecipe.Type.INSTANCE).stream()
|
return pLevel.getRecipeManager().getAllRecipesFor(TradingRecipe.Type.INSTANCE).stream()
|
||||||
.filter((tradingRecipe -> tradingRecipe.matchesBiome(biome, pLevel)))
|
.filter((tradingRecipe -> tradingRecipe.matchesBiome(biome, pLevel)))
|
||||||
.filter((tradingRecipe -> tradingRecipe.matchesExclusiveTo(machineType)))
|
.filter((tradingRecipe -> tradingRecipe.matchesExclusiveTo(machineType)))
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ modId="trading_station"
|
|||||||
version="${file.jarVersion}"
|
version="${file.jarVersion}"
|
||||||
displayName="Trading Station"
|
displayName="Trading Station"
|
||||||
logoFile="logo.png"
|
logoFile="logo.png"
|
||||||
credits="Code inspirtation from the amazing Create mod"
|
credits="Code inspiration from the amazing Create mod, LaserIO and AlchemLib"
|
||||||
authors="oierbravo"
|
authors="oierbravo"
|
||||||
description='''
|
description='''
|
||||||
Trading made simple
|
Trading made simple
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 34 KiB |
Reference in New Issue
Block a user