[1.7.10] AgriCraft

  • FTB will be shutting down this forum by the end of July. To participate in our community discussions, please join our Discord! https://ftb.team/discord

nimO

New Member
Jul 29, 2019
69
0
0
heh, 20% Pseudo-random, or 1/5 didn't think it'd actually turn out like that, I'll look at it.

I took a look at the source code. You use Math.random() for every plant at every tick. This will create a new java.util.Random() object. The random seed gets usually initialized with the current time in milli or nano seconds. As nearby
crops get updated nearly at the same tick time you will get the same Random seed and as a result the same random value. As I am not very familiar with Forge I can only help with standard Java stuff.

Edit: As a solution you can use a static (shared for all plants) java.util.Random. So the psydo random algorithm can do its work as intended. Benefit is also that you severly save on java.util.Random objects created. Drawback could be thread saftey as the instance is shared and as I said above, I have pretty much no idea about forge internals.
 

InfinityRaider

New Member
Jul 29, 2019
1,169
-1
1
I took a look at the source code. You use Math.random() for every plant at every tick. This will create a new java.util.Random() object. The random seed gets usually initialized with the current time in milli or nano seconds. As nearby
crops get updated nearly at the same tick time you will get the same Random seed and as a result the same random value. As I am not very familiar with Forge I can only help with standard Java stuff.

Edit: As a solution you can use a static (shared for all plants) java.util.Random. So the psydo random algorithm can do its work as intended. Benefit is also that you severly save on java.util.Random objects created. Drawback could be thread saftey as the instance is shared and as I said above, I have pretty much no idea about forge internals.

Thanks for the info, I've made a new private Random object in the tile entity class, so each sprinkler has it's own pseude generator. What I thought what would happen by callign Math.random() instead of making a new Random generator, is that it will every time be a new random generator with a different seed. Then again, I'm not really knowledgable about java's classes :s.
 

Cobra1117

New Member
Jul 29, 2019
38
0
0
Do the crop stats work the same as IC2? (including drawbacks for high stats)

For reference, here's a copy of how the IC2 crop stats work
Growth
Pro: Increases the speed at which a plant grows and recovers after being harvested
Con: Increases the chance and speed of weeds spawning on nearby crop sticks.

Gain
Pro: Increases the number of items that are likely to drop when the plant is harvested:
Con: High gain stat lowers the chance of dropping seed bags.

Resistance
Pro: Increases the plants resistance to being killed by nearby weeds and greatly increases the chance of dropping at least one seed bag
Con: Plants with high resist will be much slower when crossbreeding.

Also, does the maturity of a plant affect the crossbreeding processes? (i.e. When crossbreeding, should crops be left unharvested.)
 

InfinityRaider

New Member
Jul 29, 2019
1,169
-1
1
Do the crop stats work the same as IC2? (including drawbacks for high stats)

For reference, here's a copy of how the IC2 crop stats work
Growth
Pro: Increases the speed at which a plant grows and recovers after being harvested
Con: Increases the chance and speed of weeds spawning on nearby crop sticks.

Gain
Pro: Increases the number of items that are likely to drop when the plant is harvested:
Con: High gain stat lowers the chance of dropping seed bags.

Resistance
Pro: Increases the plants resistance to being killed by nearby weeds and greatly increases the chance of dropping at least one seed bag
Con: Plants with high resist will be much slower when crossbreeding.

Also, does the maturity of a plant affect the crossbreeding processes? (i.e. When crossbreeding, should crops be left unharvested.)

No cons, just pros. And yes only fully mature plants will crossbreed. You can also not decrease a stat of a plant.
 

Cobra1117

New Member
Jul 29, 2019
38
0
0
No cons, just pros. And yes only fully mature plants will crossbreed. You can also not decrease a stat of a plant.

So, you basically took all the good parts of IC2 crops and threw out all the parts that sucked. Sweet! (No more weeds--you're my modding hero of the week!)

Thanks for the great mod! :)
 

