Skip to content

Commit

Permalink
Finished recipe system rewrite, updated fabric.mod.json, added more r…
Browse files Browse the repository at this point in the history
…ecipes, cleaned up machine code.
  • Loading branch information
Dragonoidzero committed Mar 4, 2021
1 parent 1011d1a commit dbd259b
Show file tree
Hide file tree
Showing 70 changed files with 1,092 additions and 439 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.5
yarn_mappings=1.16.5+build.5
loader_version=0.11.2
# Mod Properties
mod_version=ALPHA.12
mod_version=ALPHA.11
maven_group=azzy.ttlg
archives_base_name=TTLG
libgui_version=3.3.3+1.16.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

import azzy.fabric.lookingglass.block.LookingGlassBlocks;
import azzy.fabric.lookingglass.item.LookingGlassItems;
import azzy.fabric.lookingglass.recipe.AlloyingRecipe;
import azzy.fabric.lookingglass.recipe.FreezingRecipe;
import azzy.fabric.lookingglass.recipe.InductionRecipe;
import azzy.fabric.lookingglass.recipe.LookingGlassRecipes;
import azzy.fabric.lookingglass.util.rei.AlloyingRecipeCategory;
import azzy.fabric.lookingglass.util.rei.FreezingRecipeCategory;
import azzy.fabric.lookingglass.util.rei.InductionRecipeCategory;
import azzy.fabric.lookingglass.util.rei.LookingGlassRecipeDisplay;
import azzy.fabric.lookingglass.recipe.*;
import azzy.fabric.lookingglass.util.rei.*;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeHelper;
import me.shedaniel.rei.api.plugins.REIPluginV0;
Expand All @@ -23,21 +17,29 @@ public void registerRecipeDisplays(RecipeHelper recipeHelper) {
recipeHelper.registerRecipes(LookingGlassRecipes.ALLOYING_RECIPE.getId(), AlloyingRecipe.class, LookingGlassRecipeDisplay::new);
recipeHelper.registerRecipes(LookingGlassRecipes.INDUCTION_RECIPE.getId(), InductionRecipe.class, LookingGlassRecipeDisplay::new);
recipeHelper.registerRecipes(LookingGlassRecipes.FREEZING_RECIPE.getId(), FreezingRecipe.class, LookingGlassRecipeDisplay::new);
recipeHelper.registerRecipes(LookingGlassRecipes.GRINDING_RECIPE.getId(), GrindingRecipe.class, LookingGlassRecipeDisplay::new);
recipeHelper.registerRecipes(LookingGlassRecipes.MIXING_RECIPE.getId(), MixingRecipe.class, LookingGlassRecipeDisplay::new);
}

@Override
public void registerPluginCategories(RecipeHelper recipeHelper) {
recipeHelper.registerCategory(new AlloyingRecipeCategory());
recipeHelper.registerCategory(new InductionRecipeCategory());
recipeHelper.registerCategory(new FreezingRecipeCategory());
recipeHelper.registerCategory(new GrindingRecipeCategory());
recipeHelper.registerCategory(new MixingRecipeCategory());
}

@Override
public void registerOthers(RecipeHelper recipeHelper) {
recipeHelper.registerWorkingStations(DefaultPlugin.SMELTING, EntryStack.create(LookingGlassBlocks.POWERED_FURNACE_BLOCK));
recipeHelper.registerWorkingStations(DefaultPlugin.BLASTING, EntryStack.create(LookingGlassItems.BLAST_UPGRADE_ITEM));

recipeHelper.registerWorkingStations(LookingGlassRecipes.ALLOYING_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.ALLOY_FURNACE_BLOCK));
recipeHelper.registerWorkingStations(LookingGlassRecipes.INDUCTION_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.BLOCK_INDUCTOR_BLOCK));
recipeHelper.registerWorkingStations(LookingGlassRecipes.GRINDING_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.GRINDER_BLOCK));
recipeHelper.registerWorkingStations(LookingGlassRecipes.MIXING_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.MIXER_BLOCK));

