Skip to content

Commit

Permalink
wip: Update to Minecraft 1.21.2, still broken due to Recipocalypse
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 11, 2024
1 parent 99c7098 commit f2bba50
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 104 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Fixed market block replacing the block above it when placed even if it's not replaceable
- Updated to Minecraft 1.21.2
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public static void initialize() {

public static Component getDefaultPaymentComponent(Payment payment) {
final var ingredient = payment.ingredient();
if (ingredient.isEmpty()) {
if (ingredient.items().isEmpty()) {
return Component.literal("<invalid>");
}

final var candidates = ingredient.getItems();
final var index = (int) (System.currentTimeMillis() / 1500L % candidates.length);
final var itemStack = candidates[index];
return Component.translatable("tooltip.farmingforblockheads.payment_item", payment.count(), itemStack.getHoverName());
final var candidates = ingredient.items();
final var index = (int) (System.currentTimeMillis() / 1500L % candidates.size());
final var itemHolder = candidates.get(index);
return Component.translatable("tooltip.farmingforblockheads.payment_item", payment.count(), itemHolder.value().getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package net.blay09.mods.farmingforblockheads.block;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.blay09.mods.balm.api.container.ContainerUtils;
import net.blay09.mods.farmingforblockheads.FarmingForBlockheads;
import net.blay09.mods.farmingforblockheads.block.entity.ChickenNestBlockEntity;
import net.blay09.mods.farmingforblockheads.block.entity.ModBlockEntities;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand All @@ -30,11 +26,10 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand All @@ -46,7 +41,7 @@ public class ChickenNestBlock extends BaseEntityBlock {

public static final MapCodec<ChickenNestBlock> CODEC = simpleCodec(ChickenNestBlock::new);

public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;

private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 3, 15);

Expand All @@ -72,9 +67,9 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
}

@Override
protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
use(state, level, pos, player);
return ItemInteractionResult.SUCCESS;
return InteractionResult.SUCCESS;
}

private void use(BlockState state, Level level, BlockPos pos, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import com.mojang.serialization.MapCodec;
import net.blay09.mods.balm.api.container.ContainerUtils;
import net.blay09.mods.farmingforblockheads.FarmingForBlockheads;
import net.blay09.mods.farmingforblockheads.block.entity.FeedingTroughBlockEntity;
import net.blay09.mods.farmingforblockheads.block.entity.ModBlockEntities;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
Expand All @@ -27,7 +24,6 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -54,7 +50,7 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
}

@Override
protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
if (!level.isClientSide) {
ItemStack heldItem = player.getItemInHand(hand);
BlockEntity blockEntity = level.getBlockEntity(pos);
Expand All @@ -75,7 +71,7 @@ protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state,
}
}
}
return ItemInteractionResult.SUCCESS;
return InteractionResult.SUCCESS;
}

@Override
Expand Down Expand Up @@ -112,7 +108,7 @@ public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos p
}

@Override
public VoxelShape getOcclusionShape(BlockState state, BlockGetter worldIn, BlockPos pos) {
protected VoxelShape getOcclusionShape(BlockState state) {
return RENDER_SHAPE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
Expand All @@ -41,7 +35,7 @@ public class MarketBlock extends BaseEntityBlock {
public static final MapCodec<MarketBlock> CODEC = simpleCodec(MarketBlock::new);

public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF;
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;

private static final VoxelShape TOP_SHAPE = Block.box(0, 0, 0, 16, 16, 16);
private static final VoxelShape RENDER_SHAPE = Block.box(0, 0.01, 0, 16, 16, 16);
Expand All @@ -57,13 +51,13 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState directionState, LevelAccessor world, BlockPos pos, BlockPos directionPos) {
public BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess scheduledTickAccess, BlockPos pos, Direction direction, BlockPos directionPos, BlockState directionState, RandomSource randomSource) {
final var half = state.getValue(HALF);
if ((direction.getAxis() != Direction.Axis.Y)
|| ((half == DoubleBlockHalf.LOWER) != (direction == Direction.UP))
|| ((directionState.getBlock() == this)
&& (directionState.getValue(HALF) != half))) {
if ((half != DoubleBlockHalf.LOWER) || (direction != Direction.DOWN) || state.canSurvive(world, pos)) {
if ((half != DoubleBlockHalf.LOWER) || (direction != Direction.DOWN) || state.canSurvive(level, pos)) {
return state;
}
}
Expand Down Expand Up @@ -124,7 +118,7 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L
}

level.addFreshEntity(merchant);
merchant.finalizeSpawn(((ServerLevel) level), level.getCurrentDifficultyAt(pos), MobSpawnType.STRUCTURE, null);
merchant.finalizeSpawn(((ServerLevel) level), level.getCurrentDifficultyAt(pos), EntitySpawnReason.STRUCTURE, null);
}

level.setBlock(pos.above(), state.setValue(HALF, DoubleBlockHalf.UPPER), 3);
Expand All @@ -137,9 +131,9 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP
}

@Override
protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
use(state, level, pos, player);
return ItemInteractionResult.SUCCESS;
return InteractionResult.SUCCESS;
}

