Skip to content

Commit

Permalink
Merge pull request #296 from CannoliCatfish/dev
Browse files Browse the repository at this point in the history
Fixed element indexer and removed foraging recipes
  • Loading branch information
CannoliCatfish authored Jun 22, 2022
2 parents 93517a2 + 0338393 commit 0f3ac4d
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static void clientSetupEvent(FMLClientSetupEvent event)
}

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void registerEntityRenderers(EntityRenderersEvent.RegisterRenderers event)
{
event.registerEntityRenderer(RankineEntityTypes.ALLOY_SPEAR.get(), SpearEntityRenderer.instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.cannolicatfish.rankine.ProjectRankine;
import com.cannolicatfish.rankine.recipe.ElementRecipe;
import com.cannolicatfish.rankine.util.PeriodicTableUtils;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.Util;
Expand Down Expand Up @@ -103,16 +105,17 @@ protected void renderLabels(PoseStack matrixStack, int x, int y) {
}

public void drawScaledString(PoseStack stack, Font fontRendererIn, String text, int x, int y, float size, int color) {
GL11.glScalef(size,size,size);
stack.scale(size,size,size);
float mSize = (float)Math.pow(size,-1);
drawString(stack, fontRendererIn,text,Math.round(x / size),Math.round(y / size),color);
GL11.glScalef(mSize,mSize,mSize);
stack.scale(mSize,mSize,mSize);
}

@Override
protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) {
GlStateManager._clearColor(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bindForSetup(this.GUI);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, this.GUI);
int i = this.leftPos;
int j = this.topPos;
this.blit(matrixStack, i, j, 0, 0, this.imageWidth, this.imageHeight);
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/com/cannolicatfish/rankine/recipe/ForagingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ public class ForagingRecipe implements Recipe<Container> {
private final NonNullList<Ingredient> recipeOutputs;
private final NonNullList<Float> weights;
private final NonNullList<Boolean> enchantments;
private final boolean allBiomes;

public ForagingRecipe(ResourceLocation id, List<String> biomes, Ingredient ingredientIn, NonNullList<Ingredient> recipeOutputsIn, NonNullList<Float> weights, NonNullList<Boolean> enchantments) {
public ForagingRecipe(ResourceLocation id, List<String> biomes, Ingredient ingredientIn, NonNullList<Ingredient> recipeOutputsIn, NonNullList<Float> weights, NonNullList<Boolean> enchantments, boolean allBiomes) {
this.id = id;
this.biomes = biomes;
this.ingredient = ingredientIn;
this.recipeOutputs = recipeOutputsIn;
this.weights = weights;
this.enchantments = enchantments;
this.allBiomes = allBiomes;
}

@Override
Expand Down Expand Up @@ -107,7 +109,7 @@ public static List<ForagingRecipe> getValidRecipes(Level levelIn, ResourceLocati
if (levelIn != null) {
List<ForagingRecipe> recipes = new ArrayList<>();
for (ForagingRecipe recipe : levelIn.getRecipeManager().getAllRecipesFor(RankineRecipeTypes.FORAGING)) {
if (recipe.getBiomes().contains(biomeName.toString()) && recipe.getIngredient().test(new ItemStack(state.getBlock().asItem()))) {
if ((recipe.allBiomes || recipe.getBiomes().contains(biomeName.toString())) && recipe.getIngredient().test(new ItemStack(state.getBlock().asItem()))) {
recipes.add(recipe);
}
}
Expand Down Expand Up @@ -162,12 +164,9 @@ public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> i
public ForagingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
JsonElement biomesArray = json.has("biomes") ? json.get("biomes") : null;
List<String> biomes = new ArrayList<>();

if (biomesArray == null) {
for (Biome b : ForgeRegistries.BIOMES.getValues()) {
biomes.add(b.getRegistryName().toString());
}
} else if (biomesArray.isJsonObject()) {
boolean allBiomes = true;
if (biomesArray != null && biomesArray.isJsonObject()) {
allBiomes = false;
JsonObject object = biomesArray.getAsJsonObject();
if (object.has("biome")){
biomes.add(object.get("biome").getAsString());
Expand Down Expand Up @@ -207,17 +206,22 @@ public ForagingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
i++;
}

return new ForagingRecipe(recipeId,biomes,ingredient,stacks,weights,enchantements);
return new ForagingRecipe(recipeId,biomes,ingredient,stacks,weights,enchantements,allBiomes);
}

@Nullable
@Override
public ForagingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
int biomesSize = buffer.readInt();
List<String> biomes = new ArrayList<>();
for (int i = 0; i < biomesSize; i++) {
biomes.set(i,buffer.readUtf());
boolean allBiomes = true;
if (biomesSize > 0) {
allBiomes = false;
for (int i = 0; i < biomesSize; i++) {
biomes.set(i,buffer.readUtf());
}
}

Ingredient input = Ingredient.fromNetwork(buffer);

int t = buffer.readVarInt();
Expand All @@ -231,15 +235,18 @@ public ForagingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buf
enchantements.set(i,buffer.readBoolean());
}

return new ForagingRecipe(recipeId, biomes, input, stacks, weights, enchantements);
return new ForagingRecipe(recipeId, biomes, input, stacks, weights, enchantements, allBiomes);
}

@Override
public void toNetwork(FriendlyByteBuf buffer, ForagingRecipe recipe) {
buffer.writeInt(recipe.getBiomes().size());
for (int i = 0; i < recipe.getBiomes().size(); i++) {
buffer.writeUtf(recipe.getBiomes().get(i));
if (recipe.getBiomes().size() > 0) {
for (int i = 0; i < recipe.getBiomes().size(); i++) {
buffer.writeUtf(recipe.getBiomes().get(i));
}
}

recipe.getIngredient().toNetwork(buffer);

buffer.writeVarInt(recipe.getOutputs().size());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ issueTrackerURL="http://my.issue.tracker/" #optional
# The modid of the mod
modId="rankine" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="1.3.1" #mandatory
version="1.3.3" #mandatory
# A display name for the mod
displayName="Project Rankine" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0f3ac4d

Please sign in to comment.