1st pass at fixing reconstructor...

This commit is contained in:
Flanks255 2022-01-18 19:11:23 -06:00
parent a8ba206b27
commit 92b0fed4d5
11 changed files with 84 additions and 42 deletions

View file

@ -41,13 +41,15 @@ public final class ActuallyAdditionsAPI {
public static final List<CrushingRecipe> CRUSHER_RECIPES = new ArrayList<>();
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<>();
// public static final List<TreasureChestLoot> TREASURE_CHEST_LOOT = new ArrayList<>();
public static final List<LensConversionRecipe> RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>();
//public static final List<LensConversionRecipe> RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>();
public static final List<EmpowererRecipe> EMPOWERER_RECIPES = new ArrayList<>();
public static final Map<Item, IColorLensChanger> RECONSTRUCTOR_LENS_COLOR_CHANGERS = new HashMap<>();
public static final List<SolidFuelRecipe> SOLID_FUEL_RECIPES = new ArrayList<>();
public static final List<PressingRecipe> PRESSING_RECIPES = new ArrayList<>();
public static final List<FermentingRecipe> FERMENTING_RECIPES = new ArrayList<>();
public static final List<LaserRecipe> CONVERSION_LASER_RECIPES = new ArrayList<>();
/**
* Farmer behaviors are sorted when first accessed, this will not be done until after loading, but do not add behaviors at runtime.
*/
@ -260,12 +262,12 @@ public final class ActuallyAdditionsAPI {
*/
@Deprecated
public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type) {
RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type));
//RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type));
}
@Deprecated
public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse) {
addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion);
//addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion);
}
/**
@ -279,11 +281,11 @@ public final class ActuallyAdditionsAPI {
* Note how this always has to be the same instance of the lens type that the item also has for it to work!
*/
public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse, LensConversion type) {
RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type));
//RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type));
}
public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse) {
addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion);
//addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion);
}
/**

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.lens.ILensItem;
import de.ellpeck.actuallyadditions.mod.blocks.base.FullyDirectionalBlock;
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFermentingBarrel;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.Lang;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
@ -89,11 +90,17 @@ public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container im
}
@Nullable
//@Override
public TileEntity newBlockEntity(IBlockReader worldIn) {
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityAtomicReconstructor();
}
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
// public BlockState getBaseConstructorState() {
// return this.stateContainer.getBaseState().with(FACING, Direction.NORTH);
// }

View file

@ -17,11 +17,13 @@ public class CommonConfig {
public static class MACHINES {
public static ForgeConfigSpec.IntValue FARMER_AREA;
public static ForgeConfigSpec.IntValue RECONSTRUCTOR_POWER;
public static void build() {
BUILDER.comment("Machine Settings").push("machineSettings");
FARMER_AREA = BUILDER.comment("The size of the farmer's farming area. Default is 9x9, must be an odd number.").defineInRange("farmerArea", 9, 1, Integer.MAX_VALUE);
RECONSTRUCTOR_POWER = BUILDER.comment("The amount of power the atomic reconstructor can store.").defineInRange("reconstructorPower", 300000, 300000, Integer.MAX_VALUE);
BUILDER.pop();
}

View file

@ -70,13 +70,6 @@ public enum ConfigIntValues {
500,
"The size of the booklet's large font in percent. Set to 0 to use defaults from the lang file."),
RECONSTRUCTOR_POWER(
"Atomic Reconstructor Power",
ConfigCategories.MACHINE_VALUES,
300000,
300000,
Integer.MAX_VALUE,
"The amount of power the atomic reconstructor can store."),
MINING_LENS_USE(
"Mining Lens Energy",
ConfigCategories.MACHINE_VALUES,

View file

@ -1,6 +1,7 @@
package de.ellpeck.actuallyadditions.mod.crafting;
import com.google.gson.JsonObject;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -16,6 +17,7 @@ import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistryEntry;
import javax.annotation.Nullable;
import java.util.Optional;
public class LaserRecipe implements IRecipe<IInventory> {
@ -37,10 +39,13 @@ public class LaserRecipe implements IRecipe<IInventory> {
}
public boolean matches(ItemStack itemStack, int energyIn) {
return itemIngredient.test(itemStack) && (energyIn >= energy);
}
public boolean matches(ItemStack itemStack) {
return itemIngredient.test(itemStack);
}
//nah
@Override
public boolean matches(IInventory pInv, World pLevel) {
@ -77,6 +82,14 @@ public class LaserRecipe implements IRecipe<IInventory> {
return ActuallyRecipes.Types.LASER;
}
public static Optional<LaserRecipe> getRecipeForStack(ItemStack stack) {
return ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.stream().filter(recipe -> recipe.matches(stack)).findFirst();
}
public boolean validInput(ItemStack stack) {
return getRecipeForStack(stack).isPresent();
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<LaserRecipe> {
@Override

View file

@ -58,7 +58,8 @@ public class LensColor extends Lens {
ItemStack returnStack = this.tryConvert(new ItemStack(block), hitState, hitBlock, tile);
if (returnStack != null && returnStack.getItem() instanceof BlockItem) {
Block toPlace = Block.byItem(returnStack.getItem());
BlockState state2Place = toPlace.defaultBlockState(); //getStateForPlacement(tile.getWorldObject(), hitBlock, Direction.UP, 0, 0, 0, FakePlayerFactory.getMinecraft((ServerWorld) tile.getWorldObject()), Hand.MAIN_HAND); //TODO
BlockState state2Place = toPlace.defaultBlockState();
//getStateForPlacement(tile.getWorldObject(), hitBlock, Direction.UP, 0, 0, 0, FakePlayerFactory.getMinecraft((ServerWorld) tile.getWorldObject()), Hand.MAIN_HAND); //TODO
tile.getWorldObject().setBlock(hitBlock, state2Place, 2);
tile.extractEnergy(ENERGY_USE);
}

View file

@ -27,7 +27,7 @@ import java.util.List;
public class LensMining extends Lens {
public static void init() {
public static void init() { //TODO ohhh boy
ActuallyAdditionsAPI.addMiningLensStoneOre("oreCoal", 5000);
ActuallyAdditionsAPI.addMiningLensNetherOre("oreNetherCoal", 5000);
ActuallyAdditionsAPI.addMiningLensStoneOre("oreIron", 3000);

View file

@ -14,17 +14,29 @@ import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay;
import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe;
import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3i;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class MethodHandler implements IMethodHandler {
@ -117,7 +129,7 @@ public class MethodHandler implements IMethodHandler {
@Override
public boolean invokeConversionLens(BlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) {
/* if (hitBlock != null) {
if (hitBlock != null) {
int range = 1;
int rangeX = 0;
int rangeY = 0;
@ -147,12 +159,12 @@ public class MethodHandler implements IMethodHandler {
if (state.getBlock() instanceof BlockLaserRelay) {
continue;
}
LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)), tile.getLens());
if (recipe != null && tile.getEnergy() >= recipe.getEnergyUsed()) {
ItemStack output = recipe.getOutput();
if (StackUtil.isValid(output)) {
Optional<LaserRecipe> recipe = LaserRecipe.getRecipeForStack(new ItemStack(state.getBlock()));
if (recipe.isPresent() && tile.getEnergy() >= recipe.get().getEnergy()) {
ItemStack output = recipe.get().getResultItem().copy();
if (!output.isEmpty()) {
tile.getWorldObject().levelEvent(2001, pos, Block.getId(state));
recipe.transformHook(ItemStack.EMPTY, state, pos, tile);
//recipe.transformHook(ItemStack.EMPTY, state, pos, tile); //TODO empty method
if (output.getItem() instanceof BlockItem) {
Block toPlace = Block.byItem(output.getItem());
BlockState state2Place = toPlace.defaultBlockState(); //.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND); //TODO
@ -163,7 +175,7 @@ public class MethodHandler implements IMethodHandler {
tile.getWorldObject().setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
}
tile.extractEnergy(recipe.getEnergyUsed());
tile.extractEnergy(recipe.get().getEnergy());
break;
}
}
@ -180,12 +192,12 @@ public class MethodHandler implements IMethodHandler {
for (ItemEntity item : items) {
ItemStack stack = item.getItem();
if (item.isAlive() && StackUtil.isValid(stack) && !item.getPersistentData().getBoolean("aa_cnv")) {
LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(stack, tile.getLens());
if (recipe != null) {
int itemsPossible = Math.min(tile.getEnergy() / recipe.getEnergyUsed(), stack.getCount());
Optional<LaserRecipe> recipe = LaserRecipe.getRecipeForStack(stack);
if (recipe.isPresent()) {
int itemsPossible = Math.min(tile.getEnergy() / recipe.get().getEnergy(), stack.getCount());
if (itemsPossible > 0) {
recipe.transformHook(item.getItem(), null, item.blockPosition(), tile);
//recipe.transformHook(item.getItem(), null, item.blockPosition(), tile); //TODO empty method
item.remove();
if (stack.getCount() - itemsPossible > 0) {
@ -196,21 +208,21 @@ public class MethodHandler implements IMethodHandler {
tile.getWorldObject().addFreshEntity(inputLeft);
}
ItemStack outputCopy = recipe.getOutput().copy();
ItemStack outputCopy = recipe.get().getResultItem().copy();
outputCopy.setCount(itemsPossible);
ItemEntity newItem = new ItemEntity(tile.getWorldObject(), item.getX(), item.getY(), item.getZ(), outputCopy);
newItem.getPersistentData().putBoolean("aa_cnv", true);
tile.getWorldObject().addFreshEntity(newItem);
tile.extractEnergy(recipe.getEnergyUsed() * itemsPossible);
tile.extractEnergy(recipe.get().getEnergy() * itemsPossible);
break;
}
}
}
}
return !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock);
}*/
}
return false;
}

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
@ -45,7 +46,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
public TileEntityAtomicReconstructor() {
super(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getTileEntityType(), 1);
int power = ConfigIntValues.RECONSTRUCTOR_POWER.getValue();
int power = CommonConfig.MACHINES.RECONSTRUCTOR_POWER.get();
int recieve = MathHelper.ceil(power * 0.016666F);
this.storage = new CustomEnergyStorage(power, recieve, 0);
this.lazyEnergy = LazyOptional.of(() -> this.storage);
@ -153,7 +154,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
@Override
public IAcceptor getAcceptor() {
return (slot, stack, automation) -> StackUtil.isValid(stack) && stack.getItem() instanceof ILensItem;
return (slot, stack, automation) -> !stack.isEmpty() && stack.getItem() instanceof ILensItem;
}
@Override

View file

@ -13,6 +13,8 @@ package de.ellpeck.actuallyadditions.mod.util;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import net.minecraft.client.Minecraft;
@ -30,6 +32,9 @@ import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.PacketDispatcher;
import net.minecraftforge.fml.network.PacketDistributor;
public final class AssetUtil {
@ -214,7 +219,7 @@ public final class AssetUtil {
data.putFloat("Size", size);
data.putInt("MaxAge", maxAge);
data.putFloat("Alpha", alpha);
//PacketHandler.THE_NETWORK.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96)); //TODO
PacketHandler.THE_NETWORK.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(startX, startY, startZ, 96, world.dimension())), new PacketServerToClient(data, PacketHandler.LASER_HANDLER));
}
}

View file

@ -3,11 +3,14 @@ package de.ellpeck.actuallyadditions.mod.util;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.RecipeManager;
import net.minecraft.resources.DataPackRegistries;
import net.minecraft.resources.IResourceManager;
import net.minecraft.resources.IResourceManagerReloadListener;
import java.util.List;
@SuppressWarnings("deprecation")
public class ResourceReloader implements IResourceManagerReloadListener {
private final DataPackRegistries data;
@ -29,5 +32,8 @@ public class ResourceReloader implements IResourceManagerReloadListener {
ActuallyAdditionsAPI.FERMENTING_RECIPES.clear();
ActuallyAdditionsAPI.FERMENTING_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.FERMENTING));
ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.clear();
ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.LASER));
}
}