Skip to content

Commit

Permalink
Updated codebase to fabric 0.91.6+1.20.2
Browse files Browse the repository at this point in the history
- refactored Alloy Smelter and Alloy Smelter Recipes
- removed un-used classes and their references
- changes reflect additions/deprecations/changes introduced in fabric 0.91.6+1.20.2
  • Loading branch information
Sephta committed Jun 21, 2024
1 parent 713f35f commit 64cd17e
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 242 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'

}
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.15.11

# Mod Properties
Expand All @@ -15,4 +15,4 @@ archives_base_name=stal-alloys
modid=stal-alloys

# Dependencies
fabric_version=0.92.2+1.20.1
fabric_version=0.91.6+1.20.2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 0 additions & 3 deletions src/main/java/net/stal/alloys/StalAlloys.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.stal.alloys.item.StalAlloysItemGroup;
// import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.stal.alloys.item.StalAlloysItems;
import net.stal.alloys.networking.StalAlloysMessages;
import net.stal.alloys.recipe.StalAlloysRecipes;
import net.stal.alloys.screen.StalAlloysScreenHandlers;
import net.stal.alloys.world.StalAlloysConfiguredFeatures;
Expand Down Expand Up @@ -43,8 +42,6 @@ public void onInitialize() {

StalAlloysRecipes.registerRecipes();

StalAlloysMessages.registerC2SPackets();

// Other stuff...

// ServerTickEvents.START_SERVER_TICK.register(new PlayerTickHandler());
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/net/stal/alloys/StalAlloysClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.stal.alloys.event.KeyInputHandler;
import net.stal.alloys.networking.StalAlloysMessages;
import net.stal.alloys.screen.AlloySmelterScreen;
import net.stal.alloys.screen.StalAlloysScreenHandlers;

Expand All @@ -12,9 +10,6 @@ public class StalAlloysClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
HandledScreens.register(StalAlloysScreenHandlers.ALLOY_SMELTER_SCREEN_HANDLER, AlloySmelterScreen::new);

KeyInputHandler.registerKeyBindings();
StalAlloysMessages.registerS2CPackets();
}

}
2 changes: 1 addition & 1 deletion src/main/java/net/stal/alloys/block/AlloySmelterBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
BlockEntityType<T> type) {
return checkType(type, StalAlloysBlockEntities.ALLOY_SMELTER_ENTITY, AlloySmelterEntity::tick);
return BlockWithEntity.validateTicker(type, StalAlloysBlockEntities.ALLOY_SMELTER_ENTITY, AlloySmelterEntity::tick);
}
}
48 changes: 27 additions & 21 deletions src/main/java/net/stal/alloys/block/entity/AlloySmelterEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.PropertyDelegate;
import net.minecraft.screen.ScreenHandler;
Expand Down Expand Up @@ -151,12 +151,12 @@ public void readNbt(NbtCompound nbt) {
}
}

public void setLastRecipe(@Nullable Recipe<?> recipe) {
public void setLastRecipe(@Nullable RecipeEntry<AlloySmelterRecipe> recipe) {
if (recipe != null) {
Identifier identifier = recipe.getId();
Identifier identifier = recipe.id();
this.recipesUsed.addTo(identifier, 1);
}
}
}

public static <E extends BlockEntity> void tick(World world, BlockPos blockPos, BlockState blockState, AlloySmelterEntity entity) {
if (world.isClient()) return;
Expand Down Expand Up @@ -211,17 +211,20 @@ private static boolean hasRecipe(AlloySmelterEntity entity) {
inventory.setStack(i, entity.getStack(i));
}

Optional<AlloySmelterRecipe> recipeFromInventory = entity.getWorld()
Optional<RecipeEntry<AlloySmelterRecipe>> recipeFromInventoryOpt = entity.getWorld()
.getRecipeManager()
.getFirstMatch(AlloySmelterRecipe.Type.INSTANCE, inventory, entity.getWorld());

if (recipeFromInventory.isPresent()) {
entity.mMaxProgress = recipeFromInventory.get().getCookingTime();
}
if (recipeFromInventoryOpt.isPresent()) {
AlloySmelterRecipe recipe = recipeFromInventoryOpt.get().value();

entity.mMaxProgress = recipe.getCookingTime();

return recipeFromInventory.isPresent() &&
canInsertAmountIntoOutputSlot(inventory) &&
canInsertItemIntoOutputSlot(inventory, recipeFromInventory.get().getOutput(null).getItem());
return canInsertAmountIntoOutputSlot(inventory) &&
canInsertItemIntoOutputSlot(inventory, recipe.getResult(null).getItem());
}

return false;
}