recipeHelper.registerWorkingStations(DefaultPlugin.BLASTING, EntryStack.create(LookingGlassItems.BLAST_UPGRADE_ITEM));
recipeHelper.registerWorkingStations(LookingGlassRecipes.FREEZING_RECIPE.getId(), EntryStack.create(LookingGlassItems.FREEZER_UPGRADE_ITEM));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import azzy.fabric.lookingglass.mixin.RecipeMapAccessor;
import azzy.fabric.lookingglass.recipe.InductionRecipe;
import azzy.fabric.lookingglass.recipe.LookingGlassRecipes;
import azzy.fabric.lookingglass.util.BlockEntityMover;
import azzy.fabric.lookingglass.util.FalseInventory;
import azzy.fabric.lookingglass.util.machine.BlockEntityMover;
import azzy.fabric.lookingglass.util.machine.FalseInventory;
import azzy.fabric.lookingglass.util.LookingGlassSounds;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import org.jetbrains.annotations.Nullable;

public class HorizontalMachineBlock extends LookingGlassBlock {
Expand All @@ -25,4 +29,9 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
builder.add(Properties.LIT);
super.appendProperties(builder);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return super.getCollisionShape(state, world, pos, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ private static FabricBlockSettings eldenMachine() {
public static final Block PROJECTORBLOCK = registerBlock("projector", new ProjectorBlock(paleMachine().luminance(ignored -> 7)), basicItem());
public static final Block CHUNKLOADERBLOCK = registerBlock("chunkloader", new ChunkAnchorBlock(paleMachine().luminance(ignored -> 7)), basicItem());
public static final Block WORMHOLEBLOCK = registerBlock("wormhole", new WormholeBlock(paleMachine().luminance(ignored -> 5)), basicItem());
public static final Block VACUUM_HOPPER_BLOCK = registerBlock("vacuum_hopper", new VacuumHopperBlock(dwarvenMachine(), 20, 4, 9), basicItem());
public static final Block ADVANCED_VACUUM_HOPPER_BLOCK = registerBlock("advanced_vacuum_hopper", new VacuumHopperBlock(hardenedMachine(), 5, 7, 27), advancedItem());
public static final Block BLOCK_TESSERACT_BLOCK = registerBlock("block_tesseract", new BlockTesseractBlock(eldenMachine().nonOpaque()), lategameItem());
public static final Block BLOCK_INDUCTOR_BLOCK = registerBlock("block_inductor", new BlockInductorBlock(basicMachine(BlockSoundGroup.STONE).nonOpaque().luminance(state -> state.get(AbstractInductorBlock.POWERED) ? 15 : 5)), basicItem());
Expand All @@ -100,6 +99,7 @@ private static FabricBlockSettings eldenMachine() {
public static final Block ALLOY_FURNACE_BLOCK = registerBlock("alloy_furnace", new AlloyFurnaceBlock(dwarvenMachine()), basicItem());
public static final Block GRINDER_BLOCK = registerBlock("grinder", new GrinderBlock(dwarvenMachine()), basicItem());
public static final Block MIXER_BLOCK = registerBlock("mixer", new MixerBlock(dwarvenMachine()), basicItem());
public static final Block VACUUM_HOPPER_BLOCK = registerBlock("vacuum_hopper", new VacuumHopperBlock(dwarvenMachine(), 20, 4, 9), basicItem());

//Power
public static final Block CREATIVE_ENERGY_SOURCE_BLOCK = registerBlock("creative_energy_source", new CreativeEnergySourceBlock(paleMachine().nonOpaque().luminance(7).emissiveLighting((state, world, pos) -> true)), worldforgeItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,9 @@ public void tick() {
private void tickRecipeProgression() {
if(trackedRecipe != null) {
if(progress >= getProcessTime()) {
ItemStack outSlot = inventory.get(2);
if(outSlot.isEmpty()) {
inventory.set(2, trackedRecipe.craft(this));
inventory.get(1).decrement(1);
inventory.get(0).decrement(1);
progress = 0;
sync();
}
ItemStack output = trackedRecipe.getOutput();
if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) {
inventory.get(2).increment(output.getCount());
inventory.get(1).decrement(1);
inventory.get(0).decrement(1);
progress = 0;
sync();
}
trackedRecipe.craft(this);
progress = 0;
sync();
}
else {
double drain = getPowerUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import azzy.fabric.lookingglass.block.LookingGlassBlocks;
import azzy.fabric.lookingglass.render.TesseractRenderable;
import azzy.fabric.lookingglass.util.BlockEntityMover;
import azzy.fabric.lookingglass.util.machine.BlockEntityMover;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package azzy.fabric.lookingglass.blockentity;

import azzy.fabric.lookingglass.block.LookingGlassBlocks;
import azzy.fabric.lookingglass.gui.AlloyingFurnaceGuiDescription;
import azzy.fabric.lookingglass.gui.GrinderGuiDescription;
import azzy.fabric.lookingglass.recipe.AlloyingRecipe;
import azzy.fabric.lookingglass.recipe.GrinderRecipe;
import azzy.fabric.lookingglass.recipe.GrindingRecipe;
import azzy.fabric.lookingglass.recipe.LookingGlassRecipes;
import io.github.cottonmc.cotton.gui.PropertyDelegateHolder;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -23,7 +21,7 @@
@SuppressWarnings("unchecked")
public class GrinderEntity extends LookingGlassUpgradeableMachine implements PropertyDelegateHolder {

private GrinderRecipe trackedRecipe;
private GrindingRecipe trackedRecipe;
private int progress;

public GrinderEntity() {
Expand All @@ -34,7 +32,7 @@ public GrinderEntity() {
public void tick() {
if(!world.isClient()) {
if(trackedRecipe == null) {
Optional<GrinderRecipe> recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world);
Optional<GrindingRecipe> recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world);
recipeOptional.ifPresent(recipe -> trackedRecipe = recipe);
tickRecipeProgression();
}
Expand All @@ -60,40 +58,9 @@ public void tick() {
private void tickRecipeProgression() {
if(trackedRecipe != null) {
if(progress >= getProcessTime()) {
ItemStack outSlot = inventory.get(1);
ItemStack secSlot = inventory.get(2);
List<ItemStack> outputs = trackedRecipe.getOutputs();
ItemStack output = outputs.get(0);
ItemStack secondary = outputs.get(1);
float chance = trackedRecipe.getChance();
if(outSlot.isEmpty()) {
inventory.get(0).decrement(1);
inventory.set(1, output.copy());
if(world.getRandom().nextFloat() <= chance) {
if(secSlot.isEmpty()) {
inventory.set(2, secondary.copy());
}
else if(secSlot.getCount() + secondary.getCount() <= secSlot.getMaxCount() && secondary.isItemEqual(secSlot)) {
inventory.get(2).increment(secondary.getCount());
}
}
progress = 0;
sync();
}
if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) {
inventory.get(0).decrement(1);
inventory.get(1).increment(output.getCount());
if(world.getRandom().nextFloat() <= chance) {
if(secSlot.isEmpty()) {
inventory.set(2, secondary.copy());
}
else if(secSlot.getCount() + secondary.getCount() <= secSlot.getMaxCount() && secondary.isItemEqual(secSlot)) {
inventory.get(2).increment(secondary.getCount());
}
}
progress = 0;
sync();
}
trackedRecipe.craft(this);
progress = 0;
sync();
}
else {
double drain = getPowerUsage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package azzy.fabric.lookingglass.blockentity;

import azzy.fabric.lookingglass.util.ModifierProvider;
import azzy.fabric.lookingglass.util.RecipeConversionProvider;
import azzy.fabric.lookingglass.util.machine.ModifierProvider;
import azzy.fabric.lookingglass.util.machine.RecipeConversionProvider;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package azzy.fabric.lookingglass.blockentity;

import azzy.fabric.lookingglass.block.LookingGlassBlocks;
import azzy.fabric.lookingglass.gui.AlloyingFurnaceGuiDescription;
import azzy.fabric.lookingglass.gui.MixerGuiDescription;
import azzy.fabric.lookingglass.recipe.AlloyingRecipe;
import azzy.fabric.lookingglass.recipe.LookingGlassRecipes;
import azzy.fabric.lookingglass.recipe.MixerRecipe;
import azzy.fabric.lookingglass.recipe.MixingRecipe;
import io.github.cottonmc.cotton.gui.PropertyDelegateHolder;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
Expand All @@ -22,7 +20,7 @@
@SuppressWarnings("unchecked")
public class MixerEntity extends LookingGlassUpgradeableMachine implements PropertyDelegateHolder {

private MixerRecipe trackedRecipe;
private MixingRecipe trackedRecipe;
private int progress;

public MixerEntity() {
Expand All @@ -33,7 +31,7 @@ public MixerEntity() {
public void tick() {
if(!world.isClient()) {
if(trackedRecipe == null) {
Optional<MixerRecipe> recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world);
Optional<MixingRecipe> recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world);
recipeOptional.ifPresent(recipe -> trackedRecipe = recipe);
tickRecipeProgression();
}
Expand All @@ -59,26 +57,9 @@ public void tick() {
private void tickRecipeProgression() {
if(trackedRecipe != null) {
if(progress >= getProcessTime()) {
ItemStack outSlot = inventory.get(4);
if(outSlot.isEmpty()) {
inventory.set(4, trackedRecipe.craft(this));
inventory.get(3).decrement(1);
inventory.get(2).decrement(1);
inventory.get(1).decrement(1);
inventory.get(0).decrement(1);
progress = 0;
sync();
}
ItemStack output = trackedRecipe.getOutput();
if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) {
inventory.get(4).increment(output.getCount());
inventory.get(3).decrement(1);
inventory.get(2).decrement(1);
inventory.get(1).decrement(1);
inventory.get(0).decrement(1);
progress = 0;
sync();
}
trackedRecipe.craft(this);
progress = 0;
sync();
}
else {
double drain = getPowerUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,24 @@ public void tick() {
private void tickRecipeProgression() {
if(trackedRecipe != null) {
if(progress >= getProcessTime()) {
ItemStack outSlot = inventory.get(1);
if(outSlot.isEmpty()) {
inventory.set(1, trackedRecipe.craft(this));
inventory.get(0).decrement(1);
progress = 0;
sync();
if(trackedRecipe.getType() == RecipeType.SMELTING || trackedRecipe.getType() == RecipeType.BLASTING) {
ItemStack outSlot = inventory.get(1);
if(outSlot.isEmpty()) {
inventory.set(1, trackedRecipe.craft(this));
inventory.get(0).decrement(1);
progress = 0;
sync();
}
ItemStack output = trackedRecipe.getOutput();
if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) {
inventory.get(1).increment(output.getCount());
inventory.get(0).decrement(1);
progress = 0;
sync();
}
}
ItemStack output = trackedRecipe.getOutput();
if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) {
inventory.get(1).increment(output.getCount());
inventory.get(0).decrement(1);
else {
trackedRecipe.craft(this);
progress = 0;
sync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public VacuumHopperEntity(BlockEntityType<?> type, int invSize, int delay, int r
@Override
public void tick() {
if(!world.isClient() && !getCachedState().get(LookingGlassBlock.POWERED) && (world.getTime() + offset) % delay == 0) {
List<ItemEntity> itemEntities = world.getEntitiesByType(EntityType.ITEM, new Box(pos.add(-radius, -radius, -radius), pos.add(radius, radius, radius)), ignored -> true);
List<ItemEntity> itemEntities = world.getEntitiesByType(EntityType.ITEM, new Box(pos.add(-radius, -radius, -radius), pos.add(radius + 1, radius + 1, radius + 1)), ignored -> true);
entityCheck:
for (ItemEntity itemEntity : itemEntities) {
ItemStack stack = itemEntity.getStack();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package azzy.fabric.lookingglass.gui;

import azzy.fabric.lookingglass.LookingGlassCommon;
import azzy.fabric.lookingglass.util.ModifierProvider;
import azzy.fabric.lookingglass.util.machine.ModifierProvider;
import azzy.fabric.lookingglass.util.client.BackgroundType;
import io.github.cottonmc.cotton.gui.SyncedGuiDescription;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.widget.WBar;
import io.github.cottonmc.cotton.gui.widget.WItemSlot;
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import azzy.fabric.lookingglass.blockentity.LookingGlassMachine;
import azzy.fabric.lookingglass.gui.UpgradeableMachineGuiDescription;
import azzy.fabric.lookingglass.util.ModifierProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import azzy.fabric.lookingglass.util.machine.ModifierProvider;
import net.minecraft.item.Item;

public class GenericUpgradeItem extends Item implements ModifierProvider {
Expand Down
Loading

0 comments on commit dbd259b

Please sign in to comment.