mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 04:09:40 +00:00
Use a set of blocks for pure daisy recipe sync, closes #3289
This adds a new type of pure daisy input which matches against a set of blocks. Clients receive the full set of blocks instead of a tag name. Bumped the network version to account for this change.
This commit is contained in:
1 parent
1d5bf56f26
commit
baee6d2a6f
4 files changed
+83
-7
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import vazkii.botania.api.recipe.StateIngredient;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StateIngredientBlocks implements StateIngredient {
|
||||
private final Set<Block> blocks;
|
||||
|
||||
public StateIngredientBlocks(Set<Block> blocks) {
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockState state) {
|
||||
return blocks.contains(state.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject serialize() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("type", "blocks");
|
||||
JsonArray array = new JsonArray();
|
||||
for (Block block : blocks) {
|
||||
array.add(block.getRegistryName().toString());
|
||||
}
|
||||
object.add("blocks", array);
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer) {
|
||||
buffer.writeVarInt(0);
|
||||
buffer.writeVarInt(blocks.size());
|
||||
for (Block block : blocks) {
|
||||
buffer.writeRegistryIdUnsafe(ForgeRegistries.BLOCKS, block);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> getDisplayed() {
|
||||
return blocks.stream().map(Block::getDefaultState).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user