Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- Fixed concurrentmodificationexception with resourceloading
- Prevented crash when resourceloading fails
- Fixed an incompatibility with C2ME
- Fixed error message when patchouli is not loaded
- Fixed beenests dropping without silktouch
  • Loading branch information
supermassimo committed Sep 1, 2024
1 parent 4cd8592 commit 1a21b76
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Maps;
import net.minecraft.resources.ResourceLocation;

import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Supplier;

/**
Expand All @@ -19,11 +20,11 @@ public interface ResourceCollector<R> {
void clear();

static <R> ResourceCollector<R> unordered() {
return new SimpleResourceCollector<>(Maps::newHashMap);
return new SimpleResourceCollector<>(Maps::newConcurrentMap);
}

static <R> ResourceCollector<R> ordered() {
return new SimpleResourceCollector<>(Maps::newLinkedHashMap);
return new SimpleResourceCollector<>(ConcurrentSkipListMap::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public ResultList applyAll(final Map<String, JsonElement> json, final O object)

@Override
public PropertyApplierResult apply(final O object, final String key, final JsonElement jsonElement) {
if (jsonElement == null){
return PropertyApplierResult.failure("Critical Error: TreePack properties could not be applied, jsonElement was null! This should not happen D:");
}

// If the element is a comment, ignore it and move onto next entry.
if (JsonHelper.isComment(jsonElement)) {
return PropertyApplierResult.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.tags.BiomeTags;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.level.Level;
Expand All @@ -25,6 +28,7 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.Tags;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -95,7 +99,7 @@ protected boolean postGenerate(GenFeatureConfiguration configuration, PostGenera
final LevelAccessor world = context.level();
final BlockPos rootPos = context.pos();
return world.getRandom().nextFloat() <= configuration.get(WORLD_GEN_CHANCE_FUNCTION).apply(world, rootPos) &&
this.placeBeeNestInValidPlace(configuration, world, rootPos, true);
this.placeBeeNestInValidPlace(configuration, world, rootPos, true, context.random());
}

@Override
Expand All @@ -105,10 +109,10 @@ protected boolean postGrow(GenFeatureConfiguration configuration, PostGrowContex
return false;
}

return this.placeBeeNestInValidPlace(configuration, context.level(), context.pos(), false);
return this.placeBeeNestInValidPlace(configuration, context.level(), context.pos(), false, context.random());
}

private boolean placeBeeNestInValidPlace(GenFeatureConfiguration configuration, LevelAccessor world, BlockPos rootPos, boolean worldGen) {
private boolean placeBeeNestInValidPlace(GenFeatureConfiguration configuration, LevelAccessor world, BlockPos rootPos, boolean worldGen, RandomSource random) {
Block nestBlock = configuration.get(NEST_BLOCK);

int treeHeight = getTreeHeight(world, rootPos, configuration.get(MAX_HEIGHT));
Expand All @@ -128,38 +132,28 @@ private boolean placeBeeNestInValidPlace(GenFeatureConfiguration configuration,
//There is always AT LEAST one valid direction, since if there were none the pos would not have been added to validSpaces
Direction chosenDir = chosenSpace.getValue().get(world.getRandom().nextInt(chosenSpace.getValue().size()));

return placeBeeNestWithBees(world, nestBlock, chosenSpace.getKey(), chosenDir, worldGen);
return placeBeeNestWithBees(world, nestBlock, chosenSpace.getKey(), chosenDir, worldGen, random);
}
return false;
}

private boolean placeBeeNestWithBees(LevelAccessor world, Block nestBlock, BlockPos pos, Direction faceDir, boolean worldGen) {
int honeyLevel = worldGen ? world.getRandom().nextInt(6) : 0;
private boolean placeBeeNestWithBees(LevelAccessor world, Block nestBlock, BlockPos pos, Direction faceDir, boolean worldGen, RandomSource random) {
BlockState nestState = nestBlock.defaultBlockState();
if (nestState.hasProperty(BeehiveBlock.FACING)) {
nestState = nestState.setValue(BeehiveBlock.FACING, faceDir);
}
if (nestState.hasProperty(BeehiveBlock.HONEY_LEVEL)) {
nestState = nestState.setValue(BeehiveBlock.HONEY_LEVEL, honeyLevel);
}
// Sets the nest block, but the bees still need to be added.
world.setBlock(pos, nestState, 2);
BlockEntity blockEntity = world.getBlockEntity(pos);
// Populates the bee nest with 3 bees if the nest was generated, or with 2-3 bees if it was grown.
if (blockEntity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehivetileentity = (BeehiveBlockEntity) blockEntity;
Level thisWorld = worldFromIWorld(world);
if (thisWorld == null) {
return false;
}
int beeCount = worldGen ? 3 : 2 + world.getRandom().nextInt(2);
for (int i = 0; i < beeCount; ++i) {
Bee beeEntity = new Bee(EntityType.BEE, thisWorld);
beehivetileentity.addOccupantWithPresetTicks(beeEntity, false, world.getRandom().nextInt(599));
world.setBlock(pos, nestState, 3);
world.getBlockEntity(pos, BlockEntityType.BEEHIVE).ifPresent((blockEntity) -> {
int j = 2 + random.nextInt(2);

for(int k = 0; k < j; ++k) {
CompoundTag compoundtag = new CompoundTag();
compoundtag.putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(EntityType.BEE).toString());
blockEntity.storeBee(compoundtag, random.nextInt(599), false);
}
return true;
}
return false;

});
return true;
}

//This just fetches a World instance from an IWorld instance, since IWorld cannot be used to create bees.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean run(BlockState state, LevelAccessor level, BlockPos pos, @Nullabl
if (BranchConnectables.getConnectionRadiusForBlock(state, level, pos, fromDir == null ? null : fromDir.getOpposite()) > 0) {
if (player != null && level instanceof Level) {
BlockEntity te = level.getBlockEntity(pos);
state.getBlock().onDestroyedByPlayer(state, (Level) level, pos, player, true, level.getFluidState(pos));
state.getBlock().onDestroyedByPlayer(state, (Level) level, pos, player, false, level.getFluidState(pos));
state.getBlock().playerDestroy((Level) level, player, pos, state, te, player.getMainHandItem());
} else {
level.setBlock(pos, BlockStates.AIR, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public int getUpdateSoilOnWaterRadius() {
public MangroveSpecies(ResourceLocation name, Family family, LeavesProperties leavesProperties) {
super(name, family, leavesProperties);
if (!(family instanceof MangroveFamily)) {
throw new RuntimeException("Family " + family.getRegistryName() + " for mangrove species " + getRegistryName() + "is not of type "+ MangroveFamily.class);
throw new RuntimeException("Family " + family.getRegistryName() + " for mangrove species " + getRegistryName() + " is not of type "+ MangroveFamily.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.ferreusveritas.dynamictrees.systems.genfeature.GenFeatures;
import com.ferreusveritas.dynamictrees.tree.family.Family;
import com.ferreusveritas.dynamictrees.tree.family.MangroveFamily;
import com.ferreusveritas.dynamictrees.tree.family.NetherFungusFamily;
import com.ferreusveritas.dynamictrees.util.CommonVoxelShapes;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -38,8 +39,8 @@ public class NetherFungusSpecies extends Species {

public NetherFungusSpecies(ResourceLocation name, Family family, LeavesProperties leavesProperties) {
super(name, family, leavesProperties);
if (!(family instanceof MangroveFamily)) {
LogManager.getLogger().warn("Family " + family.getRegistryName() + " for nether fungus species " + getRegistryName() + "is not of type "+ NetherFungusSpecies.class);
if (!(family instanceof NetherFungusFamily)) {
LogManager.getLogger().warn("Family " + family.getRegistryName() + " for nether fungus species " + getRegistryName() + " is not of type "+ NetherFungusFamily.class);
}
this.setSaplingShape(CommonVoxelShapes.SAPLING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class PalmSpecies extends Species {
public PalmSpecies(ResourceLocation name, Family family, LeavesProperties leavesProperties) {
super(name, family, leavesProperties);
if (!(family instanceof MangroveFamily)) {
LogManager.getLogger().warn("Family " + family.getRegistryName() + " for palm species " + getRegistryName() + "is not of type "+ PalmFamily.class);
LogManager.getLogger().warn("Family " + family.getRegistryName() + " for palm species " + getRegistryName() + " is not of type "+ PalmFamily.class);
}
if (!(leavesProperties instanceof PalmLeavesProperties))
LogManager.getLogger().warn("LeavesProperties " + leavesProperties.getRegistryName() + " for palm species " + getRegistryName() + "is not of type "+ PalmLeavesProperties.class);
LogManager.getLogger().warn("LeavesProperties " + leavesProperties.getRegistryName() + " for palm species " + getRegistryName() + " is not of type "+ PalmLeavesProperties.class);
setGrowthLogicKit(GrowthLogicKits.PALM); //palm growth logic kit by default
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;

Expand Down Expand Up @@ -576,6 +577,11 @@ public void setCommonOverride(final CommonOverride commonOverride) {
}

public boolean shouldOverrideCommon(final BlockGetter level, final BlockPos trunkPos) {
//Common Override test will fail if the server has not loaded yet
if (ServerLifecycleHooks.getCurrentServer() == null) {
LogManager.getLogger().warn("shouldOverrideCommon was called before the server was loaded. This should not happen.");
return false;
}
return this.hasCommonOverride() && this.commonOverride.test(level, trunkPos);
}

Expand Down
27 changes: 21 additions & 6 deletions src/main/resources/data/dynamictrees/recipes/guide.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{
"type": "patchouli:shapeless_book_recipe",
"ingredients": [
"type": "forge:conditional",
"recipes": [
{
"item": "minecraft:book"
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "patchouli"
}
],
"recipe": {
"type": "patchouli:shapeless_book_recipe",
"ingredients": [
{
"item": "minecraft:book"
},
{
"tag": "dynamictrees:seeds"
}
],
"book": "dynamictrees:guide"
}
},
{
"tag": "dynamictrees:seeds"
}
],
"book": "dynamictrees:guide"
]
}

0 comments on commit 1a21b76

Please sign in to comment.