private void use(BlockState state, Level level, BlockPos pos, Player player) {
Expand Down Expand Up @@ -183,7 +177,7 @@ public RenderShape getRenderShape(BlockState state) {
}

@Override
public VoxelShape getOcclusionShape(BlockState state, BlockGetter worldIn, BlockPos pos) {
public VoxelShape getOcclusionShape(BlockState state) {
if (state.getValue(HALF) == DoubleBlockHalf.UPPER) {
return Shapes.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -175,10 +176,9 @@ protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX,

Font font = minecraft.font;

guiGraphics.setColor(1f, 1f, 1f, 1f);
guiGraphics.blit(TEXTURE, leftPos, topPos - 10, 0, 0, imageWidth, imageHeight + 10);
guiGraphics.blit(RenderType::guiTextured, TEXTURE, leftPos, topPos - 10, 0, 0, imageWidth, imageHeight + 10, 256, 256);
if (menu.getSelectedRecipe() != null && !menu.isReadyToBuy()) {
guiGraphics.blit(TEXTURE, leftPos + 43, topPos + 40, 176, 0, 14, 14);
guiGraphics.blit(RenderType::guiTextured, TEXTURE, leftPos + 43, topPos + 40, 176, 0, 14, 14, 256, 256);
}

if (mouseClickY != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

Expand Down Expand Up @@ -34,8 +35,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
} else if (isHovered) {
texY += 20;
}
guiGraphics.setColor(1f, 1f, 1f, 1f);
guiGraphics.blit(ICONS, getX(), getY(), 176, texY, width, height);
guiGraphics.blit(RenderType::guiTextured, ICONS, getX(), getY(), 176, texY, width, height, 256, 256);

guiGraphics.renderItem(category.value().iconStack(), getX() + 2, getY() + 2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.blay09.mods.farmingforblockheads.client.render;

import net.minecraft.client.renderer.entity.state.VillagerRenderState;
import net.minecraft.resources.ResourceLocation;

public class MerchantRenderState extends VillagerRenderState {
public ResourceLocation textureLocation;
public int diggingAnimation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.CustomHeadLayer;
import net.minecraft.client.renderer.entity.state.VillagerRenderState;
import net.minecraft.resources.ResourceLocation;

import java.util.HashMap;
import java.util.Map;

public class MerchantRenderer extends LivingEntityRenderer<MerchantEntity, VillagerModel<MerchantEntity>> {
public class MerchantRenderer extends MobRenderer<MerchantEntity, VillagerRenderState, VillagerModel> {

private static final ResourceLocation MERCHANT_TEXTURE = ResourceLocation.fromNamespaceAndPath(FarmingForBlockheads.MOD_ID, "textures/entity/merchant.png");
private static final Map<ResourceLocation, ResourceLocation> verifiedTextures = new HashMap<>();

public MerchantRenderer(EntityRendererProvider.Context context) {
super(context, new VillagerModel<>(context.bakeLayer(ModelLayers.VILLAGER)), 0.5f);
this.addLayer(new CustomHeadLayer<>(this, context.getModelSet(), context.getItemInHandRenderer()));
super(context, new VillagerModel(context.bakeLayer(ModelLayers.VILLAGER)), 0.5f);
this.addLayer(new CustomHeadLayer<>(this, context.getModelSet(), context.getItemRenderer()));
}

@Override
public ResourceLocation getTextureLocation(MerchantEntity entity) {
ResourceLocation textureLocation = entity.getTextureLocation();
public ResourceLocation getTextureLocation(VillagerRenderState state) {
ResourceLocation textureLocation = state instanceof MerchantRenderState merchantRenderState ? merchantRenderState.textureLocation : null;
if (textureLocation == null) {
return MERCHANT_TEXTURE;
}
Expand All @@ -41,16 +42,31 @@ public ResourceLocation getTextureLocation(MerchantEntity entity) {
}

@Override
public void render(MerchantEntity entity, float p_225623_2_, float p_225623_3_, PoseStack poseStack, MultiBufferSource buffers, int p_225623_6_) {
int diggingAnimation = entity.getDiggingAnimation();
public void render(VillagerRenderState state, PoseStack poseStack, MultiBufferSource multiBufferSource, int i) {
final var diggingAnimation = state instanceof MerchantRenderState merchantRenderState ? merchantRenderState.diggingAnimation : 0;
if (diggingAnimation > 0) {
poseStack.translate(0.0, -diggingAnimation * 0.05, 0.0);
}
super.render(entity, p_225623_2_, p_225623_3_, poseStack, buffers, p_225623_6_);
super.render(state, poseStack, multiBufferSource, i);
}

@Override
protected boolean shouldShowName(MerchantEntity entity) {
return entity.getDiggingAnimation() <= 0 && super.shouldShowName(entity);
public void extractRenderState(MerchantEntity entity, VillagerRenderState state, float delta) {
super.extractRenderState(entity, state, delta);
if (state instanceof MerchantRenderState merchantRenderState) {
merchantRenderState.textureLocation = entity.getTextureLocation();
merchantRenderState.diggingAnimation = entity.getDiggingAnimation();
}
}

@Override
protected boolean shouldShowName(MerchantEntity entity, double distance) {
return entity.getDiggingAnimation() <= 0 && super.shouldShowName(entity, distance);
}

@Override
public MerchantRenderState createRenderState() {
return new MerchantRenderState();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public void register(EmiRegistry registry) {
registry.addCategory(MARKET_CATEGORY);
registry.addWorkstation(MARKET_CATEGORY, MARKET);

final var marketRecipes = registry.getRecipeManager().getAllRecipesFor(ModRecipes.marketRecipeType);
for (final var marketRecipe : marketRecipes) {
if (MarketPresetRegistry.isRecipeEnabled(marketRecipe.value())) {
registry.addRecipe(new MarketEmiRecipe(marketRecipe.id(), marketRecipe.value()));
}
}
// TODO final var marketRecipes = registry.getRecipeManager().getAllRecipesFor(ModRecipes.marketRecipeType);
// TODO for (final var marketRecipe : marketRecipes) {
// TODO if (MarketPresetRegistry.isRecipeEnabled(marketRecipe.value())) {
// TODO registry.addRecipe(new MarketEmiRecipe(marketRecipe.id(), marketRecipe.value()));
// TODO }
// TODO }

registry.addExclusionArea(MarketScreen.class, (screen, consumer) ->
screen.getFilterButtons().forEach(b ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MarketEmiRecipe implements EmiRecipe {
public MarketEmiRecipe(ResourceLocation id, MarketRecipe recipe) {
this.id = id;
this.input = List.of(EmiIngredient.of(recipe.getPaymentOrDefault().ingredient(), recipe.getPaymentOrDefault().count()));
this.output = List.of(EmiStack.of(recipe.getResultItem(RegistryAccess.EMPTY)));
this.output = List.of(EmiStack.of(recipe.getResultItem()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class JEIAddon implements IModPlugin {

@Override
public void registerRecipes(IRecipeRegistration registration) {
final var recipeManager = Minecraft.getInstance().level.getRecipeManager();
final var marketRecipes = recipeManager.getAllRecipesFor(ModRecipes.marketRecipeType)
.stream()
.filter(recipe -> MarketPresetRegistry.isRecipeEnabled(recipe.value()))
.toList();
registration.addRecipes(JeiMarketRecipeCategory.TYPE, marketRecipes);
// TODO final var recipeManager = Minecraft.getInstance().level.getRecipeManager();
// TODO final var marketRecipes = recipeManager.getAllRecipesFor(ModRecipes.marketRecipeType)
// TODO .stream()
// TODO .filter(recipe -> MarketPresetRegistry.isRecipeEnabled(recipe.value()))
// TODO .toList();
// TODO registration.addRecipes(JeiMarketRecipeCategory.TYPE, marketRecipes);
}

@Override
Expand Down
Loading

0 comments on commit f2bba50

Please sign in to comment.