nimO

New Member
Jul 29, 2019
69
0
0
So, you basically took all the good parts of IC2 crops and threw out all the parts that sucked. Sweet! (No more weeds--you're my modding hero of the week!)

Thanks for the great mod! :)

Weeds are configurable. You can enable them for some semi IC2 feeling :)
 
  • Like
Reactions: 1SDAN

InfinityRaider

New Member
Jul 29, 2019
1,169
-1
1
So, you basically took all the good parts of IC2 crops and threw out all the parts that sucked. Sweet! (No more weeds--you're my modding hero of the week!)

Thanks for the great mod! :)

Weeds are mostly to balance mutations, weeds will never sprout on crops that have a plant. If you don't like them, you can still disable ti though (just like @nimO said)
 

Cobra1117

New Member
Jul 29, 2019
38
0
0
Thanks for the info, I've made a new private Random object in the tile entity class, so each sprinkler has it's own pseude generator. What I thought what would happen by callign Math.random() instead of making a new Random generator, is that it will every time be a new random generator with a different seed. Then again, I'm not really knowledgable about java's classes :s.

This will definitely work. In Java 8 there's a ThreadLocalRandom class, but obviously you don't want to use that yet because not everyone is using Java 8 yet. If you want, you can save on objects a little bit by using a thread-local random. Here's an example:
Code:
 private static final ThreadLocal<Random> threadLocalRand =
     new ThreadLocal<Random>() {
         @Override protected Integer initialValue() {
             return new Random();
     }
};
This will allocate a single Random to each thread that tries to use it and they're automatically cleaned up if the thread terminates. In Forge it's 1 thread per dimension, if I remember correctly, so this would probably save you on object allocations. To use it you just call get() like this:
Code:
threadLocalRand.get().nextInt();
 
  • Like
Reactions: InfinityRaider

Cobra1117

New Member
Jul 29, 2019
38
0
0
Thanks, but I'm going to stick to Java 7 for now.

Ack. Should've been clear: The "ThreadLocal<Random>" solution that I posted is Java 5 and up. In Java 8 they made a convenient version called "ThreadLocalRandom" as a completely separate class. (Like I said, whatever you choose is fine--just wanted to clarify!)
 

Cobra1117

New Member
Jul 29, 2019
38
0
0
Ack. Should've been clear: The "ThreadLocal<Random>" solution that I posted is Java 5 and up. In Java 8 they made a convenient version called "ThreadLocalRandom" as a completely separate class. (Like I said, whatever you choose is fine--just wanted to clarify!)

Also, keep in mind that if you allocate a single Random to each TileEntity, all sprinklers in a chunk would be allocated at roughly the same time, so it's possible for many of them to have the same random seed. (Not exactly a big deal--just keep in mind that you may still see the event fire simultaneously in multiple locations.)
 

thephoenixlodge

New Member
Jul 29, 2019
1,388
0
0
So I'm back with another request or 2, hopefully they won't be too hard to achieve. Would it be possible to expose the defined tiers for plants with an override file so that I could, say, change the tier of a seed from 4 to 2 if I wanted to? The other thing, would it be possible to have the magic fertilizer from magic crops be able to work on crops of tier 4 or higher, as a better bonemeal, since bonemeal has no effect on those higher crops?
 

InfinityRaider

New Member
Jul 29, 2019
1,169
-1
1
So I'm back with another request or 2, hopefully they won't be too hard to achieve. Would it be possible to expose the defined tiers for plants with an override file so that I could, say, change the tier of a seed from 4 to 2 if I wanted to? The other thing, would it be possible to have the magic fertilizer from magic crops be able to work on crops of tier 4 or higher, as a better bonemeal, since bonemeal has no effect on those higher crops?
I'll consider it. This magic fertilizer is basically a more expensive bone meal that does work on magical crops right?