Skip to content

Commit

Permalink
wip: Continue port to Minecraft 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Nov 1, 2024
1 parent 6075296 commit 127bb6f
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 62 deletions.
11 changes: 0 additions & 11 deletions common/src/main/java/net/blay09/mods/excompressum/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package net.blay09.mods.excompressum;

import net.blay09.mods.balm.api.Balm;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.component.ResolvableProfile;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class CommonProxy {
public void preloadSkin(ResolvableProfile profile) {
Expand All @@ -20,12 +17,4 @@ public void spawnAutoSieveParticles(Level level, BlockPos pos, BlockState emitte

public void spawnHeavySieveParticles(Level level, BlockPos pos, BlockState particleState, int particleCount) {
}

public RecipeManager getRecipeManager(@Nullable Level level) {
if (level != null && level.getServer() != null) {
return level.getServer().getRecipeManager();
}

return Balm.getHooks().getServer().getRecipeManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.blay09.mods.excompressum.block.entity.HeavySieveBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
Expand Down Expand Up @@ -99,9 +100,11 @@ protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Lev
return InteractionResult.SUCCESS;
}

if (heavySieve.addSiftable(player, itemStack)) {
level.playSound(null, pos, SoundEvents.GRAVEL_STEP, SoundSource.BLOCKS, 0.5f, 1f);
return InteractionResult.SUCCESS;
if (level instanceof ServerLevel serverLevel) {
if (heavySieve.addSiftable(serverLevel, player, itemStack)) {
level.playSound(null, pos, SoundEvents.GRAVEL_STEP, SoundSource.BLOCKS, 0.5f, 1f);
return InteractionResult.SUCCESS;
}
}

return super.useItemOn(itemStack, state, level, pos, player, hand, blockHitResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.blay09.mods.excompressum.block.entity.ModBlockEntities;
import net.blay09.mods.excompressum.block.entity.WoodenCrucibleBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
Expand Down Expand Up @@ -78,8 +79,10 @@ protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Lev
return InteractionResult.PASS;
}

if (woodenCrucible.addItem(itemStack, false, false)) {
return InteractionResult.CONSUME;
if (level instanceof ServerLevel serverLevel) {
if (woodenCrucible.addItem(serverLevel, itemStack, false, false)) {
return InteractionResult.CONSUME;
}
}

Balm.getHooks().useFluidTank(state, level, pos, player, hand, blockHitResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class AbstractAutoSieveBlockEntity extends AbstractBaseBlockEnti
@Override
public boolean canPlaceItem(int slot, ItemStack itemStack) {
if (inputSlots.containsOuterSlot(slot)) {
return isSiftableWithMesh(itemStack, getSieveMesh());
return level instanceof ServerLevel serverLevel && isSiftableWithMesh(serverLevel, itemStack, getSieveMesh());
} else if (meshSlots.containsOuterSlot(slot)) {
return isMesh(itemStack);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public void serverTick() {
if (currentStack.isEmpty()) {
ItemStack inputStack = inputSlots.getItem(0);
SieveMeshRegistryEntry sieveMesh = getSieveMesh();
if (!inputStack.isEmpty() && sieveMesh != null && isSiftableWithMesh(inputStack, sieveMesh)) {
if (!inputStack.isEmpty() && sieveMesh != null && isSiftableWithMesh((ServerLevel) level, inputStack, sieveMesh)) {
boolean foundSpace = false;
for (int i = 0; i < outputSlots.getContainerSize(); i++) {
if (outputSlots.getItem(i).isEmpty()) {
Expand Down Expand Up @@ -239,7 +239,7 @@ public void serverTick() {
if (!level.isClientSide) {
SieveMeshRegistryEntry sieveMesh = getSieveMesh();
if (sieveMesh != null) {
Collection<ItemStack> rewards = rollSieveRewards(level, currentStack, sieveMesh, getEffectiveLuck(), level.random);
Collection<ItemStack> rewards = rollSieveRewards((ServerLevel) level, currentStack, sieveMesh, getEffectiveLuck(), level.random);
for (ItemStack itemStack : rewards) {
if (!addItemToOutput(itemStack)) {
overflowBuffer.add(itemStack);
Expand Down Expand Up @@ -312,15 +312,15 @@ public float getEffectiveLuck() {
return 0f;
}

public boolean isSiftableWithMesh(ItemStack itemStack, @Nullable SieveMeshRegistryEntry sieveMesh) {
public boolean isSiftableWithMesh(ServerLevel level, ItemStack itemStack, @Nullable SieveMeshRegistryEntry sieveMesh) {
return ExNihilo.isSiftableWithMesh(level, getBlockState(), itemStack, sieveMesh);
}

private boolean isMesh(ItemStack itemStack) {
return SieveMeshRegistry.getEntry(itemStack) != null;
}

public Collection<ItemStack> rollSieveRewards(Level level, ItemStack itemStack, SieveMeshRegistryEntry sieveMesh, float luck, RandomSource rand) {
public Collection<ItemStack> rollSieveRewards(ServerLevel level, ItemStack itemStack, SieveMeshRegistryEntry sieveMesh, float luck, RandomSource rand) {
return ExNihilo.rollSieveRewards(level, getBlockState(), itemStack, sieveMesh, luck, rand);
}

Expand Down Expand Up @@ -463,10 +463,12 @@ public ItemStack getMeshStack() {
return meshSlots.getItem(0);
}

public boolean isCorrectSieveMesh() {
public boolean isCorrectSieveMesh() { // TODO need to turn this into a data slot because it's used on client
ItemStack inputStack = inputSlots.getItem(0);
SieveMeshRegistryEntry sieveMesh = getSieveMesh();
return inputStack.isEmpty() || sieveMesh == null || isSiftableWithMesh(inputStack, sieveMesh);
return inputStack.isEmpty() || sieveMesh == null || (level instanceof ServerLevel serverLevel && isSiftableWithMesh(serverLevel,
inputStack,
sieveMesh));
}

public boolean shouldAnimate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public float getEffectiveSpeed() {
}

@Override
public boolean isRegistered(ItemStack itemStack) {
public boolean isRegistered(ServerLevel level, ItemStack itemStack) {
final var recipeManager = level.getServer().getRecipeManager();
return ExRegistries.getCompressedHammerRegistry().isHammerable(recipeManager, itemStack);
}

@Override
public Collection<ItemStack> rollHammerRewards(ItemStack itemStack, ItemStack toolItem, RandomSource rand) {
LootContext lootContext = LootTableUtils.buildLootContext(((ServerLevel) level), itemStack);
public Collection<ItemStack> rollHammerRewards(ServerLevel level, ItemStack itemStack, ItemStack toolItem, RandomSource rand) {
LootContext lootContext = LootTableUtils.buildLootContext(level, itemStack);
return CompressedHammerRegistry.rollHammerRewards(level, lootContext, itemStack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public int getCount() {
@Override
public boolean canPlaceItem(int slot, ItemStack itemStack) {
if (inputSlots.containsOuterSlot(slot)) {
return isRegistered(itemStack);
return level instanceof ServerLevel serverLevel && isRegistered(serverLevel, itemStack);
} else if (hammerSlots.containsOuterSlot(slot)) {
return isHammerUpgrade(itemStack);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public void serverTick() {
if (!isDisabledByRedstone() && overflowBuffer.isEmpty() && getEnergyStored() >= effectiveEnergy) {
if (currentStack.isEmpty() && cooldown <= 0) {
ItemStack inputStack = inputSlots.getItem(0);
if (!inputStack.isEmpty() && isRegistered(inputStack)) {
if (!inputStack.isEmpty() && isRegistered((ServerLevel) level, inputStack)) {
boolean foundSpace = false;
for (int i = 0; i < outputSlots.getContainerSize(); i++) {
if (outputSlots.getItem(i).isEmpty()) {
Expand Down Expand Up @@ -235,7 +235,7 @@ public void serverTick() {
});
}
}
Collection<ItemStack> rewards = rollHammerRewards(currentStack, getEffectiveTool(), level.random);
Collection<ItemStack> rewards = rollHammerRewards((ServerLevel) level, currentStack, getEffectiveTool(), level.random);
for (ItemStack itemStack : rewards) {
if (!addItemToOutput(itemStack)) {
overflowBuffer.add(itemStack);
Expand All @@ -250,8 +250,8 @@ public void serverTick() {
}
}
} else if (!overflowBuffer.isEmpty()) {
if (addItemToOutput(overflowBuffer.get(0))) {
overflowBuffer.remove(0);
if (addItemToOutput(overflowBuffer.getFirst())) {
overflowBuffer.removeFirst();
}
}

Expand Down Expand Up @@ -441,7 +441,7 @@ public boolean isHammerUpgrade(ItemStack itemStack) {
return itemStack.is(ModItemTags.HAMMERS);
}

public boolean isRegistered(ItemStack itemStack) {
public boolean isRegistered(ServerLevel level, ItemStack itemStack) {
if (level == null) {
return false;
}
Expand All @@ -450,14 +450,14 @@ public boolean isRegistered(ItemStack itemStack) {
return ExNihilo.isHammerable(level, itemStack) || ExRegistries.getHammerRegistry().isHammerable(recipeManager, itemStack);
}

public Collection<ItemStack> rollHammerRewards(ItemStack itemStack, ItemStack toolItem, RandomSource rand) {
public Collection<ItemStack> rollHammerRewards(ServerLevel level, ItemStack itemStack, ItemStack toolItem, RandomSource rand) {
if (level == null) {
return Collections.emptyList();
}

final var recipeManager = level.getServer().getRecipeManager();
if (ExRegistries.getHammerRegistry().isHammerable(recipeManager, itemStack)) {
LootContext lootContext = LootTableUtils.buildLootContext(((ServerLevel) level), itemStack);
LootContext lootContext = LootTableUtils.buildLootContext(level, itemStack);
return HammerRegistry.rollHammerRewards(lootContext, itemStack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public AutoHeavySieveBlockEntity(BlockPos pos, BlockState state) {
}

@Override
public boolean isSiftableWithMesh(ItemStack itemStack, @Nullable SieveMeshRegistryEntry sieveMesh) {
public boolean isSiftableWithMesh(ServerLevel level, ItemStack itemStack, @Nullable SieveMeshRegistryEntry sieveMesh) {
return ExRegistries.getHeavySieveRegistry().isSiftable(level, getBlockState(), itemStack, sieveMesh);
}

@Override
public Collection<ItemStack> rollSieveRewards(Level level, ItemStack itemStack, SieveMeshRegistryEntry sieveMesh, float luck, RandomSource rand) {
LootContext lootContext = LootTableUtils.buildLootContext(((ServerLevel) this.level), itemStack);
public Collection<ItemStack> rollSieveRewards(ServerLevel level, ItemStack itemStack, SieveMeshRegistryEntry sieveMesh, float luck, RandomSource rand) {
LootContext lootContext = LootTableUtils.buildLootContext(level, itemStack);
return HeavySieveRegistry.rollSieveRewards(level, lootContext, getBlockState(), sieveMesh, itemStack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public HeavySieveBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.heavySieve.get(), pos, state);
}

public boolean addSiftable(Player player, ItemStack itemStack) {
public boolean addSiftable(ServerLevel level, Player player, ItemStack itemStack) {
if (!currentStack.isEmpty() || meshStack.isEmpty() || !ExRegistries.getHeavySieveRegistry().isSiftable(level, getBlockState(), itemStack, getSieveMesh())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -77,7 +78,7 @@ public WoodenCrucibleBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.woodenCrucible.get(), pos, state);
}

public boolean addItem(ItemStack itemStack, boolean isAutomated, boolean simulate) {
public boolean addItem(ServerLevel level, ItemStack itemStack, boolean isAutomated, boolean simulate) {
// When inserting dust, turn it into clay if we have enough liquid
if (fluidTank.getAmount() >= 1000 && itemStack.is(ModItemTags.DUSTS)) {
if (!simulate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import net.blay09.mods.excompressum.tag.ModItemTags;
import net.blay09.mods.excompressum.utils.StupidUtils;
import net.minecraft.core.component.DataComponents;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

public class HammerSpeedHandler {

Expand All @@ -19,8 +19,13 @@ public static void initialize() {
public static void onDigSpeed(DigSpeedEvent event) {
ItemStack heldItem = event.getPlayer().getItemInHand(InteractionHand.MAIN_HAND);
final var targetItem = StupidUtils.getItemStackFromState(event.getState());
Level level = event.getPlayer().level();
if ((heldItem.is(ModItemTags.HAMMERS) || heldItem.is(ModItemTags.COMPRESSED_HAMMERS)) && (ExRegistries.getHammerRegistry().isHammerable(level, targetItem) || ExRegistries.getCompressedHammerRegistry().isHammerable(level, targetItem))) {
final var level = event.getPlayer().level();
if (!(level instanceof ServerLevel serverLevel)) {
return; // TODO I believe this needs to run on client too though... might have to upgrade more stuff to tags and to be less dependent on recipe existence
}

if ((heldItem.is(ModItemTags.HAMMERS) || heldItem.is(ModItemTags.COMPRESSED_HAMMERS)) && (ExRegistries.getHammerRegistry()
.isHammerable(serverLevel, targetItem) || ExRegistries.getCompressedHammerRegistry().isHammerable(serverLevel, targetItem))) {
float newSpeed = 2f;
final var tool = heldItem.get(DataComponents.TOOL);
if (tool != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ public InteractionResult use(Level level, Player player, InteractionHand hand) {

@Override
public boolean isCorrectToolForDrops(ItemStack itemStack, BlockState state) {
RecipeManager recipeManager = ExCompressum.proxy.get().getRecipeManager(null);
return ExRegistries.getChickenStickRegistry().isHammerable(recipeManager, new ItemStack(state.getBlock()));
// TODO no more recipe manager on client, might need to introduce a tag and manage it alongside the recipes
// RecipeManager recipeManager = ExCompressum.proxy.get().getRecipeManager(null);
// return ExRegistries.getChickenStickRegistry().isHammerable(recipeManager, new ItemStack(state.getBlock()));
return true;
}

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
RecipeManager recipeManager = ExCompressum.proxy.get().getRecipeManager(null);
if ((ExRegistries.getChickenStickRegistry().isHammerable(recipeManager, new ItemStack(state.getBlock())))) {
if (isAngry(stack)) {
return CHICKEN_STICK_TIER.speed() * 1.5f;
}
return CHICKEN_STICK_TIER.speed();
}
// TODO no more recipe manager on client, might need to introduce a tag and manage it alongside the recipes
// RecipeManager recipeManager = ExCompressum.proxy.get().getRecipeManager(null);
// if ((ExRegistries.getChickenStickRegistry().isHammerable(recipeManager, new ItemStack(state.getBlock())))) {
// if (isAngry(stack)) {
// return CHICKEN_STICK_TIER.speed() * 1.5f;
// }
// return CHICKEN_STICK_TIER.speed();
// }
return 0.8f;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.blay09.mods.excompressum.mixin.RecipeManagerAccessor;
import net.blay09.mods.excompressum.registry.ModRecipeTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
Expand All @@ -13,7 +14,7 @@

public class ChickenStickRegistry {

public static List<ItemStack> rollHammerRewards(Level level, LootContext context, ItemStack itemStack) {
public static List<ItemStack> rollHammerRewards(ServerLevel level, LootContext context, ItemStack itemStack) {
final var recipeManager = level.getServer().getRecipeManager();
final var recipeMap = ((RecipeManagerAccessor) recipeManager).getRecipes();
final var recipes = recipeMap.byType(ModRecipeTypes.chickenStickRecipeType);
Expand All @@ -35,7 +36,7 @@ private static boolean testRecipe(ItemStack itemStack, ChickenStickRecipe recipe
return recipe.getIngredient().test(itemStack);
}

public boolean isHammerable(Level level, ItemStack itemStack) {
public boolean isHammerable(ServerLevel level, ItemStack itemStack) {
return isHammerable(level.getServer().getRecipeManager(), itemStack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import net.blay09.mods.excompressum.mixin.RecipeManagerAccessor;
import net.blay09.mods.excompressum.registry.ExNihilo;
import net.blay09.mods.excompressum.registry.ModRecipeTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.loot.LootContext;

import java.util.*;

public class CompressedHammerRegistry {

public static List<ItemStack> rollHammerRewards(Level level, LootContext context, ItemStack itemStack) {
public static List<ItemStack> rollHammerRewards(ServerLevel level, LootContext context, ItemStack itemStack) {
final var recipeManager = level.getServer().getRecipeManager();
final var recipeMap = ((RecipeManagerAccessor) recipeManager).getRecipes();
final var recipes = recipeMap.byType(ModRecipeTypes.compressedHammerRecipeType);
Expand All @@ -37,7 +37,7 @@ private static boolean testRecipe(ItemStack itemStack, CompressedHammerRecipe re
return recipe.getIngredient().test(itemStack);
}

public boolean isHammerable(Level level, ItemStack itemStack) {
public boolean isHammerable(ServerLevel level, ItemStack itemStack) {
return isHammerable(level.getServer().getRecipeManager(), itemStack);
}

Expand Down
Loading

0 comments on commit 127bb6f

Please sign in to comment.