@@ -129,119 +129,12 @@ public int GetRuntimeId()
129129
130130 public virtual Item GetItem ( )
131131 {
132- if ( ! BlockFactory . BlockStates . TryGetValue ( GetState ( ) , out BlockStateContainer stateFromPick ) ) return null ;
133-
134- if ( stateFromPick . ItemInstance != null ) return ItemFactory . GetItem ( stateFromPick . ItemInstance . Id , stateFromPick . ItemInstance . Metadata ) ;
135-
136- // The rest of this code is to search for an state with the proper value. This is caused by blocks that have lots
137- // of states, and no easy way to map 1-1 with meta. Expensive, but rare.
138-
139- // Only compare with states that actually have the values we checking for, and have meta.
140- var statesWithMeta = BlockFactory . BlockPalette . Values . Where ( b => b . Name == stateFromPick . Name && b . Data != - 1 ) . ToList ( ) ;
141- foreach ( IBlockState state in stateFromPick . States . ToArray ( ) )
142- {
143- bool remove = true ;
144- foreach ( BlockStateContainer blockStateContainer in statesWithMeta )
145- {
146- foreach ( IBlockState currentState in blockStateContainer . States )
147- {
148- if ( currentState . Name != state . Name ) continue ;
149-
150- if ( ! currentState . Equals ( state ) )
151- {
152- remove = false ;
153- break ;
154- }
155- }
156- }
157- if ( remove ) stateFromPick . States . Remove ( state ) ;
158- }
159-
160- foreach ( BlockStateContainer blockStateContainer in statesWithMeta )
161- {
162- bool match = true ;
163-
164- foreach ( IBlockState currentState in blockStateContainer . States )
165- {
166- if ( stateFromPick . States . All ( s => s . Name != currentState . Name ) ) continue ;
167-
168- if ( stateFromPick . States . All ( state => ! state . Equals ( currentState ) ) )
169- {
170- Log . Debug ( $ "State: { currentState . Name } , { currentState } ") ;
171-
172- match = false ;
173- break ;
174- }
175- }
176- if ( match )
177- {
178- var id = blockStateContainer . Id ;
179- var meta = blockStateContainer . Data ;
180-
181- var statesWithMetaAndItem = statesWithMeta . Where ( b => b . ItemInstance != null ) . ToList ( ) ;
182- var actualState = statesWithMetaAndItem . FirstOrDefault ( s => s . Id == id && s . Data == meta && s . ItemInstance != null ) ;
183- if ( actualState == null ) break ;
184- return ItemFactory . GetItem ( actualState . ItemInstance . Id , actualState . ItemInstance . Metadata ) ;
185- }
186- }
187-
188- // Ok that didn't give an item. Lets try more stuff.
189-
190- // Remove states that repeat. They can not contribute to a meta-variant.
191- //BUG: There might be states that have more than one. Don't know.
192- foreach ( BlockStateContainer stateContainer in statesWithMeta )
193- {
194- foreach ( var state in stateContainer . States . ToArray ( ) )
195- {
196- var states = statesWithMeta . SelectMany ( m => m . States ) . ToList ( ) ;
197- if ( states . Count ( s => s . Equals ( state ) ) > 1 )
198- {
199- if ( stateFromPick . States . FirstOrDefault ( s => s . Name == state . Name ) != null )
200- {
201- stateFromPick . States . Remove ( stateFromPick . States . First ( s => s . Name == state . Name ) ) ;
202- }
203- }
204- }
205- }
206-
207- if ( stateFromPick . States . Count == 0 )
132+ var id = Id ;
133+ if ( id > 255 )
208134 {
209- var stateToPick = statesWithMeta . FirstOrDefault ( ) ;
210- if ( stateToPick ? . ItemInstance != null )
211- {
212- return ItemFactory . GetItem ( stateToPick . ItemInstance . Id , stateToPick . ItemInstance . Metadata ) ;
213- }
214- }
215-
216- foreach ( BlockStateContainer blockStateContainer in statesWithMeta )
217- {
218- bool match = true ;
219-
220- foreach ( IBlockState currentState in blockStateContainer . States )
221- {
222- if ( stateFromPick . States . All ( s => s . Name != currentState . Name ) ) continue ;
223-
224- if ( stateFromPick . States . All ( state => ! state . Equals ( currentState ) ) )
225- {
226- Log . Debug ( $ "State: { currentState . Name } , { currentState } ") ;
227-
228- match = false ;
229- break ;
230- }
231- }
232- if ( match )
233- {
234- var id = blockStateContainer . Id ;
235- var meta = blockStateContainer . Data ;
236-
237- var statesWithMetaAndItem = statesWithMeta . Where ( b => b . ItemInstance != null ) . ToList ( ) ;
238- var actualState = statesWithMetaAndItem . FirstOrDefault ( s => s . Id == id && s . Data == meta && s . ItemInstance != null ) ;
239- if ( actualState == null ) break ;
240- return ItemFactory . GetItem ( actualState . ItemInstance . Id , actualState . ItemInstance . Metadata ) ;
241- }
135+ id = - ( id - 255 ) ;
242136 }
243-
244- return null ;
137+ return ItemFactory . GetItem ( ( short ) id , Metadata , 1 ) ;
245138 }
246139
247140 public bool CanPlace ( Level world , Player player , BlockCoordinates targetCoordinates , BlockFace face )
@@ -353,6 +246,11 @@ public virtual Item[] GetDrops(Item tool)
353246 return new [ ] { item } ;
354247 }
355248
249+ public virtual bool IsBestTool ( Item item )
250+ {
251+ return false ;
252+ }
253+
356254 public virtual Item GetSmelt ( )
357255 {
358256 return null ;
0 commit comments