Skip to content

Commit

Permalink
update Neo and NG
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Jan 5, 2024
1 parent 023e30c commit 3af6c6b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.61'
id 'net.neoforged.gradle.userdev' version '7.0.80'
}

version = mod_version
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.debug=false

minecraft_version=1.20.4
minecraft_version_range=[1.20.4,1.21)
neo_version=20.4.22-beta
neo_version_range=[20.4,)
neo_version=20.4.77-beta
neo_version_range=[20.4.77-beta,)
loader_version_range=[1,)

mod_id=bibliocraft
mod_name=Bibliocraft Legacy
mod_license=MIT License
mod_version=1.0.0
mod_group_id=com.example.examplemod
mod_group_id=com.github.minecraftschurlimods.bibliocraft
mod_authors=IchHabeHunger54, Minecraftschurli
mod_credits=Nuchaz for creating the original mod
mod_description=Bibliocraft Legacy is a port of the original BiblioCraft Minecraft mod by Nuchaz. It adds various pieces of decorative and functional furniture into the game.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.github.minecraftschurlimods.bibliocraft.content.label;

import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCBlock;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.BlockGetter;
Expand All @@ -20,7 +19,6 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

import java.util.stream.IntStream;
Expand Down Expand Up @@ -73,14 +71,10 @@ public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) {

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (level.isClientSide()) return InteractionResult.SUCCESS;
if (!player.isSecondaryUseActive() || !player.getItemInHand(hand).isEmpty()) {
BlockPos newPos = pos.offset(state.getValue(FACING).getOpposite().getNormal());
return level.getBlockState(newPos).use(level, player, hand, hit.withPosition(newPos));
}
if (level.getBlockEntity(pos) instanceof MenuProvider provider) {
NetworkHooks.openScreen((ServerPlayer) player, provider, pos);
}
return InteractionResult.SUCCESS;
return BCUtil.openBEMenu(player, level, pos);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.github.minecraftschurlimods.bibliocraft.util;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -61,6 +66,21 @@ public static <T> Collection<T> mergeRaw(Collection... collections) {
return list;
}

/**
* Shorthand to open a menu for the block entity at the given position and return {@link InteractionResult#SUCCESS}.
*
* @param player The player to open the menu for.
* @param level The level of the block entity.
* @param pos The position of the block entity.
* @return {@link InteractionResult#SUCCESS}
*/
public static InteractionResult openBEMenu(Player player, Level level, BlockPos pos) {
if (level.getBlockEntity(pos) instanceof MenuProvider menu) {
player.openMenu(menu);
}
return InteractionResult.SUCCESS;
}

//region Static variants of the methods in DyeableLeatherItem.
public static boolean hasNBTColor(ItemStack stack) {
if (!stack.hasTag() || !stack.getTag().contains(TAG_DISPLAY)) return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.minecraftschurlimods.bibliocraft.util.content;

import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
Expand All @@ -29,7 +29,6 @@
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable;

/**
Expand Down Expand Up @@ -91,12 +90,7 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (player.isSecondaryUseActive()) return InteractionResult.PASS;
if (level.isClientSide()) return InteractionResult.SUCCESS;
if (level.getBlockEntity(pos) instanceof MenuProvider provider) {
NetworkHooks.openScreen((ServerPlayer) player, provider, pos);
}
return InteractionResult.SUCCESS;
return player.isSecondaryUseActive() ? InteractionResult.PASS : BCUtil.openBEMenu(player, level, pos);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.github.minecraftschurlimods.bibliocraft.util.content;

import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.network.NetworkHooks;

/**
* Abstract superclass for blocks that have in-world interactions.
Expand All @@ -33,25 +31,18 @@ public BCInteractibleBlock(Properties properties) {

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (player.isSecondaryUseActive()) {
if (level.isClientSide()) return InteractionResult.SUCCESS;
if (level.getBlockEntity(pos) instanceof MenuProvider provider) {
NetworkHooks.openScreen((ServerPlayer) player, provider, pos);
}
return InteractionResult.SUCCESS;
}
if (canAccessFromDirection(state, hit.getDirection())) {
ItemStack stack = player.getItemInHand(hand);
int slot = lookingAtSlot(state, hit);
if (slot != -1) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof BCBlockEntity bcbe) {
ItemStack slotStack = bcbe.getItem(slot);
if ((!stack.isEmpty() && bcbe.canPlaceItem(slot, stack)) || !slotStack.isEmpty()) {
bcbe.setItem(slot, stack);
player.setItemInHand(hand, slotStack);
return InteractionResult.SUCCESS;
}
if (player.isSecondaryUseActive()) return BCUtil.openBEMenu(player, level, pos);
if (!canAccessFromDirection(state, hit.getDirection())) return super.use(state, level, pos, player, hand, hit);
ItemStack stack = player.getItemInHand(hand);
int slot = lookingAtSlot(state, hit);
if (slot != -1) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof BCBlockEntity bcbe) {
ItemStack slotStack = bcbe.getItem(slot);
if ((!stack.isEmpty() && bcbe.canPlaceItem(slot, stack)) || !slotStack.isEmpty()) {
bcbe.setItem(slot, stack);
player.setItemInHand(hand, slotStack);
return InteractionResult.SUCCESS;
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
modLoader="javafml" #mandatory
loaderVersion="${loader_version_range}" #mandatory
modLoader="javafml"
loaderVersion="${loader_version_range}"
license="${mod_license}"

[[mods]] #mandatory
modId="${mod_id}" #mandatory
version="${mod_version}" #mandatory
displayName="${mod_name}" #mandatory
#logoFile="examplemod.png" #optional
credits="${mod_credits}" #optional
authors="${mod_authors}" #optional
description='''${mod_description}''' #mandatory
[[mods]]
modId="${mod_id}"
version="${mod_version}"
displayName="${mod_name}"
#logoFile="examplemod.png"
credits="${mod_credits}"
authors="${mod_authors}"
description='''${mod_description}'''

[[dependencies.${mod_id}]] #optional
modId="neoforge" #mandatory
mandatory=true #mandatory
versionRange="${neo_version_range}" #mandatory
[[dependencies.${mod_id}]]
modId="neoforge"
type="required"
versionRange="${neo_version_range}"
ordering="NONE"
side="BOTH"

[[dependencies.${mod_id}]]
modId="minecraft"
mandatory=true
type="required"
versionRange="${minecraft_version_range}"
ordering="NONE"
side="BOTH"

0 comments on commit 3af6c6b

Please sign in to comment.