Skip to content

Commit a582c14

Browse files
committed
fixes to maple, paperbark and cinnamon
1 parent e7c187a commit a582c14

24 files changed

Lines changed: 351 additions & 314 deletions

File tree

src/generated/resources/data/dtphc2/loot_table/trees/leaves/dragon_fruit.json

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/maxhyper/dtphc2/genfeatures/DripSyrupNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public boolean run(BlockState blockState, LevelAccessor world, BlockPos pos, Dir
2424
finished = true;
2525
return false;
2626
}
27-
for(Direction face : Direction.Plane.HORIZONTAL) { //Check all sides of this block
27+
for(Direction face : Direction.Plane.HORIZONTAL.shuffledCopy(world.getRandom())) { //Check all sides of this block
2828
BlockPos offPos = pos.relative(face);
2929
BlockState state = world.getBlockState(offPos);
3030
if(state.getBlock() == DTPHC2Blocks.MAPLE_SPILE_BUCKET_BLOCK.get()) { //Found a bucket

src/main/java/maxhyper/dtphc2/genfeatures/SyrupGenFeature.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
import javax.annotation.Nonnull;
1919
import java.awt.*;
2020

21-
import static net.minecraft.util.Mth.clamp;
22-
2321
public class SyrupGenFeature extends GenFeature {
2422

2523
private static final ConfigurationProperty<Float> BASE_SYRUP_CHANCE = ConfigurationProperty.floatProperty("base_syrup_chance");
2624
private static final ConfigurationProperty<Float> OUT_OF_SEASON_SYRUP_CHANCE = ConfigurationProperty.floatProperty("out_of_season_syrup_chance");
27-
private static final ConfigurationProperty<Float> SEASONAL_OFFSET = ConfigurationProperty.floatProperty("seasonal_offset");
28-
private static final ConfigurationProperty<Float> SEASONAL_RANGE = ConfigurationProperty.floatProperty("seasonal_range");
25+
public static final ConfigurationProperty<Float> SEASONAL_OFFSET = ConfigurationProperty.floatProperty("seasonal_offset");
2926
private static final ConfigurationProperty<Item> SYRUP_ITEM = ConfigurationProperty.item("syrup_item");
3027
private static final ConfigurationProperty<String> TINT = ConfigurationProperty.string("tint");
3128

@@ -35,7 +32,7 @@ public SyrupGenFeature(ResourceLocation registryName) {
3532

3633
@Override
3734
protected void registerProperties() {
38-
this.register(BASE_SYRUP_CHANCE, OUT_OF_SEASON_SYRUP_CHANCE, SYRUP_ITEM, SEASONAL_OFFSET, SEASONAL_RANGE, TINT);
35+
this.register(BASE_SYRUP_CHANCE, OUT_OF_SEASON_SYRUP_CHANCE, SYRUP_ITEM, SEASONAL_OFFSET, TINT);
3936
}
4037

4138
@Nonnull
@@ -46,7 +43,6 @@ public GenFeatureConfiguration createDefaultConfiguration() {
4643
.with(OUT_OF_SEASON_SYRUP_CHANCE, 0.001F)
4744
.with(SYRUP_ITEM, Items.AIR)
4845
.with(SEASONAL_OFFSET, 3.5F)
49-
.with(SEASONAL_RANGE, 1.0F)
5046
.with(TINT, "#FF00FF");//ugly purple to show that its missing
5147
}
5248

@@ -70,16 +66,17 @@ public boolean postGrow(@Nonnull GenFeatureConfiguration configuration, @Nonnull
7066

7167
//Update syrup extract rate depending on seasons
7268
public double getSyrupChance(LevelContext world, BlockPos pos, GenFeatureConfiguration config) {
73-
Float season = SeasonHelper.getSeasonValue(world, pos);
74-
float offset = config.get(SEASONAL_OFFSET);
75-
float range = config.get(SEASONAL_RANGE);
76-
ConfigurationProperty<Float> chanceProp = (season == null || SeasonHelper.isSeasonBetween(season, offset, offset + range)) ? BASE_SYRUP_CHANCE : OUT_OF_SEASON_SYRUP_CHANCE;
77-
float chance = config.get(chanceProp);
78-
return clamp(chance, 0.0f, 1.0f);
69+
float factor = seasonalFruitProductionFactor(world, pos, config);
70+
return Math.max(factor * config.get(BASE_SYRUP_CHANCE), config.get(OUT_OF_SEASON_SYRUP_CHANCE));
7971
}
8072

8173
private void dripSyrup(LevelAccessor world, BlockPos rootPos) {
8274
TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(new DripSyrupNode()));
8375
}
8476

77+
public float seasonalFruitProductionFactor(LevelContext levelContext, BlockPos pos, GenFeatureConfiguration config) {
78+
float season = SeasonHelper.getSeasonValue(levelContext, pos);
79+
return config.getAsOptional(SEASONAL_OFFSET).isPresent() ? SeasonHelper.globalSeasonalFruitProductionFactor(levelContext, new BlockPos(0,(int)(season*64),-1), -config.get(SEASONAL_OFFSET), true) : 1.0F;
80+
}
81+
8582
}

src/main/java/maxhyper/dtphc2/init/RegisterJSONAppliers.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public static void registerSpeciesAppliers(PropertyAppliers<Species, JsonElement
3535
GenOnExtraSoilSpecies::setExtraSoil)
3636
.register("log_drop_item", FruitLogSpecies.class, Item.class, FruitLogSpecies::setDropItem)
3737
//.register("log_drop_item", FruitLogSpecies.class, ResourceLocation.class, FruitLogSpecies::setDropItem)
38-
.register("log_drop_multiplier", FruitLogSpecies.class, Float.class, FruitLogSpecies::setMultiplier)
39-
.register("log_drop_fake_log", FruitLogSpecies.class, Item.class, FruitLogSpecies::setFakeLog);
38+
.register("log_drop_item_multiplier", FruitLogSpecies.class, Float.class, FruitLogSpecies::setItemMultiplier)
39+
.register("log_drop_fake_log", FruitLogSpecies.class, Item.class, FruitLogSpecies::setFakeLog)
40+
.register("log_drop_fake_log_multiplier", FruitLogSpecies.class, Float.class, FruitLogSpecies::setFakeLogMultiplier);
4041
}
4142

4243
// public static void registerFruitAppliers(PropertyAppliers<Fruit, JsonElement> appliers) {

src/main/java/maxhyper/dtphc2/items/FruitVineItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ public FruitVineItem(FruitVineBlock pBlock, Properties pProperties) {
2424

2525
@Override
2626
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
27-
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
2827
Level level = context.level();
2928
if (level == null) return;
3029
if (SeasonHelper.getSeasonValue(LevelContext.create(level), BlockPos.ZERO) == null) return;
3130
int flags = getSeasonalTooltipFlags(level);
3231

3332
if (flags != 0) {
34-
tooltipComponents.add(Component.literal("desc.dynamictrees.seasonal.fertile_seasons").append(":"));
33+
tooltipComponents.add(Component.translatable("desc.dynamictrees.seasonal.fertile_seasons").append(":"));
3534

3635
if ((flags & 15) == 15) {
3736
tooltipComponents.add(Component.literal(" ").append(Component.translatable("desc.sereneseasons.year_round").withStyle(ChatFormatting.LIGHT_PURPLE)));
@@ -50,6 +49,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
5049
}
5150
}
5251
}
52+
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
5353
}
5454

5555
public int getSeasonalTooltipFlags(final Level world) {

src/main/java/maxhyper/dtphc2/trees/FruitLogSpecies.java

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
package maxhyper.dtphc2.trees;
22

3+
import com.dtteam.dynamictrees.api.registry.RegistryHandler;
34
import com.dtteam.dynamictrees.api.registry.TypedRegistry;
5+
import com.dtteam.dynamictrees.api.worldgen.LevelContext;
46
import com.dtteam.dynamictrees.block.leaves.LeavesProperties;
7+
import com.dtteam.dynamictrees.item.Seed;
58
import com.dtteam.dynamictrees.systems.nodemapper.NetVolumeNode;
9+
import com.dtteam.dynamictrees.systems.season.SeasonHelper;
610
import com.dtteam.dynamictrees.tree.family.Family;
711
import com.dtteam.dynamictrees.tree.species.Species;
12+
import maxhyper.dtphc2.genfeatures.SyrupGenFeature;
13+
import net.minecraft.ChatFormatting;
14+
import net.minecraft.core.BlockPos;
15+
import net.minecraft.network.chat.Component;
816
import net.minecraft.resources.ResourceLocation;
917
import net.minecraft.world.item.Item;
1018
import net.minecraft.world.item.ItemStack;
1119
import net.minecraft.world.item.Items;
20+
import net.minecraft.world.item.TooltipFlag;
21+
import net.minecraft.world.level.Level;
1222
import net.minecraft.world.level.block.Blocks;
1323

1424
import java.util.LinkedList;
1525
import java.util.List;
26+
import java.util.concurrent.atomic.AtomicBoolean;
27+
import java.util.concurrent.atomic.AtomicReference;
1628

1729
public class FruitLogSpecies extends Species {
1830

1931
public static final TypedRegistry.EntryType<Species> TYPE = createDefaultType(FruitLogSpecies::new);
2032

2133
//private ResourceLocation dropItemLoc = new ResourceLocation("air");
2234
private Item dropItem = null;
23-
private float multiplier = 1;
35+
private float item_multiplier = 1;
36+
private float fake_log_multiplier = 1;
2437
private Item fakeLog = Items.AIR;
2538

2639
public FruitLogSpecies(ResourceLocation name, Family family, LeavesProperties leavesProperties) {
@@ -44,7 +57,7 @@ public LogsAndSticks getLogsAndSticks(NetVolumeNode.Volume volume, boolean silkT
4457
}
4558
} else {
4659
if (dropItem != Items.AIR) {
47-
int itemVol = (int)(vol * multiplier);
60+
int itemVol = (int)(vol * item_multiplier);
4861
ItemStack stack = new ItemStack(dropItem);
4962
while (itemVol > 0) {
5063
ItemStack drop = stack.copy();
@@ -54,7 +67,7 @@ public LogsAndSticks getLogsAndSticks(NetVolumeNode.Volume volume, boolean silkT
5467
}
5568
}
5669
if (fakeLog != Items.AIR){
57-
int logVol = vol;
70+
int logVol = (int)(vol * fake_log_multiplier);
5871
ItemStack logStack = new ItemStack(fakeLog);
5972
while (logVol > 0) {
6073
ItemStack drop = logStack.copy();
@@ -74,11 +87,90 @@ public void setDropItem(Item item) {
7487
this.dropItem = item;
7588
}
7689

77-
public void setMultiplier(float multiplier) {
78-
this.multiplier = multiplier;
90+
public void setItemMultiplier(float multiplier) {
91+
this.item_multiplier = multiplier;
92+
}
93+
94+
public void setFakeLogMultiplier(float multiplier) {
95+
this.fake_log_multiplier = multiplier;
7996
}
8097

8198
public void setFakeLog(Item fakeLog) {
8299
this.fakeLog = fakeLog;
83100
}
101+
102+
//Appends seasonal hover text to trees that use the Syrup gen feature (maple trees).
103+
@Override
104+
public Species generateSeed() {
105+
return this.shouldGenerateSeed() && this.seed == null ? this.setSeed(RegistryHandler.addItem(this.getSeedName(), () -> new Seed(this){
106+
@Override
107+
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
108+
Level level = context.level();
109+
if (level == null) return;
110+
if (SeasonHelper.getSeasonValue(LevelContext.create(level), BlockPos.ZERO) == null) return;
111+
int flags = getSeasonalTooltipFlags(LevelContext.create(level));
112+
113+
if (flags != 0) {
114+
tooltipComponents.add(Component.translatable("desc.dynamictrees.seasonal.fertile_seasons").append(":"));
115+
116+
if ((flags & 15) == 15) {
117+
tooltipComponents.add(Component.literal(" ").append(Component.translatable("desc.sereneseasons.year_round").withStyle(ChatFormatting.LIGHT_PURPLE)));
118+
} else {
119+
if ((flags & 1) != 0) {
120+
tooltipComponents.add(Component.literal(" ").append(Component.translatable("desc.sereneseasons.spring").withStyle(ChatFormatting.GREEN)));
121+
}
122+
if ((flags & 2) != 0) {
123+
tooltipComponents.add(Component.literal(" ").append(Component.translatable("desc.sereneseasons.summer").withStyle(ChatFormatting.YELLOW)));
124+
}
125+
if ((flags & 4) != 0) {
126+
tooltipComponents.add(Component.literal(" ").append(Component.translatable("desc.sereneseasons.autumn").withStyle(ChatFormatting.GOLD)));
127+
}
128+
if ((flags & 8) != 0) {
129+
tooltipComponents.add(Component.literal(" ").append(Component.translatable("desc.sereneseasons.winter").withStyle(ChatFormatting.AQUA)));
130+
}
131+
}
132+
}
133+
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
134+
}
135+
136+
public int getSeasonalTooltipFlags(LevelContext levelContext) {
137+
final float seasonStart = 1f / 6;
138+
final float seasonEnd = 1 - 1f / 6;
139+
final float threshold = 0.75f;
140+
141+
AtomicReference<Float> seasonOffset = new AtomicReference<>();
142+
AtomicBoolean found = new AtomicBoolean(false);
143+
getSpecies().getGenFeatures().forEach(gf->{
144+
if (gf.getGenFeature() instanceof SyrupGenFeature){
145+
seasonOffset.set(gf.get(SyrupGenFeature.SEASONAL_OFFSET));
146+
found.set(true);
147+
}
148+
});
149+
if (!found.get()) return 0;
150+
151+
int seasonFlags = 0;
152+
153+
for(int i = 0; i < 4; ++i) {
154+
boolean isValidSeason = false;
155+
if (seasonOffset.get() != null) {
156+
float prod1 = SeasonHelper.globalSeasonalFruitProductionFactor(levelContext, new BlockPos(0, (int)(((float)i + seasonStart - seasonOffset.get()) * 64.0F), 0), true);
157+
float prod2 = SeasonHelper.globalSeasonalFruitProductionFactor(levelContext, new BlockPos(0, (int)(((float)i + seasonEnd - seasonOffset.get()) * 64.0F), 0), true);
158+
if (Math.min(prod1, prod2) > threshold) {
159+
isValidSeason = true;
160+
}
161+
} else {
162+
isValidSeason = true;
163+
}
164+
165+
if (isValidSeason) {
166+
seasonFlags |= 1 << i;
167+
}
168+
}
169+
170+
return seasonFlags;
171+
172+
}
173+
174+
})) : this;
175+
}
84176
}

src/main/java/maxhyper/dtphc2/trees/PaperbarkFamily.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ public void stripBranch(BlockState state, Level world, BlockPos pos, Player play
5050
}
5151

5252
@Override
53-
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource rand) {
53+
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource rand) {
5454
if (rand.nextFloat() < barkRegrowChance && isStrippedBranch()){
55-
int radius = TreeHelper.getRadius(world, pos);
56-
int radiusDown = TreeHelper.isBranch(world.getBlockState(pos.below())) ? TreeHelper.getRadius(world, pos.below()) : getMaxRadius();
57-
this.getFamily().getBranch().ifPresent(branch -> branch.setRadius(world, pos,
55+
int radius = TreeHelper.getRadius(level, pos);
56+
int radiusDown = TreeHelper.isBranch(level.getBlockState(pos.below())) ? TreeHelper.getRadius(level, pos.below()) : getMaxRadius();
57+
this.getFamily().getBranch().ifPresent(branch -> branch.setRadius(level, pos,
5858
Math.min(radiusDown, radius + (Services.CONFIG.getBoolConfig(IConfigHelper.ENABLE_STRIP_RADIUS_REDUCTION) ? 1 : 0)),
5959
null
6060
)
6161
);
6262
}
63-
super.tick(state, world, pos, rand);
63+
super.randomTick(state, level, pos, rand);
6464
}
65+
6566
};
6667
if (this.isFireProof()) branch.setFireSpreadSpeed(0).setFlammability(0);
6768
return branch;

src/generated/resources/data/dtphc2/loot_table/blocks/banana_leaves.json renamed to src/main/resources/data/dtphc2/loot_table/blocks/banana_leaves.json

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,6 @@
3838
}
3939
],
4040
"name": "minecraft:jungle_leaves"
41-
},
42-
{
43-
"type": "dynamictrees:seed_item",
44-
"conditions": [
45-
{
46-
"condition": "minecraft:survives_explosion"
47-
},
48-
{
49-
"chances": [
50-
0.015625,
51-
0.03125,
52-
0.046875,
53-
0.0625
54-
],
55-
"condition": "minecraft:table_bonus",
56-
"enchantment": "minecraft:fortune"
57-
},
58-
{
59-
"condition": "dynamictrees:seasonal_seed_drop_chance"
60-
}
61-
]
6241
}
6342
]
6443
}

0 commit comments

Comments
 (0)