Skip to content

Commit

Permalink
Implemented JEI integration.
Browse files Browse the repository at this point in the history
Also, some code cleanup.
  • Loading branch information
gazotti committed Apr 14, 2021
1 parent 4ceb147 commit 5b3be5a
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="lib" path="CraftTweaker-1.16.3-[7.0.0.48]_mapped_snapshot_20201028-1.16.3.jar"/>
<classpathentry kind="lib" path="ZenScript-1.0.0.jar"/>
<classpathentry kind="lib" path="jei-1.16.5-7.6.1.75-api.jar" sourcepath="jei-1.16.5-7.6.1.75-sources.jar"/>
<classpathentry kind="lib" path="CraftTweaker-1.16.5-7.1.0.203-deobf.jar"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 19 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

//crafttweaker support
repositories {
//crafttweaker
maven { url 'https://maven.blamejared.com' }

//JEI
maven {
// location of the maven that hosts JEI files
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "https://modmaven.k-4u.nl"
}
}

dependencies {

//runtimeOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.16.3:[7.0.0.48]")
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.16.3:[7.0.0.48]")
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.16.5:[7.1.0.203]")
compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api")
// at runtime, use the full JEI jar
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")

}

Expand Down Expand Up @@ -152,9 +167,9 @@ jar {
attributes([
"Specification-Title": "borkler",
"Specification-Vendor": "gazcreations",
"Specification-Version": "0.2.1", // We are version 1 of ourselves
"Specification-Version": "0.2.2", // We are version 1 of ourselves
"Implementation-Title": "borkler",
"Implementation-Version": "0.2.1",
"Implementation-Version": "0.2.2",
"Implementation-Vendor" :"gazcreations",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/gazcreations/borkler/Borkler.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,15 @@ private void setup(final FMLCommonSetupEvent event) {
FluidTags.createOptional(steam, steamTypes);
}

/*
* @SubscribeEvent public void addReloadListener(final AddReloadListenerEvent
* event) { event.addListener(new ReloadListener<Void>() {
*
* @Override protected void apply(Void arg0, IResourceManager arg1, IProfiler
* arg2) { MinecraftServer server = null; if ((server =
* ServerLifecycleHooks.getCurrentServer()) != null) { for (ServerWorld w :
* server.getWorlds()) { BorklerTileEntity.addFutureServerTask(w, () ->
* BorklerPacketHandler.sendToAll(BorklerTileEntity.getValidFuelTypes()), true);
* } } }
*
* @Override protected Void prepare(IResourceManager arg0, IProfiler arg1) {
* return null; } }); }
*/

private void enqueueIMC(final InterModEnqueueEvent event) {
void enqueueIMC(final InterModEnqueueEvent event) {
// some example code to dispatch IMC to another mod
// InterModComms.sendTo("borkler", "helloworld", () -> {
// LOGGER.info("Hello world from the MDK");
// return "Hello world";});

}

private void processIMC(final InterModProcessEvent event) {
void processIMC(final InterModProcessEvent event) {
// some example code to receive and process InterModComms from other mods
// LOGGER.info("Got IMC {}",
// event.getIMCStream().map(m ->
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/gazcreations/borkler/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,13 @@ public static final class Items {
.create(BorklerTileEntity::new, Index.Blocks.BORKLERBLOCK).build(null)
.setRegistryName("borkler", "borklertile");

@SuppressWarnings("unchecked")
private static <T extends Container> ContainerType<T> register(String name, IContainerFactory<T> containerFactory) {
return (ContainerType<T>) new ContainerType<>(containerFactory).setRegistryName("borkler", name);
}

@ObjectHolder(value = "borkler:borklercontainer")
public static final ContainerType<?> BORKLER_CONTAINER_TYPE = register("borklercontainer",
/*
* new IContainerFactory<BorklerContainer>() {
*
* @Override public BorklerContainer create(int windowId, PlayerInventory inv,
* PacketBuffer data) { return new BorklerContainer(windowId, inv, data); } });
*/
((windowId, inv, data) -> {
return new BorklerContainer(windowId, inv, data);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void markDirty() {
* @return The burn time, in ticks, for a given solid fuel, corrected by
* {@link BorklerConfig#NERFACTOR}.
*/
private int nerfdBurnTime(ItemStack item) {
public static int nerfdBurnTime(ItemStack item) {
int defaultBT = ForgeHooks.getBurnTime(item);
return defaultBT > 0 ? Math.toIntExact(Math.round(Math.floor(defaultBT * BorklerConfig.CONFIG.NERFACTOR.get())))
: -1;
Expand Down Expand Up @@ -509,7 +509,7 @@ public byte getTankForFluid(Fluid fluid) {
* @param stack
* @return true if this ItemStack has the FluidHandler Capability.
*/
private boolean isActuallyALiquid(ItemStack stack) {
boolean isActuallyALiquid(ItemStack stack) {
return stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).isPresent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
@OnlyIn(Dist.CLIENT)
public class BorklerScreen extends ContainerScreen<BorklerContainer> implements IHasContainer<BorklerContainer> {

private static final ResourceLocation guiTexture = new ResourceLocation("borkler", "textures/gui/steam_boiler.png");
private static final ResourceLocation overlayTexture = new ResourceLocation("borkler",
public static final ResourceLocation guiTexture = new ResourceLocation("borkler", "textures/gui/steam_boiler.png");
public static final ResourceLocation overlayTexture = new ResourceLocation("borkler",
"textures/gui/boiler_overlay.png");
// private List<Pair<FluidStack, Integer>> fluids;
private TankSimulator[] tanks;
private BorklerTileEntity ent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with Borkler. If not, see <https://www.gnu.org/licenses/>.
*/
package gazcreations.borkler.compat;
package gazcreations.borkler.compat.crafttweaker;

import com.blamejared.crafttweaker.api.managers.IRecipeManager;
import com.blamejared.crafttweaker.impl.actions.recipes.ActionAddRecipe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with Borkler. If not, see <https://www.gnu.org/licenses/>.
*/

package gazcreations.borkler.compat;
package gazcreations.borkler.compat.crafttweaker;

import org.openzen.zencode.java.ZenCodeType;

Expand Down Expand Up @@ -53,9 +53,8 @@ public final IRecipeType<BorklerFuel> getRecipeType() {
@ZenCodeType.Method
public final void addFuel(String recipeName, IFluidStack fluid, int burnTime) {
ResourceLocation reciPath = new ResourceLocation("crafttweaker", fixRecipeName(recipeName));
final BorklerFuel fuel = new BorklerFuel(fluid.getFluid().getInternal(), burnTime, reciPath);
final BorklerFuel fuel = new BorklerFuel(fluid.getFluid(), burnTime, reciPath);
CraftTweakerAPI.apply(new ActionAddFluidRecipe(this, fuel));
// BorklerTileEntity.addFuel(fluid.getFluid().getInternal(), burnTime);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* Copyright 2021, B. Gazotti
*
* This file is part of Borkler.
*
* Borkler is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Borkler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Borkler. If not, see <https://www.gnu.org/licenses/>.
*/
package gazcreations.borkler.compat.jei;

import java.util.ArrayList;

import com.mojang.blaze3d.matrix.MatrixStack;

import gazcreations.borkler.BorklerConfig;
import gazcreations.borkler.Index;
import gazcreations.borkler.client.screen.BorklerScreen;
import gazcreations.borkler.recipes.BorklerFuel;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.client.Minecraft;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;

/**
* A class representing the JEI category for a fluid Borkler fuel.
*
* @author gazotti
*
*/
class BorklerFluidFuelCategory extends BorklerFuelCategory<BorklerFuel> {

static final ResourceLocation UID = new ResourceLocation("borkler", "jei_borkler_fluid_fuel");

final int waterCap = BorklerConfig.CONFIG.WATER_USE.get();
final int steamCap = (int) (waterCap * BorklerConfig.CONFIG.CONVERSION_RATE.get());

public BorklerFluidFuelCategory(IGuiHelper guiHelper) {
super(guiHelper);
}

/**
* Returns a {@link java.util.List} of 2 @link FluidStack}s: the first is water,
* the second is the provided fuel. <br>
* For JEI prettiness purposes.
*/
private java.util.List<FluidStack> plusWater(FluidStack fuel) {
ArrayList<FluidStack> list = new ArrayList<>(3);
list.add(new FluidStack(Fluids.WATER, waterCap));
list.add(fuel);
return list;
}

@Override
public ResourceLocation getUid() {
return UID;
}

@Override
public Class<? extends BorklerFuel> getRecipeClass() {
return BorklerFuel.class;
}

@Override
public void setIngredients(BorklerFuel recipe, IIngredients ingredients) {
ingredients.setInputs(VanillaTypes.FLUID, plusWater(recipe.getFluid()));
ingredients.setOutput(VanillaTypes.FLUID, new FluidStack(Index.Fluids.STEAMSOURCE, steamCap));
}

@Override
public void setRecipe(IRecipeLayout layout, BorklerFuel recipe, IIngredients ingredients) {
// TODO minor cosmetic fix if I come around to it
waterTank = guiHelper.createDrawable(BorklerScreen.overlayTexture, 0, 49, 16, 48);
layout.getFluidStacks().init(0, true, 83, 7, 17, 48, waterCap, false, waterTank);
layout.getFluidStacks().set(0, new FluidStack(Fluids.WATER, waterCap));
fuelTank = guiHelper.createDrawable(BorklerScreen.overlayTexture, 0, 49, 16, 48);
layout.getFluidStacks().init(1, true, 115, 7, 17, 48, 4, false, fuelTank);
layout.getFluidStacks().set(1, recipe.getFluid());
steamTank = guiHelper.createDrawable(BorklerScreen.overlayTexture, 0, 0, 16, 49);
layout.getFluidStacks().init(2, false, 148, 7, 17, 48, steamCap, false, steamTank);
layout.getFluidStacks().set(2, new FluidStack(Index.Fluids.STEAMSOURCE, steamCap));
}

@SuppressWarnings("resource")
@Override
public void draw(BorklerFuel recipe, MatrixStack stack, double mouseX, double mouseY) {
Minecraft.getInstance().fontRenderer.drawString(stack, recipe.getBurnTime() + " ticks", 5, 5, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright 2021, B. Gazotti
*
* This file is part of Borkler.
*
* Borkler is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Borkler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Borkler. If not, see <https://www.gnu.org/licenses/>.
*/
package gazcreations.borkler.compat.jei;

import gazcreations.borkler.BorklerConfig;
import gazcreations.borkler.Index;
import gazcreations.borkler.client.screen.BorklerScreen;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;

/**
* An abstract Borkler Fuel category for JEI.
*
* @author gazotti
*
*/
public abstract class BorklerFuelCategory<T> implements IRecipeCategory<T> {

protected final IGuiHelper guiHelper;
protected static final ResourceLocation BG = new ResourceLocation("borkler", "textures/gui/steam_boiler_jei.png");
protected IDrawable waterTank;
protected IDrawable fuelTank;
protected IDrawable steamTank;
protected IDrawable text;

public BorklerFuelCategory(IGuiHelper guiHelper) {
this.guiHelper = guiHelper;
}

@Override
public String getTitle() {
return I18n.format("container.borkler.steam_boiler");
}

@Override
public IDrawable getBackground() {
return guiHelper.createDrawable(BG, 0, 0, 175, 62); // also the bounds for our GUI
}

@Override
public IDrawable getIcon() {
return guiHelper.createDrawableIngredient(new ItemStack(() -> Index.Items.BORKLERITEM, 1));
}

@Override
public void setRecipe(IRecipeLayout layout, T recipe, IIngredients ingredients) {
int waterCap = BorklerConfig.CONFIG.WATER_USE.get();
int steamCap = (int) (waterCap * BorklerConfig.CONFIG.CONVERSION_RATE.get());
waterTank = guiHelper.createDrawable(BorklerScreen.overlayTexture, 0, 49, 16, 48);
layout.getFluidStacks().init(0, true, 83, 7, 17, 48, waterCap, false, waterTank);
layout.getFluidStacks().set(0, new FluidStack(Fluids.WATER, waterCap));
steamTank = guiHelper.createDrawable(BorklerScreen.overlayTexture, 0, 0, 16, 49);
layout.getFluidStacks().init(2, false, 148, 7, 17, 48, steamCap, false, steamTank);
layout.getFluidStacks().set(2, new FluidStack(Index.Fluids.STEAMSOURCE, steamCap));
}
}
Loading

0 comments on commit 5b3be5a

Please sign in to comment.