22
33import com .robotgryphon .compactcrafting .CompactCrafting ;
44import com .robotgryphon .compactcrafting .blocks .FieldProjectorBlock ;
5+ import com .robotgryphon .compactcrafting .core .FieldProjectionSize ;
56import com .robotgryphon .compactcrafting .core .Registration ;
7+ import com .robotgryphon .compactcrafting .crafting .CraftingHelper ;
68import net .minecraft .block .BlockState ;
79import net .minecraft .entity .item .ItemEntity ;
810import net .minecraft .entity .player .PlayerEntity ;
2224import java .util .List ;
2325import java .util .Optional ;
2426
25- public class FieldProjectorTile extends TileEntity implements ITickableTileEntity {
27+ public class FieldProjectorTile extends TileEntity implements ITickableTileEntity {
28+
29+ private FieldProjectionSize projectionSize = FieldProjectionSize .MEDIUM ;
2630
2731 public FieldProjectorTile () {
2832 super (Registration .FIELD_PROJECTOR_TILE .get ());
@@ -34,7 +38,7 @@ public Optional<BlockPos> getCenter() {
3438
3539
3640 Optional <BlockPos > location = getOppositeProjector ();
37- if (location .isPresent ()) {
41+ if (location .isPresent ()) {
3842 BlockPos opp = location .get ();
3943 int centerOffset = opp .manhattanDistance (pos );
4044
@@ -48,21 +52,22 @@ public Optional<BlockPos> getCenter() {
4852
4953 /**
5054 * Gets the location of the opposite field projector.
55+ *
5156 * @return
5257 */
5358 public Optional <BlockPos > getOppositeProjector () {
5459 BlockState bs = this .getBlockState ();
5560 Direction facing = bs .get (FieldProjectorBlock .FACING );
5661
57- for (int i = 1 ; i <= 13 ; i ++) {
62+ for (int i = 1 ; i <= 13 ; i ++) {
5863 // check block exists in offset position
5964 BlockPos offsetInDirection = pos .offset (facing , i );
6065 BlockState stateInPos = world .getBlockState (offsetInDirection );
6166
62- if (stateInPos .getBlock () instanceof FieldProjectorBlock ) {
67+ if (stateInPos .getBlock () instanceof FieldProjectorBlock ) {
6368 // We have a field projector
6469 Direction otherFpDirection = stateInPos .get (FieldProjectorBlock .FACING );
65- if (otherFpDirection == facing .getOpposite ())
70+ if (otherFpDirection == facing .getOpposite ())
6671 return Optional .of (offsetInDirection );
6772 }
6873 }
@@ -84,49 +89,51 @@ public boolean isMainProjector() {
8489 return side == Direction .NORTH ;
8590 }
8691
92+ public FieldProjectionSize getProjectionSize () {
93+ // TODO: Make this different depending on the spacing of the field projectors
94+ return FieldProjectionSize .MEDIUM ;
95+ }
96+
8797 @ Override
8898 public void tick () {
89- if (!isMainProjector ())
99+ if (!isMainProjector ())
90100 return ;
91101
92- Optional <BlockPos > center = getCenter ();
93- if (center .isPresent ()) {
94- BlockPos c = center .get ();
95- world .addParticle (ParticleTypes .SMOKE , c .getX () + 0.5f , c .getY () + 0.5f , c .getZ () + 0.5f , 0.0D , 0.0D , 0.0D );
96- }
97-
102+ // TODO: Check crafting state of projection field, update that state instead of doing manual work here
98103 searchForCatalyst ();
99104 }
100105
101106 private void searchForCatalyst () {
102107 Optional <BlockPos > center = getCenter ();
103108
104109 // No center area - no other projector present
105- if (!center .isPresent ())
110+ if (!center .isPresent ())
106111 return ;
107112
108113 BlockPos centerPos = center .get ();
109- AxisAlignedBB itemSuckBounds = new AxisAlignedBB (centerPos ).grow (2 );
114+ FieldProjectionSize size = getProjectionSize ();
115+ AxisAlignedBB itemSuckBounds = new AxisAlignedBB (centerPos ).grow (size .getSize ());
110116
111117 try {
112118 List <ItemEntity > itemsInRange = world .getEntitiesWithinAABB (ItemEntity .class , itemSuckBounds );
113119 collectItems (centerPos , itemsInRange );
114- }
115-
116- catch (NullPointerException npe ) {
120+ } catch (NullPointerException npe ) {
117121
118122 }
119123 }
120124
121125 private void collectItems (BlockPos center , List <ItemEntity > itemsInRange ) {
122126 itemsInRange .forEach (item -> {
123- if (item .getItem ().getItem () == Items .ENDER_PEARL ) {
124- PlayerEntity closestPlayer = world .getClosestPlayer (center .getX (), center .getY (), center .getZ (), 5 , false );
127+ if (item .getItem ().getItem () == Items .ENDER_PEARL ) {
128+
129+ boolean consumedCatalyst = CraftingHelper .consumeCatalystItem (item , 1 );
125130
126- item .remove (false );
131+ if (consumedCatalyst ) {
132+ PlayerEntity closestPlayer = world .getClosestPlayer (center .getX (), center .getY (), center .getZ (), 5 , false );
127133
128- ItemStack output = new ItemStack (Items .DIAMOND , 1 );
129- closestPlayer .addItemStackToInventory (output );
134+ ItemStack output = new ItemStack (Items .DIAMOND , 1 );
135+ closestPlayer .addItemStackToInventory (output );
136+ }
130137 }
131138 });
132139 }
0 commit comments