Skip to content

Commit 5d89495

Browse files
committed
fixed crash with saccharine leaves
1 parent 037d7bc commit 5d89495

4 files changed

Lines changed: 32 additions & 35 deletions

File tree

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod_id=dtcobblemon
33
mod_name=DynamicTrees-Cobblemon
44
mod_display_name=DynamicTrees for Cobblemon
55
mod_license=MIT
6-
mod_version=1.2.0-BETA03
6+
mod_version=1.2.0-BETA04
77
mod_group_id=com.dtteam.dtcobblemon
88
mod_authors= Nyfaria, Max Hyper
99
mod_credits=
@@ -12,8 +12,8 @@ mod_description=Compatibility mood between Dynamic Trees and Cobblemon
1212
versionType=beta
1313

1414
## Dependencies
15-
dynamictrees_version=1.5.0
16-
dynamictreesplus_version=1.3.0-BETA03
15+
dynamictrees_version=1.5.1
16+
dynamictreesplus_version=1.3.0-BETA04
1717
cobblemon_file=7247564
1818
cc_version=1.116.2
1919

src/main/java/com/dtteam/dtcobblemon/leaves/DynamicSaccharineLeavesBlock.java

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.dtteam.dtcobblemon.leaves;
22

3-
import com.bedrockk.molang.runtime.value.DoubleValue;
4-
import com.cobblemon.mod.common.entity.MoLangScriptingEntity;
53
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
64
import com.dtteam.dynamictrees.block.leaves.DynamicLeavesBlock;
75
import com.dtteam.dynamictrees.block.leaves.LeavesProperties;
@@ -38,27 +36,24 @@
3836
import net.minecraft.world.level.pathfinder.PathComputationType;
3937
import net.minecraft.world.level.pathfinder.PathType;
4038
import net.minecraft.world.phys.BlockHitResult;
41-
import net.minecraft.world.phys.shapes.CollisionContext;
42-
import net.minecraft.world.phys.shapes.EntityCollisionContext;
43-
import net.minecraft.world.phys.shapes.Shapes;
4439
import net.minecraft.world.phys.shapes.VoxelShape;
4540
import org.jetbrains.annotations.NotNull;
4641
import org.jetbrains.annotations.Nullable;
4742

4843
public class DynamicSaccharineLeavesBlock extends DynamicLeavesBlock {
4944

50-
public static final IntegerProperty AGE = BlockStateProperties.AGE_2;
51-
public static final int MAX_AGE = 2;
52-
public static final int MIN_AGE = 0;
45+
public static final IntegerProperty HONEY = BlockStateProperties.AGE_2;
46+
public static final int MAX_HONEY = 2;
47+
public static final int MIN_HONEY = 0;
5348

5449
public DynamicSaccharineLeavesBlock(LeavesProperties leavesProperties, Properties properties) {
5550
super(leavesProperties, properties);
56-
registerDefaultState(defaultBlockState().setValue(AGE, MIN_AGE));
51+
registerDefaultState(defaultBlockState().setValue(HONEY, MIN_HONEY));
5752
}
5853

5954
@Override
6055
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
61-
builder.add(AGE);
56+
builder.add(HONEY);
6257
super.createBlockStateDefinition(builder);
6358
}
6459

@@ -81,9 +76,11 @@ public int updateHydro(LevelAccessor accessor, BlockPos pos, BlockState state, b
8176
}
8277
}
8378

