30
30
import baritone .utils .BlockStateInterface ;
31
31
import baritone .utils .Helper ;
32
32
import net .minecraft .block .Block ;
33
+ import net .minecraft .entity .Entity ;
34
+ import net .minecraft .entity .item .EntityItem ;
33
35
import net .minecraft .init .Blocks ;
34
36
import net .minecraft .item .Item ;
35
37
import net .minecraft .item .ItemStack ;
36
38
import net .minecraft .util .math .BlockPos ;
39
+ import net .minecraft .world .World ;
37
40
import net .minecraft .world .chunk .EmptyChunk ;
38
41
39
42
import java .util .*;
45
48
* @author leijurv
46
49
*/
47
50
public final class MineBehavior extends Behavior implements IMineBehavior , Helper {
48
-
51
+ public static final int ORE_LOCATIONS_COUNT = 64 ;
49
52
private List <Block > mining ;
50
53
private List <BlockPos > knownOreLocations ;
51
54
private BlockPos branchPoint ;
@@ -91,7 +94,7 @@ private void updateGoal() {
91
94
}
92
95
List <BlockPos > locs = knownOreLocations ;
93
96
if (!locs .isEmpty ()) {
94
- List <BlockPos > locs2 = prune (new ArrayList <>(locs ), mining , 64 );
97
+ List <BlockPos > locs2 = prune (new ArrayList <>(locs ), mining , ORE_LOCATIONS_COUNT , world () );
95
98
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
96
99
baritone .getPathingBehavior ().setGoalAndPath (new GoalComposite (locs2 .stream ().map (loc -> coalesce (loc , locs2 )).toArray (Goal []::new )));
97
100
knownOreLocations = locs2 ;
@@ -127,7 +130,8 @@ private void rescan() {
127
130
if (Baritone .settings ().legitMine .get ()) {
128
131
return ;
129
132
}
130
- List <BlockPos > locs = searchWorld (mining , 64 );
133
+ List <BlockPos > locs = searchWorld (mining , ORE_LOCATIONS_COUNT , world ());
134
+ locs .addAll (droppedItemsScan (mining , world ()));
131
135
if (locs .isEmpty ()) {
132
136
logDebug ("No locations for " + mining + " known, cancelling" );
133
137
mine (0 , (String []) null );
@@ -158,7 +162,30 @@ private static Goal coalesce(BlockPos loc, List<BlockPos> locs) {
158
162
}
159
163
}
160
164
161
- public List <BlockPos > searchWorld (List <Block > mining , int max ) {
165
+ public static List <BlockPos > droppedItemsScan (List <Block > mining , World world ) {
166
+ if (!Baritone .settings ().mineScanDroppedItems .get ()) {
167
+ return new ArrayList <>();
168
+ }
169
+ Set <Item > searchingFor = new HashSet <>();
170
+ for (Block block : mining ) {
171
+ Item drop = block .getItemDropped (block .getDefaultState (), new Random (), 0 );
172
+ Item ore = Item .getItemFromBlock (block );
173
+ searchingFor .add (drop );
174
+ searchingFor .add (ore );
175
+ }
176
+ List <BlockPos > ret = new ArrayList <>();
177
+ for (Entity entity : world .loadedEntityList ) {
178
+ if (entity instanceof EntityItem ) {
179
+ EntityItem ei = (EntityItem ) entity ;
180
+ if (searchingFor .contains (ei .getItem ().getItem ())) {
181
+ ret .add (entity .getPosition ());
182
+ }
183
+ }
184
+ }
185
+ return ret ;
186
+ }
187
+
188
+ public static List <BlockPos > searchWorld (List <Block > mining , int max , World world ) {
162
189
List <BlockPos > locs = new ArrayList <>();
163
190
List <Block > uninteresting = new ArrayList <>();
164
191
//long b = System.currentTimeMillis();
@@ -178,7 +205,7 @@ public List<BlockPos> searchWorld(List<Block> mining, int max) {
178
205
locs .addAll (WorldScanner .INSTANCE .scanChunkRadius (uninteresting , max , 10 , 26 ));
179
206
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
180
207
}
181
- return prune (locs , mining , max );
208
+ return prune (locs , mining , max , world );
182
209
}
183
210
184
211
public void addNearby () {
@@ -194,15 +221,16 @@ public void addNearby() {
194
221
}
195
222
}
196
223
}
197
- knownOreLocations = prune (knownOreLocations , mining , 64 );
224
+ knownOreLocations = prune (knownOreLocations , mining , ORE_LOCATIONS_COUNT , world () );
198
225
}
199
226
200
- public List <BlockPos > prune (List <BlockPos > locs2 , List <Block > mining , int max ) {
227
+ public static List <BlockPos > prune (List <BlockPos > locs2 , List <Block > mining , int max , World world ) {
228
+ List <BlockPos > dropped = droppedItemsScan (mining , world );
201
229
List <BlockPos > locs = locs2
202
230
.stream ()
203
231
204
232
// remove any that are within loaded chunks that aren't actually what we want
205
- .filter (pos -> world () .getChunk (pos ) instanceof EmptyChunk || mining .contains (BlockStateInterface .get (pos ).getBlock ()))
233
+ .filter (pos -> world .getChunk (pos ) instanceof EmptyChunk || mining .contains (BlockStateInterface .get (pos ).getBlock ()) || dropped . contains ( pos ))
206
234
207
235
// remove any that are implausible to mine (encased in bedrock, or touching lava)
208
236
.filter (MineBehavior ::plausibleToBreak )
0 commit comments