Skip to content

Commit

Permalink
Update to MC 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 8, 2024
1 parent dd28e06 commit 5e84326
Show file tree
Hide file tree
Showing 94 changed files with 217 additions and 233 deletions.
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'net.neoforged.gradle.userdev' version '7.0.97'
id 'net.neoforged.gradle.userdev' version '7.0.145'
id 'net.darkhax.curseforgegradle' version '1.0.8'
id 'com.diffplug.spotless' version '5.14.3'
id 'com.modrinth.minotaur' version '2.+'
Expand Down Expand Up @@ -31,7 +31,7 @@ base {
}

// Set Java details
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
compileJava.options.compilerArgs << "-Xmaxerrs" << "9999"
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))

Expand Down Expand Up @@ -98,10 +98,10 @@ dependencies {
}

// Project lombok
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
}

minecraft {
Expand Down Expand Up @@ -300,6 +300,8 @@ publishing {

idea {
module {
downloadSources = true
downloadJavadoc = true
for (String excludeDirName in ["run", "out", "logs", "gradle"]) {
File excludeDir = new File(projectDir, excludeDirName)
excludeDirs.add(excludeDir)
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod_id=colossalchests
mod_version=1.8.5
minecraft_version=1.20.4
neoforge_version=20.4.160-beta
cyclopscore_version=1.19.0-421
minecraft_version=1.21
neoforge_version=21.0.43-beta
cyclopscore_version=1.19.1-452
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

commoncapabilities_version=2.9.1-113
commoncapabilities_version=2.9.1-125

# Workaround for Spotless bug
# https://github.com/diffplug/spotless/issues/834
Expand Down
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-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 8 additions & 8 deletions src/main/java/org/cyclops/colossalchests/RegistryEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
*/
public class RegistryEntries {

public static final DeferredHolder<Item, Item> ITEM_CHEST = DeferredHolder.create(Registries.ITEM, new ResourceLocation("minecraft:chest"));
public static final DeferredHolder<Item, Item> ITEM_CHEST = DeferredHolder.create(Registries.ITEM, ResourceLocation.parse("minecraft:chest"));

public static final DeferredHolder<Block, Block> BLOCK_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK, new ResourceLocation("colossalchests:uncolossal_chest"));
public static final DeferredHolder<Block, Block> BLOCK_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK, ResourceLocation.parse("colossalchests:uncolossal_chest"));

public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityColossalChest>> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("colossalchests:colossal_chest"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityInterface>> BLOCK_ENTITY_INTERFACE = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("colossalchests:interface"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityUncolossalChest>> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("colossalchests:uncolossal_chest"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityColossalChest>> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:colossal_chest"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityInterface>> BLOCK_ENTITY_INTERFACE = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:interface"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityUncolossalChest>> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:uncolossal_chest"));

public static final DeferredHolder<MenuType<?>, MenuType<ContainerColossalChest>> CONTAINER_COLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, new ResourceLocation("colossalchests:colossal_chest"));
public static final DeferredHolder<MenuType<?>, MenuType<ContainerUncolossalChest>> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, new ResourceLocation("colossalchests:uncolossal_chest"));
public static final DeferredHolder<MenuType<?>, MenuType<ContainerColossalChest>> CONTAINER_COLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, ResourceLocation.parse("colossalchests:colossal_chest"));
public static final DeferredHolder<MenuType<?>, MenuType<ContainerUncolossalChest>> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolder.create(Registries.MENU, ResourceLocation.parse("colossalchests:uncolossal_chest"));

public static final DeferredHolder<CriterionTrigger<?>, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolder.create(Registries.TRIGGER_TYPE, new ResourceLocation("colossalchests:chest_formed"));
public static final DeferredHolder<CriterionTrigger<?>, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolder.create(Registries.TRIGGER_TYPE, ResourceLocation.parse("colossalchests:chest_formed"));

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.ExtraCodecs;
import org.apache.commons.lang3.tuple.Pair;
import org.cyclops.colossalchests.block.ChestMaterial;
import org.cyclops.cyclopscore.advancement.criterion.ICriterionInstanceTestable;
Expand All @@ -21,9 +20,9 @@ public class ChestFormedTrigger extends SimpleCriterionTrigger<ChestFormedTrigge

public static final Codec<ChestFormedTrigger.Instance> CODEC = RecordCodecBuilder.create(
p_311401_ -> p_311401_.group(
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player").forGetter(ChestFormedTrigger.Instance::player),
ExtraCodecs.strictOptionalField(ChestMaterial.CODEC, "material").forGetter(ChestFormedTrigger.Instance::material),
ExtraCodecs.strictOptionalField(Codec.INT, "minimumSize").forGetter(ChestFormedTrigger.Instance::minimumSize)
EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(ChestFormedTrigger.Instance::player),
ChestMaterial.CODEC.optionalFieldOf("material").forGetter(ChestFormedTrigger.Instance::material),
Codec.INT.optionalFieldOf("minimumSize").forGetter(ChestFormedTrigger.Instance::minimumSize)
)
.apply(p_311401_, ChestFormedTrigger.Instance::new)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.google.gson.JsonSyntaxException;
import com.mojang.serialization.Codec;
import net.minecraft.core.Vec3i;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.inventory.MenuType;
import org.cyclops.colossalchests.GeneralConfig;
import org.cyclops.colossalchests.Reference;
Expand All @@ -29,7 +28,7 @@
*/
public class ChestMaterial {

public static final Codec<ChestMaterial> CODEC = ExtraCodecs.stringResolverCodec(
public static final Codec<ChestMaterial> CODEC = Codec.stringResolver(
ChestMaterial::getName,
ChestMaterial::valueOfSafe
);
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/org/cyclops/colossalchests/block/ChestWall.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
Expand All @@ -26,7 +23,7 @@
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.living.MobSpawnEvent;
import net.neoforged.neoforge.event.entity.living.FinalizeSpawnEvent;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.cyclopscore.block.multi.CubeDetector;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
Expand All @@ -53,7 +50,7 @@ public ChestWall(Block.Properties properties, ChestMaterial material) {
NeoForge.EVENT_BUS.addListener(this::onLivingSpawn);
}

public void onLivingSpawn(MobSpawnEvent.FinalizeSpawn event) {
public void onLivingSpawn(FinalizeSpawnEvent event) {
// Only isValidSpawn is insufficient in some cases, so we add this forceful check as well.
if (event.getSpawnType() != MobSpawnType.CHUNK_GENERATION && event.getEntity().getBlockStateOn().getBlock() == this) {
event.setSpawnCancelled(true);
Expand Down Expand Up @@ -86,11 +83,6 @@ public boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockRe
return blockState.getValue(ENABLED);
}

@Override
public boolean isValidSpawn(BlockState state, BlockGetter world, BlockPos pos, SpawnPlacements.Type type, EntityType<?> entityType) {
return false;
}

@Override
public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) {
return true;
Expand Down Expand Up @@ -137,18 +129,17 @@ public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean v
}

@Override
public InteractionResult use(BlockState blockState, Level world, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
public InteractionResult useWithoutItem(BlockState blockState, Level world, BlockPos blockPos, Player player, BlockHitResult rayTraceResult) {
if(blockState.getValue(ENABLED)) {
BlockPos tileLocation = ColossalChest.getCoreLocation(material, world, blockPos);
if(tileLocation != null) {
return world.getBlockState(tileLocation).getBlock().
use(blockState, world, tileLocation, player, hand, rayTraceResult);
return world.getBlockState(tileLocation).useWithoutItem(world, player, rayTraceResult.withPosition(tileLocation));
}
} else {
ColossalChest.addPlayerChatError(material, world, blockPos, player, hand);
ColossalChest.addPlayerChatError(material, world, blockPos, player);
return InteractionResult.FAIL;
}
return super.use(blockState, world, blockPos, player, hand, rayTraceResult);
return super.useWithoutItem(blockState, world, blockPos, player, rayTraceResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public ChestWallConfig(ChestMaterial material) {
.strength(5.0F)
.sound(SoundType.WOOD)
.requiresCorrectToolForDrops()
.noOcclusion(),
.noOcclusion()
.isValidSpawn((state, level, pos, entityType) -> false),
material),
(eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material)
);
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/org/cyclops/colossalchests/block/ColossalChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
Expand All @@ -14,13 +15,10 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
Expand All @@ -45,7 +43,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.living.MobSpawnEvent;
import net.neoforged.neoforge.event.entity.living.FinalizeSpawnEvent;
import org.cyclops.colossalchests.RegistryEntries;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.cyclopscore.block.BlockWithEntityGui;
Expand Down Expand Up @@ -84,7 +82,7 @@ public ColossalChest(Properties properties, ChestMaterial material) {
NeoForge.EVENT_BUS.addListener(this::onLivingSpawn);
}

public void onLivingSpawn(MobSpawnEvent.FinalizeSpawn event) {
public void onLivingSpawn(FinalizeSpawnEvent event) {
// Only isValidSpawn is insufficient in some cases, so we add this forceful check as well.
if (event.getSpawnType() != MobSpawnType.CHUNK_GENERATION && event.getEntity().getBlockStateOn().getBlock() == this) {
event.setSpawnCancelled(true);
Expand Down Expand Up @@ -153,11 +151,6 @@ public boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockRe
return blockState.getValue(ENABLED);
}

@Override
public boolean isValidSpawn(BlockState state, BlockGetter world, BlockPos pos, SpawnPlacements.Type type, EntityType<?> entityType) {
return false;
}

@Override
public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) {
return true;
Expand All @@ -183,7 +176,7 @@ public static DetectionResult triggerDetector(ChestMaterial material, LevelAcces
@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.setPlacedBy(world, pos, state, placer, stack);
if (stack.hasCustomHoverName()) {
if (stack.has(DataComponents.CUSTOM_NAME)) {
BlockEntityColossalChest tile = BlockEntityHelpers.get(world, pos, BlockEntityColossalChest.class).orElse(null);
if (tile != null) {
tile.setCustomName(stack.getHoverName());
Expand Down Expand Up @@ -244,10 +237,9 @@ public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean v
* @param world The world.
* @param blockPos The start position.
* @param player The player.
* @param hand The used hand.
*/
public static void addPlayerChatError(ChestMaterial material, Level world, BlockPos blockPos, Player player, InteractionHand hand) {
if(!world.isClientSide && player.getItemInHand(hand).isEmpty()) {
public static void addPlayerChatError(ChestMaterial material, Level world, BlockPos blockPos, Player player) {
if(!world.isClientSide && player.getItemInHand(player.getUsedItemHand()).isEmpty()) {
DetectionResult result = material.getChestDetector().detect(world, blockPos, null, new MaterialValidationAction(), false);
if (result != null && result.getError() != null) {
addPlayerChatError(player, result.getError());
Expand Down Expand Up @@ -275,17 +267,17 @@ public static void addPlayerChatError(Player player, Component error) {
}

@Override
public void writeExtraGuiData(FriendlyByteBuf packetBuffer, Level world, Player player, BlockPos blockPos, InteractionHand hand, BlockHitResult rayTraceResult) {
public void writeExtraGuiData(FriendlyByteBuf packetBuffer, Level world, Player player, BlockPos blockPos, BlockHitResult rayTraceResult) {
BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize()));
}

@Override
public InteractionResult use(BlockState blockState, Level world, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
public InteractionResult useWithoutItem(BlockState blockState, Level world, BlockPos blockPos, Player player, BlockHitResult rayTraceResult) {
if(!(blockState.getValue(ENABLED))) {
ColossalChest.addPlayerChatError(material, world, blockPos, player, hand);
ColossalChest.addPlayerChatError(material, world, blockPos, player);
return InteractionResult.FAIL;
}
return super.use(blockState, world, blockPos, player, hand, rayTraceResult);
return super.useWithoutItem(blockState, world, blockPos, player, rayTraceResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public ColossalChestConfig(ChestMaterial material) {
.strength(5.0F)
.sound(SoundType.WOOD)
.requiresCorrectToolForDrops()
.noOcclusion(),
.noOcclusion()
.isValidSpawn((state, level, pos, entityType) -> false),
material),
(eConfig, block) -> new ItemBlockMaterial(block, new Item.Properties(), material)
);
Expand Down
Loading

0 comments on commit 5e84326

Please sign in to comment.