-
Notifications
You must be signed in to change notification settings - Fork 79
/
TileEntityBlockChiseled.java
869 lines (725 loc) · 21.4 KB
/
TileEntityBlockChiseled.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
package mod.chiselsandbits.chiseledblock;
import java.util.Collection;
import java.util.Collections;
import mod.chiselsandbits.api.EventBlockBitPostModification;
import mod.chiselsandbits.api.EventFullBlockRestoration;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob.BlobStats;
import mod.chiselsandbits.chiseledblock.data.VoxelBlobStateReference;
import mod.chiselsandbits.chiseledblock.data.VoxelNeighborRenderTracker;
import mod.chiselsandbits.client.UndoTracker;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.Log;
import mod.chiselsandbits.core.api.BitAccess;
import mod.chiselsandbits.helpers.DeprecationHelper;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.integration.mcmultipart.MCMultipartProxy;
import mod.chiselsandbits.interfaces.IChiseledTileContainer;
import mod.chiselsandbits.render.chiseledblock.ChiseledBlockSmartModel;
import mod.chiselsandbits.render.chiseledblock.tesr.ChisledBlockRenderChunkTESR;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityBlockChiseled extends TileEntity implements IChiseledTileContainer
{
private IExtendedBlockState state;
public IChiseledTileContainer occlusionState;
boolean isNormalCube = false;
int sideState = 0;
int lightlevel = 0;
public TileEntityBlockChiseled()
{
}
public IChiseledTileContainer getTileContainer()
{
if ( occlusionState != null )
{
return occlusionState;
}
return this;
}
@Override
public boolean isBlobOccluded(
final VoxelBlob blob )
{
return false;
}
@Override
public void saveData()
{
super.markDirty();
}
@Override
public void sendUpdate()
{
ModUtil.sendUpdate( worldObj, pos );
}
public void copyFrom(
final TileEntityBlockChiseled src )
{
state = src.state;
isNormalCube = src.isNormalCube;
sideState = src.sideState;
lightlevel = src.lightlevel;
}
public IExtendedBlockState getBasicState()
{
return getState( false, 0, worldObj );
}
public IExtendedBlockState getRenderState(
final IBlockAccess access )
{
return getState( true, 1, access );
}
protected IExtendedBlockState getState(
final boolean updateNeightbors,
final int updateCost,
final IBlockAccess access )
{
if ( state == null )
{
return (IExtendedBlockState) ChiselsAndBits.getBlocks().getChiseledDefaultState();
}
if ( updateNeightbors )
{
final boolean isDyanmic = this instanceof TileEntityBlockChiseledTESR;
final VoxelNeighborRenderTracker vns = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );
if ( vns == null )
{
return state;
}
vns.update( isDyanmic, access, pos );
tesrUpdate( access, vns );
final TileEntityBlockChiseled self = this;
if ( vns.isAboveLimit() && !isDyanmic )
{
ChisledBlockRenderChunkTESR.addNextFrameTask( new Runnable() {
@Override
public void run()
{
if ( self.worldObj != null && self.pos != null )
{
final TileEntity current = self.worldObj.getTileEntity( self.pos );
final TileEntityBlockChiseled dat = MCMultipartProxy.proxyMCMultiPart.getChiseledTileEntity( self.worldObj, self.pos, false );
if ( current == null || self.isInvalid() )
{
return;
}
if ( current == self )
{
current.invalidate();
final TileEntityBlockChiseledTESR TESR = new TileEntityBlockChiseledTESR();
TESR.copyFrom( self );
self.worldObj.removeTileEntity( self.pos );
self.worldObj.setTileEntity( self.pos, TESR );
self.worldObj.markBlockRangeForRenderUpdate( self.pos, self.pos );
vns.unlockDynamic();
}
else if ( dat == self )
{
MCMultipartProxy.proxyMCMultiPart.convertTo( current, new TileEntityBlockChiseledTESR() );
vns.unlockDynamic();
}
}
}
} );
}
else if ( !vns.isAboveLimit() && isDyanmic )
{
ChisledBlockRenderChunkTESR.addNextFrameTask( new Runnable() {
@Override
public void run()
{
if ( self.worldObj != null && self.pos != null )
{
final TileEntity current = self.worldObj.getTileEntity( self.pos );
final TileEntityBlockChiseled dat = MCMultipartProxy.proxyMCMultiPart.getChiseledTileEntity( self.worldObj, self.pos, false );
if ( current == null || self.isInvalid() )
{
return;
}
if ( current == self )
{
current.invalidate();
final TileEntityBlockChiseled nonTesr = new TileEntityBlockChiseled();
nonTesr.copyFrom( self );
self.worldObj.removeTileEntity( self.pos );
self.worldObj.setTileEntity( self.pos, nonTesr );
self.worldObj.markBlockRangeForRenderUpdate( self.pos, self.pos );
vns.unlockDynamic();
}
else if ( dat == self )
{
MCMultipartProxy.proxyMCMultiPart.convertTo( current, new TileEntityBlockChiseled() );
vns.unlockDynamic();
}
}
}
} );
}
}
return state;
}
protected void tesrUpdate(
final IBlockAccess access,
final VoxelNeighborRenderTracker vns )
{
}
public BlockBitInfo getBlockInfo(
final Block alternative )
{
return BlockBitInfo.getBlockInfo( getBlockState( alternative ) );
}
public IBlockState getBlockState(
final Block alternative )
{
final Integer stateID = getBasicState().getValue( BlockChiseled.UProperty_Primary_BlockState );
if ( stateID != null )
{
final IBlockState state = ModUtil.getStateById( stateID );
if ( state != null )
{
return state;
}
}
return alternative.getDefaultState();
}
public void setState(
final IExtendedBlockState state )
{
final VoxelBlobStateReference originalRef = getBasicState().getValue( BlockChiseled.UProperty_VoxelBlob );
final VoxelBlobStateReference newRef = state.getValue( BlockChiseled.UProperty_VoxelBlob );
this.state = state;
if ( originalRef != null && newRef != null && !newRef.equals( originalRef ) )
{
final EventBlockBitPostModification bmm = new EventBlockBitPostModification( getWorld(), getPos() );
MinecraftForge.EVENT_BUS.post( bmm );
}
}
@Override
public boolean shouldRefresh(
final World world,
final BlockPos pos,
final IBlockState oldState,
final IBlockState newState )
{
return oldState.getBlock() != newState.getBlock();
}
@Override
public SPacketUpdateTileEntity getUpdatePacket()
{
final NBTTagCompound nbttagcompound = new NBTTagCompound();
writeChisleData( nbttagcompound );
if ( nbttagcompound.hasNoTags() )
{
return null;
}
return new SPacketUpdateTileEntity( pos, 255, nbttagcompound );
}
@Override
public NBTTagCompound getUpdateTag()
{
final NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setInteger( "x", pos.getX() );
nbttagcompound.setInteger( "y", pos.getY() );
nbttagcompound.setInteger( "z", pos.getZ() );
writeChisleData( nbttagcompound );
return nbttagcompound;
}
@Override
public void handleUpdateTag(
final NBTTagCompound tag )
{
readChisleData( tag );
}
@Override
public void onDataPacket(
final NetworkManager net,
final SPacketUpdateTileEntity pkt )
{
final boolean changed = readChisleData( pkt.getNbtCompound() );
if ( worldObj != null && changed )
{
worldObj.markBlockRangeForRenderUpdate( pos, pos );
triggerDynamicUpdates();
}
}
/**
* look at near by TESRs and re-render them.
*/
private void triggerDynamicUpdates()
{
if ( worldObj.isRemote && state != null )
{
final VoxelNeighborRenderTracker vns = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );
// will it update anyway?
if ( vns != null && vns.isDynamic() )
{
return;
}
for ( final EnumFacing f : EnumFacing.VALUES )
{
final BlockPos p = getPos().offset( f );
if ( worldObj.isBlockLoaded( p ) )
{
final TileEntity te = worldObj.getTileEntity( p );
if ( te instanceof TileEntityBlockChiseledTESR )
{
final TileEntityBlockChiseledTESR tesr = (TileEntityBlockChiseledTESR) te;
if ( tesr.getRenderChunk() != null )
{
tesr.getRenderChunk().rebuild( false );
}
}
}
}
}
}
public boolean readChisleData(
final NBTTagCompound tag )
{
final boolean changed = new NBTBlobConverter( false, this ).readChisleData( tag );
final VoxelNeighborRenderTracker vns = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );
if ( vns != null )
{
vns.triggerUpdate();
}
return changed;
}
public void writeChisleData(
final NBTTagCompound tag )
{
new NBTBlobConverter( false, this ).writeChisleData( tag, false );
}
@Override
public NBTTagCompound writeToNBT(
final NBTTagCompound compound )
{
super.writeToNBT( compound );
writeChisleData( compound );
return compound;
}
@Override
public void readFromNBT(
final NBTTagCompound compound )
{
super.readFromNBT( compound );
readChisleData( compound );
}
@Override
public void func_189668_a(
final Mirror p_189668_1_ )
{
switch ( p_189668_1_ )
{
case FRONT_BACK:
setBlob( getBlob().mirror( Axis.X ), true );
break;
case LEFT_RIGHT:
setBlob( getBlob().mirror( Axis.Z ), true );
break;
case NONE:
default:
break;
}
}
@Override
public void func_189667_a(
final Rotation p_189667_1_ )
{
switch ( p_189667_1_ )
{
case CLOCKWISE_90:
setBlob( getBlob().spin( Axis.Y ).spin( Axis.Y ).spin( Axis.Y ), true );
break;
case CLOCKWISE_180:
setBlob( getBlob().spin( Axis.Y ).spin( Axis.Y ), true );
break;
case COUNTERCLOCKWISE_90:
setBlob( getBlob().spin( Axis.Y ), true );
break;
case NONE:
default:
break;
}
}
public void fillWith(
final IBlockState blockType )
{
final int ref = ModUtil.getStateId( blockType );
sideState = 0xff;
lightlevel = DeprecationHelper.getLightValue( blockType );
isNormalCube = ModUtil.isNormalCube( blockType );
IExtendedBlockState state = getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( ModUtil.getStateId( blockType ), getPositionRandom( pos ) ) );
final VoxelNeighborRenderTracker tracker = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );
if ( tracker == null )
{
state = state.withProperty( BlockChiseled.UProperty_VoxelNeighborState, new VoxelNeighborRenderTracker() );
}
else
{
tracker.isDynamic();
}
// required for placing bits
if ( ref != 0 )
{
state = state.withProperty( BlockChiseled.UProperty_Primary_BlockState, ref );
}
setState( state );
getTileContainer().saveData();
}
private long getPositionRandom(
final BlockPos pos )
{
if ( pos != null && FMLCommonHandler.instance().getSide() == Side.CLIENT )
{
return MathHelper.getPositionRandom( pos );
}
return 0;
}
public VoxelBlobStateReference getBlobStateReference()
{
return getBasicState().getValue( BlockChiseled.UProperty_VoxelBlob );
}
public VoxelBlob getBlob()
{
VoxelBlob vb = null;
final VoxelBlobStateReference vbs = getBlobStateReference();
if ( vbs != null )
{
vb = vbs.getVoxelBlob();
if ( vb == null )
{
vb = new VoxelBlob();
vb.fill( ModUtil.getStateId( Blocks.COBBLESTONE.getDefaultState() ) );
}
}
else
{
vb = new VoxelBlob();
}
return vb;
}
public IBlockState getPreferedBlock()
{
return ChiselsAndBits.getBlocks().getConversionWithDefault( getBlockState( Blocks.STONE ) ).getDefaultState();
}
public void setBlob(
final VoxelBlob vb )
{
setBlob( vb, true );
}
public boolean updateBlob(
final NBTBlobConverter converter,
final boolean triggerUpdates )
{
final int oldLV = getLightValue();
final boolean oldNC = isNormalCube();
final int oldSides = sideState;
final VoxelBlobStateReference originalRef = getBasicState().getValue( BlockChiseled.UProperty_VoxelBlob );
VoxelBlobStateReference voxelRef = null;
sideState = converter.getSideState();
final int b = converter.getPrimaryBlockStateID();
lightlevel = converter.getLightValue();
isNormalCube = converter.isNormalCube();
try
{
voxelRef = converter.getVoxelRef( VoxelBlob.VERSION_COMPACT, getPositionRandom( pos ) );
}
catch ( final Exception e )
{
if ( getPos() != null )
{
Log.logError( "Unable to read blob at " + getPos(), e );
}
else
{
Log.logError( "Unable to read blob.", e );
}
voxelRef = new VoxelBlobStateReference( 0, getPositionRandom( pos ) );
}
IExtendedBlockState newstate = getBasicState()
.withProperty( BlockChiseled.UProperty_Primary_BlockState, b )
.withProperty( BlockChiseled.UProperty_VoxelBlob, voxelRef );
final VoxelNeighborRenderTracker tracker = newstate.getValue( BlockChiseled.UProperty_VoxelNeighborState );
if ( tracker == null )
{
newstate = newstate.withProperty( BlockChiseled.UProperty_VoxelNeighborState, new VoxelNeighborRenderTracker() );
}
else
{
tracker.isDynamic();
}
setState( newstate );
if ( hasWorldObj() && triggerUpdates )
{
if ( oldLV != getLightValue() || oldNC != isNormalCube() )
{
worldObj.checkLight( pos );
}
if ( oldSides != sideState )
{
worldObj.notifyNeighborsOfStateChange( pos, worldObj.getBlockState( pos ).getBlock() );
}
}
return voxelRef != null ? !voxelRef.equals( originalRef ) : true;
}
public void setBlob(
final VoxelBlob vb,
final boolean triggerUpdates )
{
final Integer olv = getLightValue();
final Boolean oldNC = isNormalCube();
final BlobStats common = vb.getVoxelStats();
final float light = common.blockLight;
final boolean nc = common.isNormalBlock;
final int lv = Math.max( 0, Math.min( 15, (int) ( light * 15 ) ) );
// are most of the bits in the center solid?
final int sideFlags = vb.getSideFlags( 5, 11, 4 * 4 );
if ( worldObj == null )
{
if ( common.mostCommonState == 0 )
{
common.mostCommonState = getBasicState().getValue( BlockChiseled.UProperty_Primary_BlockState );
}
sideState = sideFlags;
lightlevel = lv;
isNormalCube = nc;
IExtendedBlockState newState = getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( vb.blobToBytes( VoxelBlob.VERSION_COMPACT ), getPositionRandom( pos ) ) )
.withProperty( BlockChiseled.UProperty_VoxelNeighborState, new VoxelNeighborRenderTracker() )
.withProperty( BlockChiseled.UProperty_Primary_BlockState, common.mostCommonState );
final VoxelNeighborRenderTracker tracker = newState.getValue( BlockChiseled.UProperty_VoxelNeighborState );
if ( tracker == null )
{
newState = newState.withProperty( BlockChiseled.UProperty_VoxelNeighborState, new VoxelNeighborRenderTracker() );
}
else
{
tracker.isDynamic();
}
setState( newState );
return;
}
if ( common.isFullBlock )
{
setState( getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( common.mostCommonState, getPositionRandom( pos ) ) ) );
final IBlockState newState = ModUtil.getStateById( common.mostCommonState );
if ( !MinecraftForge.EVENT_BUS.post( new EventFullBlockRestoration( worldObj, pos, newState ) ) )
{
worldObj.setBlockState( pos, newState, triggerUpdates ? 3 : 0 );
}
}
else if ( common.mostCommonState != 0 )
{
sideState = sideFlags;
lightlevel = lv;
isNormalCube = nc;
setState( getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( vb.blobToBytes( VoxelBlob.VERSION_COMPACT ), getPositionRandom( pos ) ) )
.withProperty( BlockChiseled.UProperty_Primary_BlockState, common.mostCommonState ) );
getTileContainer().saveData();
getTileContainer().sendUpdate();
// since its possible for bits to occlude parts.. update every time.
final Block blk = worldObj.getBlockState( pos ).getBlock();
MCMultipartProxy.proxyMCMultiPart.triggerPartChange( worldObj.getTileEntity( pos ) );
worldObj.notifyBlockOfStateChange( pos, blk );
if ( triggerUpdates )
{
worldObj.notifyNeighborsOfStateChange( pos, blk );
}
}
else
{
setState( getBasicState()
.withProperty( BlockChiseled.UProperty_VoxelBlob, new VoxelBlobStateReference( 0, getPositionRandom( pos ) ) ) );
ModUtil.removeChisledBlock( worldObj, pos );
}
if ( olv != lv || oldNC != nc )
{
worldObj.checkLight( pos );
}
}
static private class ItemStackGeneratedCache
{
public ItemStackGeneratedCache(
final ItemStack itemstack,
final VoxelBlobStateReference blobStateReference,
final int rotations2 )
{
out = itemstack == null ? null : itemstack.copy();
ref = blobStateReference;
rotations = rotations2;
}
final ItemStack out;
final VoxelBlobStateReference ref;
final int rotations;
public ItemStack getItemStack()
{
return out == null ? null : out.copy();
}
};
/**
* prevent mods that constantly ask for pick block from killing the
* client... ( looking at you waila )
**/
private ItemStackGeneratedCache pickcache = null;
public ItemStack getItemStack(
final EntityPlayer player )
{
final ItemStackGeneratedCache cache = pickcache;
if ( player != null )
{
EnumFacing enumfacing = ModUtil.getPlaceFace( player );
final int rotations = ModUtil.getRotationIndex( enumfacing );
if ( cache != null && cache.rotations == rotations && cache.ref == getBlobStateReference() && cache.out != null )
{
return cache.getItemStack();
}
VoxelBlob vb = getBlob();
int countDown = rotations;
while ( countDown > 0 )
{
countDown--;
enumfacing = enumfacing.rotateYCCW();
vb = vb.spin( Axis.Y );
}
final BitAccess ba = new BitAccess( null, null, vb, VoxelBlob.NULL_BLOB );
final ItemStack itemstack = ba.getBitsAsItem( enumfacing, ItemType.CHISLED_BLOCK, false );
pickcache = new ItemStackGeneratedCache( itemstack, getBlobStateReference(), rotations );
return itemstack;
}
else
{
if ( cache != null && cache.rotations == 0 && cache.ref == getBlobStateReference() )
{
return cache.getItemStack();
}
final BitAccess ba = new BitAccess( null, null, getBlob(), VoxelBlob.NULL_BLOB );
final ItemStack itemstack = ba.getBitsAsItem( null, ItemType.CHISLED_BLOCK, false );
pickcache = new ItemStackGeneratedCache( itemstack, getBlobStateReference(), 0 );
return itemstack;
}
}
public boolean isNormalCube()
{
return isNormalCube;
}
public boolean isSideSolid(
final EnumFacing side )
{
return ( sideState & 1 << side.ordinal() ) != 0;
}
@SideOnly( Side.CLIENT )
public boolean isSideOpaque(
final EnumFacing side )
{
final VoxelNeighborRenderTracker vns = state != null ? state.getValue( BlockChiseled.UProperty_VoxelNeighborState ) : null;
if ( vns != null && vns.isDynamic() )
{
return false;
}
final Integer sideFlags = ChiseledBlockSmartModel.getSides( this );
return ( sideFlags & 1 << side.ordinal() ) != 0;
}
public void completeEditOperation(
final VoxelBlob vb )
{
final VoxelBlobStateReference before = getBlobStateReference();
setBlob( vb );
final VoxelBlobStateReference after = getBlobStateReference();
if ( worldObj != null )
{
worldObj.markBlockRangeForRenderUpdate( pos, pos );
triggerDynamicUpdates();
}
UndoTracker.getInstance().add( getWorld(), getPos(), before, after );
}
public void rotateBlock(
final EnumFacing axis )
{
final VoxelBlob occluded = new VoxelBlob();
MCMultipartProxy.proxyMCMultiPart.addFiller( getWorld(), getPos(), occluded );
VoxelBlob postRotation = getBlob();
int maxRotations = 4;
while ( --maxRotations > 0 )
{
postRotation = postRotation.spin( axis.getAxis() );
if ( occluded.canMerge( postRotation ) )
{
setBlob( postRotation );
return;
}
}
}
public boolean canMerge(
final VoxelBlob voxelBlob )
{
final VoxelBlob vb = getBlob();
final IChiseledTileContainer occ = getTileContainer();
if ( vb.canMerge( voxelBlob ) && !occ.isBlobOccluded( voxelBlob ) )
{
return true;
}
return false;
}
public Collection<AxisAlignedBB> getBoxes(
final BoxType type )
{
final VoxelBlobStateReference ref = getBlobStateReference();
if ( ref != null )
{
return ref.getBoxes( type );
}
else
{
return Collections.emptyList();
}
}
@Override
public AxisAlignedBB getRenderBoundingBox()
{
final BlockPos p = getPos();
return new AxisAlignedBB( p.getX(), p.getY(), p.getZ(), p.getX() + 1, p.getY() + 1, p.getZ() + 1 );
}
public void setNormalCube(
final boolean b )
{
isNormalCube = b;
}
public int getLightValue()
{
return lightlevel;
}
@Override
public void invalidate()
{
if ( worldObj != null )
{
triggerDynamicUpdates();
}
}
}