11package maxhyper .dtphc2 .trees ;
22
3+ import com .dtteam .dynamictrees .api .registry .RegistryHandler ;
34import com .dtteam .dynamictrees .api .registry .TypedRegistry ;
5+ import com .dtteam .dynamictrees .api .worldgen .LevelContext ;
46import com .dtteam .dynamictrees .block .leaves .LeavesProperties ;
7+ import com .dtteam .dynamictrees .item .Seed ;
58import com .dtteam .dynamictrees .systems .nodemapper .NetVolumeNode ;
9+ import com .dtteam .dynamictrees .systems .season .SeasonHelper ;
610import com .dtteam .dynamictrees .tree .family .Family ;
711import 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 ;
816import net .minecraft .resources .ResourceLocation ;
917import net .minecraft .world .item .Item ;
1018import net .minecraft .world .item .ItemStack ;
1119import net .minecraft .world .item .Items ;
20+ import net .minecraft .world .item .TooltipFlag ;
21+ import net .minecraft .world .level .Level ;
1222import net .minecraft .world .level .block .Blocks ;
1323
1424import java .util .LinkedList ;
1525import java .util .List ;
26+ import java .util .concurrent .atomic .AtomicBoolean ;
27+ import java .util .concurrent .atomic .AtomicReference ;
1628
1729public 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}
0 commit comments