84-
private @NotNull BlockState getLeavesBlockStateForPlacementWithHoney(LevelAccessor accessor, BlockPos pos, BlockState oldState,BlockState newHydroState, boolean worldGen, int oldHydro) {
85-
int honey = oldState.getValue(AGE);
86-
if (newHydroState.hasProperty(AGE)) newHydroState = newHydroState.setValue(AGE, honey);
79+
private @NotNull BlockState getLeavesBlockStateForPlacementWithHoney(LevelAccessor accessor, BlockPos pos, BlockState oldState, BlockState newHydroState, boolean worldGen, int oldHydro) {
80+
if (oldState.hasProperty(HONEY)){
81+
int honey = oldState.getValue(HONEY);
82+
if (newHydroState.hasProperty(HONEY)) newHydroState = newHydroState.setValue(HONEY, honey);
83+
}
8784
return this.getLeavesBlockStateForPlacement(accessor, pos, newHydroState, oldHydro, worldGen);
8885
}
8986

@@ -110,7 +107,7 @@ protected boolean isPathfindable(BlockState state, PathComputationType pathCompu
110107
@Override
111108
public SoundType getSoundType(BlockState state, LevelReader level, BlockPos pos, @Nullable Entity entity) {
112109
SoundType defaultType = super.getSoundType(state, level, pos, entity);
113-
if (state.hasProperty(AGE) && state.getValue(AGE) > MIN_AGE)
110+
if (state.hasProperty(HONEY) && state.getValue(HONEY) > MIN_HONEY)
114111
return new SoundType(defaultType.volume, defaultType.pitch, defaultType.getBreakSound(), SoundEvents.HONEY_BLOCK_STEP, defaultType.getPlaceSound(), SoundEvents.HONEY_BLOCK_HIT, SoundEvents.HONEY_BLOCK_FALL);
115112
return defaultType;
116113
}
@@ -122,17 +119,17 @@ public boolean isRandomlyTicking(BlockState state) {
122119

123120
@Override
124121
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
125-
int currentAge = state.getValue(AGE);
122+
int currentAge = state.getValue(HONEY);
126123

127-
if (currentAge > MIN_AGE && random.nextInt(2) == 0) {
124+
if (currentAge > MIN_HONEY && random.nextInt(2) == 0) {
128125
for (int i = 1; i <= 10; i++) {
129126
BlockPos belowPos = pos.below(i);
130127
BlockState belowState = world.getBlockState(belowPos);
131128

132129
if (!belowState.isAir()) {
133130
if (belowState.getBlock() instanceof DynamicSaccharineLeavesBlock) {
134-
int belowAge = belowState.getValue(AGE);
135-
if (belowAge < MAX_AGE) {
131+
int belowAge = belowState.getValue(HONEY);
132+
if (belowAge < MAX_HONEY) {
136133
world.setBlock(pos, changeAge(state, -1), Block.UPDATE_CLIENTS);
137134
world.setBlock(belowPos, changeAge(belowState, 1), Block.UPDATE_CLIENTS);
138135
}
@@ -148,11 +145,11 @@ public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random
148145
@Override
149146
public boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state, FluidState fluidState) {
150147
if (!state.getValue(WATERLOGGED) && fluidState.getType() == Fluids.WATER) {
151-
boolean hasHoney = state.getValue(AGE) > 0;
148+
boolean hasHoney = state.getValue(HONEY) > 0;
152149

153150
if (!level.isClientSide()) {
154151
BlockState newState = state.setValue(WATERLOGGED, true);
155-
if (hasHoney) newState = newState.setValue(AGE, 0);
152+
if (hasHoney) newState = newState.setValue(HONEY, 0);
156153

157154
level.setBlock(pos, newState, 3);
158155
level.scheduleTick(pos, fluidState.getType(), fluidState.getType().getTickDelay(level));
@@ -171,11 +168,11 @@ public boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state,
171168
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
172169
int particleCount = random.nextInt(3);
173170

174-
if (state.getValue(AGE) == 1) {
171+
if (state.getValue(HONEY) == 1) {
175172
for (int i = 0; i < particleCount; i++) {
176173
spawnHoneyParticles(level, pos, state, 0.025F);
177174
}
178-
} else if (state.getValue(AGE) == 2) {
175+
} else if (state.getValue(HONEY) == 2) {
179176
for (int i = 0; i < particleCount; i++) {
180177
spawnHoneyParticles(level, pos, state, 0.05F);
181178
}
@@ -238,15 +235,15 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level
238235
player.addItem(new ItemStack(Items.HONEY_BOTTLE));
239236

240237
level.playSound(null, pos, SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS);
241-
level.setBlock(pos, state.setValue(AGE, 0), 2);
238+
level.setBlock(pos, state.setValue(HONEY, 0), 2);
242239
level.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
243240

244241
return ItemInteractionResult.SUCCESS;
245242
} else if (isHoneyBottle && !isAtMaxAge(state)) {
246243
item.consume(1, player);
247244

248245
level.playSound(null, pos, SoundEvents.HONEY_BLOCK_PLACE, SoundSource.BLOCKS);
249-
level.setBlock(pos, state.setValue(AGE, 2), 2);
246+
level.setBlock(pos, state.setValue(HONEY, 2), 2);
250247
level.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
251248

252249
return ItemInteractionResult.SUCCESS;
@@ -257,16 +254,16 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level
257254
}
258255

259256
private boolean isAtMaxAge(BlockState state) {
260-
return state.getValue(AGE) == MAX_AGE;
257+
return state.getValue(HONEY) == MAX_HONEY;
261258
}
262259

263260
private boolean isAtMinAge(BlockState state) {
264-
return state.getValue(AGE) == MIN_AGE;
261+
return state.getValue(HONEY) == MIN_HONEY;
265262
}
266263

267264
private BlockState changeAge(BlockState state, int value) {
268-
int newAge = Mth.clamp(state.getValue(AGE) + value, MIN_AGE, MAX_AGE);
269-
return state.setValue(AGE, newAge);
265+
int newAge = Mth.clamp(state.getValue(HONEY) + value, MIN_HONEY, MAX_HONEY);
266+
return state.setValue(HONEY, newAge);
270267
}
271268

272269
private void spawnDestroyHoneyParticles(Level level, BlockPos pos, BlockState state) {
@@ -292,7 +289,7 @@ private void spawnDestroyHoneyParticles(Level level, BlockPos pos, BlockState st
292289
@Override
293290
public void spawnDestroyParticles(Level level, Player player, BlockPos pos, BlockState state) {
294291
spawnDestroyHoneyParticles(level, pos, state);
295-
super.spawnDestroyParticles(level, player, pos, state.setValue(AGE, state.getValue(AGE)));
292+
super.spawnDestroyParticles(level, player, pos, state.setValue(HONEY, state.getValue(HONEY)));
296293
}
297294
}
298295

src/main/java/com/dtteam/dtcobblemon/mixin/BeeEntityMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public class BeeEntityMixin {
2323
private void injectCustomGrowth(CallbackInfo ci, @Local(ordinal = 0) BlockState blockState, @Local Block block) {
2424
if (block instanceof DynamicSaccharineLeavesBlock) {
2525

26-
int age = blockState.getValue(DynamicSaccharineLeavesBlock.AGE);
26+
int age = blockState.getValue(DynamicSaccharineLeavesBlock.HONEY);
2727
boolean waterlogged = blockState.getValue(BlockStateProperties.WATERLOGGED);
2828

2929
if (age < 2 && !waterlogged) {
30-
this.dtcobblemon$result = blockState.setValue(DynamicSaccharineLeavesBlock.AGE, age + 1);
30+
this.dtcobblemon$result = blockState.setValue(DynamicSaccharineLeavesBlock.HONEY, age + 1);
3131
}
3232
}
3333
}

src/main/java/com/dtteam/dtcobblemon/mixin/SacLeavesSensorMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private void isValidLeafBlock(BlockState state, CallbackInfoReturnable<Boolean>
1919
&& state.getValue(BlockStateProperties.WATERLOGGED)) {
2020
cir.setReturnValue(false);
2121
}
22-
cir.setReturnValue(state.getValue(DynamicSaccharineLeavesBlock.AGE) != DynamicSaccharineLeavesBlock.MAX_AGE);
22+
cir.setReturnValue(state.getValue(DynamicSaccharineLeavesBlock.HONEY) != DynamicSaccharineLeavesBlock.MAX_HONEY);
2323
}
2424
}
2525

0 commit comments

Comments
 (0)