Skip to content

Commit

Permalink
Merge pull request #2404 from PocketSizedWeeb/trunk/1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar authored Jul 28, 2024
2 parents 3abc378 + 1ca0c86 commit 02cfd51
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 46 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/lothrazar/cyclic/block/PeatBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraftforge.common.ForgeConfigSpec.DoubleValue;

public class PeatBlock extends BlockCyclic {
Expand All @@ -32,8 +32,9 @@ public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random
List<BlockPos> waters = new ArrayList<>();
for (BlockPos p : around) {
//try to bake if SOURCE water is nearby
Block bSide = world.getBlockState(p).getBlock();
if (bSide == Blocks.WATER) {
//using FluidState instead of Block
FluidState fluid = world.getFluidState(p);
if (fluid.getType() == Fluids.WATER.getSource()) {
sidesWet++;
waters.add(p);
}
Expand Down
41 changes: 36 additions & 5 deletions src/main/java/com/lothrazar/cyclic/block/crafter/TileCrafter.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ public void serverTick() {
if (timer < 0) {
timer = 0;
}
//timer phase
if (--timer > 0) {
return;
}
//timer is out, therefore processing
Recipe<CraftingContainer> lastValidRecipe = findMatchingRecipe(null);
if (lastValidRecipe == null) {
//reset
Expand All @@ -160,6 +155,13 @@ public void serverTick() {
setPreviewSlot(recipeOutput);
//if we have space for the output, then go ahead
if (hasFreeSpace(outHandler, recipeOutput)) {
if(!checkInput(inputHandler)) { //Checks input before processing
this.timer = TIMER_FULL;
return;
}
if (--timer > 0) { //Get recipe before processing
return;
}
if (doCraft(lastValidRecipe)) {
//reset the timer
this.timer = TIMER_FULL;
Expand Down Expand Up @@ -211,6 +213,35 @@ private boolean hasFreeSpace(IItemHandler inv, ItemStack output) {
return test.isEmpty(); //empty means all of it was allowed to go in
}

// This could be done better, but it works so ¯\_(ツ)_/¯
private boolean checkInput(IItemHandler inv) {
IItemHandler gridHandler = this.gridCap.orElse(null);
List<ItemStack> inputStacks = new ArrayList<ItemStack>();
List<ItemStack> gridStacks = new ArrayList<ItemStack>();
for(int i = 0; i < inv.getSlots(); i++) {
inputStacks.add(inv.getStackInSlot(i).copy());
}
for(int i = 0; i < gridHandler.getSlots(); i++) {
gridStacks.add(gridHandler.getStackInSlot(i).copy());
}
for(ItemStack stack : inputStacks) {
List<ItemStack> lolbit = new ArrayList<ItemStack>();
boolean match = false;
for(ItemStack grid : gridStacks) {
if(stack.getItem() == grid.getItem()) {
match = true;
lolbit.add(grid);
stack.shrink(1);
}
}
if(match) {
gridStacks.removeAll(lolbit);
}
}
if(gridStacks.isEmpty()) return true;
return false;
}

//TODO:? re-write this whole thing using ASSEMBLE?
//big change
// for (int i = 0; i < 9; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.items.SlotItemHandler;

Expand All @@ -28,13 +29,23 @@ public void setChanged() {
});
addSlot(new SlotItemHandler(tile.outputSlots, 0, 105 + 4, 21 + 4) {

@Override
public boolean mayPlace(ItemStack stack) {
return false;
}

@Override
public void setChanged() {
tile.setChanged();
}
});
addSlot(new SlotItemHandler(tile.outputSlots, 1, 109, 55) {

@Override
public boolean mayPlace(ItemStack stack) {
return false;
}

@Override
public void setChanged() {
tile.setChanged();
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/lothrazar/cyclic/block/crusher/TileCrusher.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public TileCrusher(BlockPos pos, BlockState state) {
this.needsRedstone = 0;
}

public static void clientTick(Level level, BlockPos blockPos, BlockState blockState, TileCrusher tileAnvilAuto) {
tileAnvilAuto.tick();
public static void clientTick(Level level, BlockPos blockPos, BlockState blockState, TileCrusher e) {
e.tick();
}

public static <E extends BlockEntity> void serverTick(Level level, BlockPos blockPos, BlockState blockState, TileCrusher e) {
Expand Down Expand Up @@ -111,6 +111,14 @@ public void tick() {
if (level.isClientSide) {
return;
}
if (currentRecipe == null) {
this.findMatchingRecipe();
return;
}
//Checks if there is space in the output slots before processing
if(outputSlots.getStackInSlot(0).getCount() > 64 - currentRecipe.getResultItem(level.registryAccess()).copy().getCount()) return;
if(outputSlots.getStackInSlot(1).getCount() > 64 - currentRecipe.randOutput.bonus.getCount()) return;

if (this.burnTime <= 0 && this.currentRecipe != null) {
this.burnTimeMax = 0;
this.burnTime = 0;
Expand All @@ -133,10 +141,6 @@ public void tick() {
if (this.burnTime <= 0 && this.burnTimeMax == 0) {
this.findMatchingRecipe();
}
if (currentRecipe == null) {
this.findMatchingRecipe();
return;
}
if (this.burnTimeMax > 0) {
setLitProperty(true); // has recipe so lit
int onSim = energy.extractEnergy(currentRecipe.energy.getRfPertick(), true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lothrazar.cyclic.block.generatorfluid;

import java.util.List;

import com.google.gson.JsonObject;
import com.lothrazar.cyclic.ModCyclic;
import com.lothrazar.cyclic.registry.CyclicRecipeType;
Expand All @@ -10,13 +12,16 @@
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistries;

public class RecipeGeneratorFluid implements Recipe<TileGeneratorFluid> {

Expand Down Expand Up @@ -61,6 +66,12 @@ public FluidStack getRecipeFluid() {
return fluidIng.getFluidStack();
}

public List<Fluid> getFluidsFromTag() {
TagKey<Fluid> tag = ForgeRegistries.FLUIDS.tags().createTagKey(new ResourceLocation(this.fluidIng.getTag()));
List<Fluid> list = ForgeRegistries.FLUIDS.tags().getTag(tag).stream().toList();
return list;
}

@Override
public boolean matches(TileGeneratorFluid inv, Level worldIn) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void render(GuiGraphics gg, int mouseX, int mouseY, float partialTicks) {
this.renderTooltip(gg, mouseX, mouseY);
energy.renderHoveredToolTip(gg, mouseX, mouseY, menu.tile.getEnergy());
progress.renderHoveredToolTip(gg, mouseX, mouseY, menu.tile.getField(TileGeneratorFluid.Fields.TIMER.ordinal()));
fluid.renderHoveredToolTip(gg, mouseX, mouseY, menu.tile.getFluid());
//fluid.renderHoveredToolTip(gg, mouseX, mouseY, menu.tile.getFluid());
btnRedstone.onValueUpdate(menu.tile);
var pose = gg.pose();
pose.pushPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private ArrayList<Fluid> indexFluidsFromRecipes() {
ArrayList<Fluid> fluids = new ArrayList<>();
for (RecipeGeneratorFluid recipe : recipes) {
fluids.add(recipe.getRecipeFluid().getFluid());
fluids.addAll(recipe.getFluidsFromTag());
}
return fluids;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void tick() {
if (currentRecipe == null) {
return;
}
//Fixes sync issue entirely
if(level.isClientSide()) return;
this.timer--;
if (timer < 0) {
timer = 0;
Expand Down Expand Up @@ -230,7 +232,7 @@ private boolean tryProcessRecipe() {
//ok it has room for all the fluid none will be wasted
inventory.getStackInSlot(0).shrink(1);
inventory.getStackInSlot(1).shrink(1);
if (!level.isClientSide()) tank.fill(this.currentRecipe.getRecipeFluid(), FluidAction.EXECUTE);
tank.fill(this.currentRecipe.getRecipeFluid(), FluidAction.EXECUTE);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public void tick() {
this.timer = 0;
return;
}
//Fixes sync issue entirely
if(level.isClientSide()) return;
//Checks if there is space in the output slot
if(this.outputSlots.getStackInSlot(0).getCount() > 64 - currentRecipe.getResultItem(level.registryAccess()).getCount()) return;
final int energyCost = this.currentRecipe.getEnergy().getRfPertick();
final int fluidCost = this.currentRecipe.getRecipeFluid().getAmount();
if ((energy.getEnergyStored() < energyCost && energyCost > 0)
Expand Down Expand Up @@ -220,9 +224,9 @@ private boolean tryProcessRecipe() {
inputSlots.getStackInSlot(0).shrink(1);
inputSlots.getStackInSlot(1).shrink(1);
inputSlots.getStackInSlot(2).shrink(1);
if (!level.isClientSide()) { // only drain serverside to avoid desync issues
// if (!level.isClientSide()) { // only drain serverside to avoid desync issues # not needed anymore with above fix
tank.drain(this.currentRecipe.fluidIngredient.getAmount(), FluidAction.EXECUTE);
}
// }
outputSlots.insertItem(0, currentRecipe.getResultItem(level.registryAccess()), false);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.lothrazar.cyclic.registry.TileRegistry;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.core.BlockPos;
import net.minecraft.world.Containers;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -44,4 +45,18 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, Block
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(POWERED);
}

@Override // was onReplaced
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
TileWirelessTransmit tileentity = (TileWirelessTransmit) worldIn.getBlockEntity(pos);
if (tileentity != null) {
for (int i = 0; i < tileentity.inventory.getSlots(); ++i) {
// was InventoryHelper.spawnItemStack
Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), tileentity.inventory.getStackInSlot(i));
}
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.lothrazar.cyclic.ModCyclic;
import com.lothrazar.cyclic.block.crusher.RecipeCrusher;
import com.lothrazar.cyclic.block.solidifier.TileSolidifier;
import com.lothrazar.cyclic.registry.BlockRegistry;
import com.lothrazar.cyclic.registry.TextureRegistry;
import com.lothrazar.library.gui.EnergyBar;
import com.lothrazar.library.gui.TexturedProgress;
import com.lothrazar.library.util.ChatUtil;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand All @@ -14,6 +18,7 @@
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -26,10 +31,17 @@ public class CrusherRecipeCategory implements IRecipeCategory<RecipeCrusher> {
static final RecipeType<RecipeCrusher> TYPE = new RecipeType<>(ID, RecipeCrusher.class);
private IDrawable gui;
private IDrawable icon;
private Font font;
private EnergyBar bar;

public CrusherRecipeCategory(IGuiHelper helper) {
font = Minecraft.getInstance().font;
gui = helper.drawableBuilder(new ResourceLocation(ModCyclic.MODID, "textures/jei/crusher.png"), 0, 0, 155, 49).setTextureSize(155, 49).build();
icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(BlockRegistry.CRUSHER.get()));
bar = new EnergyBar(font, TileSolidifier.MAX);
bar.setHeight(48);
bar.guiLeft = -16;
bar.guiTop = -8;
}

@Override
Expand All @@ -55,7 +67,6 @@ public RecipeType<RecipeCrusher> getRecipeType() {
@Override
public void draw(RecipeCrusher recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics ms, double mouseX, double mouseY) {
int x = 78;
var font = Minecraft.getInstance().font;
if (recipe.energy.getTicks() < 40) {
ms.drawString(font, recipe.energy.getTicks() + " t", x, 6, FONT);
}
Expand All @@ -64,10 +75,11 @@ public void draw(RecipeCrusher recipe, IRecipeSlotsView recipeSlotsView, GuiGrap
ms.drawString(font, sec + " s", x, 6, FONT);
}
ms.drawString(font, recipe.energy.getRfPertick() + " RF/t", x, 16, FONT);
ms.drawString(font, recipe.energy.getEnergyTotal() + " RF", x, 26, FONT);
if (!recipe.randOutput.bonus.isEmpty() && recipe.randOutput.percent > 0) {
ms.drawString(font, recipe.randOutput.percent + "%", 56, 36, FONT);
}
bar.draw(ms, recipe.energy.getEnergyTotal());
bar.renderHoveredToolTip(ms, (int) mouseX, (int) mouseY, recipe.energy.getEnergyTotal());
}

@Override
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/lothrazar/cyclic/compat/jei/CyclicPluginJEI.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,23 @@ public void registerRecipes(IRecipeRegistration registry) {
@Override
public void registerGuiHandlers(IGuiHandlerRegistration registry) {
registry.addRecipeClickArea(ScreenMelter.class,
75, 20,
40, 26, MelterRecipeCategory.TYPE);
68, 37,
24, 17, MelterRecipeCategory.TYPE);
registry.addRecipeClickArea(ScreenSolidifier.class,
75, 20,
40, 26, SolidifierRecipeCategory.TYPE);
68, 37,
24, 17, SolidifierRecipeCategory.TYPE);
registry.addRecipeClickArea(ScreenGeneratorDrops.class,
10, 10,
40, 66, GenitemRecipeCategory.TYPE);
38, 6,
100, 10, GenitemRecipeCategory.TYPE);
registry.addRecipeClickArea(ScreenGeneratorFluid.class,
50, 8,
20, 20, GenfluidRecipeCategory.TYPE);
28, 6,
120, 10, GenfluidRecipeCategory.TYPE);
registry.addRecipeClickArea(ScreenPackager.class,
60, 0,
60, 30, PackagerRecipeCategory.TYPE);
60, 4,
52, 12, PackagerRecipeCategory.TYPE);
registry.addRecipeClickArea(ScreenCrusher.class,
50, 0,
40, 30, CrusherRecipeCategory.TYPE);
76, 38,
20, 20, CrusherRecipeCategory.TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public void draw(RecipeGeneratorFluid recipe, IRecipeSlotsView recipeSlotsView,
ms.drawString(font, recipe.getTicks() + " t", 60, 0, FONT);
ms.drawString(font, recipe.getRfpertick() + " RF/t", 60, 10, FONT);
ms.drawString(font, recipe.getRfTotal() + " RF", 60, 20, FONT);
//ms.drawString(font, recipe.fluidIng.getAmount() + " mB", 60, 30, FONT);
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, RecipeGeneratorFluid recipe, IFocusGroup focuses) {
List<FluidStack> matchingFluids = recipe.fluidIng.getMatchingFluids();
builder.addSlot(RecipeIngredientRole.INPUT, 6, 7).addIngredients(ForgeTypes.FLUID_STACK, matchingFluids);
builder.addSlot(RecipeIngredientRole.INPUT, 6, 7).addIngredients(ForgeTypes.FLUID_STACK, matchingFluids).setFluidRenderer(4000, false, 16, 16);
}
//keep old code for reference
//
Expand Down
Loading

0 comments on commit 02cfd51

Please sign in to comment.