private static void craftItem(AlloySmelterEntity entity) {
Expand All @@ -231,23 +234,25 @@ private static void craftItem(AlloySmelterEntity entity) {
inventory.setStack(i, entity.getStack(i));
}

Optional<AlloySmelterRecipe> recipeFromInventory = entity.getWorld()
Optional<RecipeEntry<AlloySmelterRecipe>> recipeFromInventoryOpt = entity.getWorld()
.getRecipeManager()
.getFirstMatch(AlloySmelterRecipe.Type.INSTANCE, inventory, entity.getWorld());

if (hasRecipe(entity)) {
if (recipeFromInventoryOpt.isPresent() && hasRecipe(entity)) {
AlloySmelterRecipe recipe = recipeFromInventoryOpt.get().value();

entity.removeStack(AlloySmelterInventorySlots.FIRST.value, 1);
entity.removeStack(AlloySmelterInventorySlots.SECOND.value, 1);

entity.setStack(
AlloySmelterInventorySlots.THIRD.value,
new ItemStack(
recipeFromInventory.get().getOutput(null).getItem(),
recipe.getResult(null).getItem(),
entity.getStack(AlloySmelterInventorySlots.THIRD.value).getCount() + 1
)
);

entity.setLastRecipe(recipeFromInventory.get());
entity.setLastRecipe(recipeFromInventoryOpt.get());

entity.resetProgress();
}
Expand All @@ -264,17 +269,18 @@ private static boolean canInsertAmountIntoOutputSlot(SimpleInventory inventory)
}

public void dropExperienceForRecipesUsed(ServerPlayerEntity player) {
List<Recipe<?>> list = this.getRecipesUsedAndDropExperience(player.getServerWorld(), player.getPos());
player.unlockRecipes(list);
List<RecipeEntry<?>> recipes = this.getRecipesUsedAndDropExperience(player.getServerWorld(), player.getPos());
player.unlockRecipes(recipes);
this.recipesUsed.clear();
}

public List<Recipe<?>> getRecipesUsedAndDropExperience(ServerWorld world, Vec3d pos) {
ArrayList<Recipe<?>> list = Lists.newArrayList();
@SuppressWarnings("unchecked")
public List<RecipeEntry<?>> getRecipesUsedAndDropExperience(ServerWorld world, Vec3d pos) {
ArrayList<RecipeEntry<?>> list = Lists.newArrayList();
for (Object2IntMap.Entry<Identifier> entry : this.recipesUsed.object2IntEntrySet()) {
world.getRecipeManager().get((Identifier)entry.getKey()).ifPresent(recipe -> {
list.add((Recipe<?>)recipe);
AlloySmelterEntity.dropExperience(world, pos, entry.getIntValue(), ((AlloySmelterRecipe)recipe).getExperience());
list.add((RecipeEntry<?>)recipe);
AlloySmelterEntity.dropExperience(world, pos, entry.getIntValue(), ((RecipeEntry<AlloySmelterRecipe>)recipe).value().getExperience());
});
}
return list;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package net.stal.alloys.datagen;

import java.util.List;
import java.util.function.Consumer;

import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.ItemConvertible;
Expand All @@ -28,7 +27,7 @@ public StalAlloysRecipeProvider(FabricDataOutput output) {
}

@Override
public void generate(Consumer<RecipeJsonProvider> exporter) {
public void generate(RecipeExporter exporter) {
// Smelting recipes
offerSmelting(exporter, CHROMIUM_SMELTABLES, RecipeCategory.MISC, StalAlloysItems.CHROMIUM_INGOT, 1.0F, 360, "chromium_ingot");
offerSmelting(exporter, NICKEL_SMELTABLES, RecipeCategory.MISC, StalAlloysItems.NICKEL_INGOT, 1.0F, 200, "nickel_ingot");
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/net/stal/alloys/event/KeyInputHandler.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/java/net/stal/alloys/networking/StalAlloysMessages.java

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 64cd17e

Please sign in to comment.