-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
src/main/java/gregtechfoodoption/machines/farmer/ChorusFarmerMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package gregtechfoodoption.machines.farmer; | ||
|
||
import gregtechfoodoption.utils.GTFOUtils; | ||
import it.unimi.dsi.fastutil.PriorityQueue; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayPriorityQueue; | ||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockChorusFlower; | ||
import net.minecraft.block.BlockChorusPlant; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.init.Blocks; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.NonNullList; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.*; | ||
|
||
|
||
public class ChorusFarmerMode implements FarmerMode { | ||
@Override | ||
public boolean canOperate(IBlockState blockState, MetaTileEntityFarmer farmer, BlockPos pos, World world) { | ||
if (blockState.getBlock() != Blocks.CHORUS_PLANT && blockState.getBlock() != Blocks.CHORUS_FLOWER) | ||
return false; | ||
for (Iterator<BlockPos> it = getChorusIterator(pos, world); it.hasNext(); ) { | ||
IBlockState state = world.getBlockState(it.next()); | ||
if (state.getBlock() == Blocks.CHORUS_FLOWER && state.getValue(BlockChorusFlower.AGE) != 5) { | ||
return false; // Let all flowers grow | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private Iterator<BlockPos> getChorusIterator(BlockPos pos, World world) { | ||
return new Iterator<>() { | ||
final PriorityQueue<BlockPos> plantQueue = new ObjectArrayPriorityQueue<>(new BlockPos[]{pos}); | ||
final Set<BlockPos> visited = new ObjectOpenHashSet<>(); | ||
|
||
final World myWorld = world; | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return !plantQueue.isEmpty(); | ||
} | ||
|
||
@Override | ||
public BlockPos next() { | ||
BlockPos blockPos = plantQueue.dequeue(); | ||
visited.add(blockPos); | ||
IBlockState state = myWorld.getBlockState(blockPos); | ||
if (state.getPropertyKeys().contains(BlockChorusPlant.UP)) { | ||
state = Blocks.CHORUS_PLANT.getActualState(state, myWorld, blockPos); | ||
if (state.getValue(BlockChorusPlant.UP)) { | ||
add(blockPos.up()); | ||
} | ||
if (state.getValue(BlockChorusPlant.EAST)) { | ||
add(blockPos.east()); | ||
} | ||
if (state.getValue(BlockChorusPlant.WEST)) { | ||
add(blockPos.west()); | ||
} | ||
if (state.getValue(BlockChorusPlant.NORTH)) { | ||
add(blockPos.north()); | ||
} | ||
if (state.getValue(BlockChorusPlant.SOUTH)) { | ||
add(blockPos.south()); | ||
} | ||
} | ||
return blockPos; | ||
} | ||
|
||
private void add(BlockPos pos) { | ||
if (!visited.contains(pos)) { | ||
plantQueue.enqueue(pos); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public List<ItemStack> getDrops(IBlockState blockState, World world, BlockPos.MutableBlockPos pos, MetaTileEntityFarmer farmer) { | ||
NonNullList<ItemStack> drops = NonNullList.create(); | ||
for (Iterator<BlockPos> it = getChorusIterator(pos, world); it.hasNext(); ) { | ||
IBlockState state = world.getBlockState(it.next()); | ||
if (state.getBlock() == Blocks.CHORUS_FLOWER) { | ||
drops.add(new ItemStack(Blocks.CHORUS_FLOWER, 1)); // Because the normal function isn't very nice. | ||
} else { | ||
state.getBlock().getDrops(drops, world, pos, state, 0); | ||
} | ||
} | ||
return drops; | ||
} | ||
|
||
@Override | ||
public boolean canPlaceItem(ItemStack stack) { | ||
return stack.isItemEqual(new ItemStack(Blocks.CHORUS_FLOWER)); | ||
} | ||
|
||
@Override | ||
public void harvest(IBlockState state, World world, BlockPos.MutableBlockPos pos, MetaTileEntityFarmer farmer) { | ||
List<BlockPos> blocks = new ArrayList<>(); | ||
for (Iterator<BlockPos> it = getChorusIterator(pos, world); it.hasNext(); ) { | ||
blocks.add(it.next()); | ||
} | ||
Collections.sort(blocks); | ||
for (int i = blocks.size() - 1; i >= 0; i--) { | ||
world.playEvent(2001, blocks.get(i), Block.getStateId(state)); | ||
world.setBlockToAir(blocks.get(i)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/gregtechfoodoption/recipe/chain/ChorusChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package gregtechfoodoption.recipe.chain; | ||
|
||
public class ChorusChain { | ||
public static void init() { | ||
|
||
} | ||
} |
Empty file.