Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.World;
import net.modificationstation.sltest.item.ItemListener;
import net.modificationstation.stationapi.api.block.BlockState;
import net.modificationstation.stationapi.api.block.CustomFarmlandBlock;
import net.modificationstation.stationapi.api.util.Identifier;
import net.modificationstation.stationapi.api.state.StateManager;
import net.modificationstation.stationapi.api.state.property.EnumProperty;
Expand All @@ -14,8 +15,7 @@

import java.util.List;

public class VariationBlock extends TemplateBlock {

public class VariationBlock extends TemplateBlock implements CustomFarmlandBlock {
public enum Variant implements StringIdentifiable {
IDLE,
PASSIVE,
Expand Down Expand Up @@ -46,4 +46,9 @@ public List<ItemStack> getDropList(World level, int x, int y, int z, BlockState
case ACTIVE -> ItemListener.variationBlockActive;
}));
}

@Override
public boolean isWet(World world, int x, int y, int z) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.modificationstation.sltest.tooltip;

import net.mine_diver.unsafeevents.listener.EventListener;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.modificationstation.stationapi.api.block.context.BlockTagContext;
import net.modificationstation.stationapi.api.client.event.gui.screen.container.TooltipBuildEvent;
import net.modificationstation.stationapi.api.item.context.ItemTagContext;
import net.modificationstation.stationapi.api.tag.TagKey;
import net.modificationstation.stationapi.api.util.Formatting;

public class TooltipEventListener {
@EventListener
public void addTagsToTooltip(TooltipBuildEvent event) {
ItemStack stack = event.itemStack;

event.tooltip.add(Formatting.DARK_PURPLE + "Item Tags:");
for (TagKey<Item> tag : stack.getItem().getRegistryEntry().getTags(ItemTagContext.of(stack))) {
event.tooltip.add(" " + Formatting.LIGHT_PURPLE + tag.id().toString());
}


if (stack.getItem() instanceof BlockItem blockItem) {
event.tooltip.add("");
event.tooltip.add(Formatting.DARK_PURPLE + "Block Tags:");
Block placedBlock = blockItem.getBlock();
for (TagKey<Block> tag : placedBlock.getRegistryEntry().getTags(BlockTagContext.of(blockItem.getPlacementMetadata(stack.getDamage())))) {
event.tooltip.add(" " + Formatting.LIGHT_PURPLE + tag.id().toString());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:variation_block"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"remove": [
"#c:crops/pumpkin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"remove": [
"#c:crops/pumpkin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "minecraft:crafting_shaped",
"pattern":
[
"pwl",
"pwl",
"pwl"
],
"key":
{
"p":
{
"tag": "c:dyes/pink"
},
"w":
{
"tag": "c:dyes/white"
},
"l":
{
"tag": "c:dyes/light_blue"
}
},
"result":
{
"item": "sltest:test_item",
"count": 67
}
}
3 changes: 2 additions & 1 deletion src/test/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"net.modificationstation.sltest.keyboard.KeyboardListener",
"net.modificationstation.sltest.texture.TextureListener",
"net.modificationstation.sltest.render.entity.EntityRendererListener",
"net.modificationstation.sltest.render.ModelLoadingListener"
"net.modificationstation.sltest.render.ModelLoadingListener",
"net.modificationstation.sltest.tooltip.TooltipEventListener"
],
"main": [
"net.modificationstation.sltest.MainTest"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.modificationstation.stationapi.api.block;

import net.minecraft.world.World;

public interface CustomFarmlandBlock {
boolean isWet(World world, int x, int y, int z);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public final class BlockTags {
WOODEN_TRAPDOORS = of("c:trapdoors/wooden"),
OAK_TRAPDOORS = of("c:trapdoors/wooden/oak"),
WOOLS = of("c:wools"),
FARMLANDS = of("c:farmlands"),
NORMAL_FARMLANDS = of("c:farmlands/normal"),

INFINIBURN = of("infiniburn"),
MINEABLE_AXE = of("mineable/axe"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.modificationstation.stationapi.mixin.block;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.block.Block;
import net.minecraft.block.CropBlock;
import net.minecraft.block.PlantBlock;
import net.minecraft.world.World;
import net.modificationstation.stationapi.api.block.BlockState;
import net.modificationstation.stationapi.api.block.CustomFarmlandBlock;
import net.modificationstation.stationapi.api.block.context.BlockTagContext;
import net.modificationstation.stationapi.api.registry.tag.BlockTags;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(CropBlock.class)
class CropBlockMixin extends PlantBlockMixin {
@Override
protected boolean stationapi_injectCanPlantOnTopCanPlaceAt(PlantBlock plantBlock, int id, Operation<Boolean> original, World world, int x, int y, int z) {
BlockState state = world.getBlockState(x, y - 1, z);
if (state.isIn(BlockTags.FARMLANDS, BlockTagContext.of(world, x, y - 1, z))) {
return true;
}

return original.call(plantBlock, id);
}

@Override
protected boolean stationapi_injectCanPlantOnTopCanGrow(PlantBlock plantBlock, int id, Operation<Boolean> original, World world, int x, int y, int z) {
BlockState state = world.getBlockState(x, y - 1, z);
if (state.isIn(BlockTags.FARMLANDS, BlockTagContext.of(world, x, y - 1, z))) {
return true;
}

return original.call(plantBlock, id);
}


@WrapOperation(method = "getAvailableMoisture", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockId(III)I", ordinal = 8))
private int stationapi_getCustomFarmlandMoisturable(World world, int x, int y, int z, Operation<Integer> original) {
int result = original.call(world, x, y, z);

if (result != Block.FARMLAND.id) {
BlockState state = world.getBlockState(x, y, z);
if (state.isIn(BlockTags.FARMLANDS, BlockTagContext.of(world, x, y, z))) {
return Block.FARMLAND.id;
}
}

return result;
}

@WrapOperation(method = "getAvailableMoisture", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockMeta(III)I"))
private int stationapi_getCustomFarmlandWet(World world, int x, int y, int z, Operation<Integer> original) {
Block block = Block.BLOCKS[world.getBlockId(x, y, z)];

if (block != Block.FARMLAND && block instanceof CustomFarmlandBlock customFarmlandBlock) {
return customFarmlandBlock.isWet(world, x, y, z) ? 7 : 0;
}

return original.call(world, x, y, z);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.modificationstation.stationapi.mixin.block;

import net.minecraft.block.FarmlandBlock;
import net.minecraft.world.World;
import net.modificationstation.stationapi.api.block.CustomFarmlandBlock;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(FarmlandBlock.class)
class FarmlandBlockMixin implements CustomFarmlandBlock {
@Override
public boolean isWet(World world, int x, int y, int z) {
return world.getBlockMeta(x, y, z) > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.modificationstation.stationapi.mixin.block;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.PlantBlock;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@SuppressWarnings("LocalMayUseName")
@Mixin(PlantBlock.class)
class PlantBlockMixin {
@WrapOperation(method = "canPlaceAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/PlantBlock;canPlantOnTop(I)Z"))
protected boolean stationapi_injectCanPlantOnTopCanPlaceAt(PlantBlock plantBlock, int id, Operation<Boolean> original, @Local(argsOnly = true, ordinal = 0) World world, @Local(argsOnly = true, ordinal = 0) int x, @Local(argsOnly = true, ordinal = 1) int y, @Local(argsOnly = true, ordinal = 2) int z) {
return original.call(plantBlock, id);
}

@WrapOperation(method = "canGrow", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/PlantBlock;canPlantOnTop(I)Z"))
protected boolean stationapi_injectCanPlantOnTopCanGrow(PlantBlock plantBlock, int id, Operation<Boolean> original, @Local(argsOnly = true, ordinal = 0) World world, @Local(argsOnly = true, ordinal = 0) int x, @Local(argsOnly = true, ordinal = 1) int y, @Local(argsOnly = true, ordinal = 2) int z) {
return original.call(plantBlock, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"mixins": [
"BlockItemMixin",
"BlockMixin",
"CropBlockMixin",
"FarmlandBlockMixin",
"FireBlockMixin",
"LeavesBlockMixin",
"PlantBlockMixin",
"SecondaryBlockItemMixin"
],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ interface BlockTagContextDelegate extends BlockTagContext, Delegate {}
return (BlockTagContextDelegate) () -> data;
}

static BlockTagContext of(int meta) {
Context data = Context.of(BlockContext.BLOCK_METADATA_KEY, meta);
interface BlockTagContextDelegate extends BlockTagContext, Delegate {}
return (BlockTagContextDelegate) () -> data;
}

static BlockTagContext of(Context context) {
if (context instanceof BlockTagContext b) return b;
interface BlockTagContextDelegate extends BlockTagContext, Delegate {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public final class ItemTags {
LEATHER_LEGGINGS = of("c:armors/leggings/leather"),
BONES = of("c:bones"),
BOOKSHELVES = of("c:bookshelves"),
WOODEN_BOWLS = of("c:bowls/wooden"),
BOWLS = of("c:bowls"),
BRICK_BLOCKS = of("c:brick_blocks"),
NORMAL_BRICK_BLOCKS = of("c:brick_blocks/normal"),
BRICKS = of("c:bricks"),
Expand All @@ -48,7 +50,6 @@ public final class ItemTags {
WATER_BUCKETS = of("c:buckets/water"),
BUTTONS = of("c:buttons"),
STONE_BUTTONS = of("c:buttons/stone"),
CACTI = of("c:cacti"),
CHESTS = of("c:chests"),
WOODEN_CHESTS = of("c:chests/wooden"),
CLAY_BLOCKS = of("c:clay_blocks"),
Expand All @@ -70,6 +71,22 @@ public final class ItemTags {
GLOWSTONE_DUSTS = of("c:dusts/glowstone"),
REDSTONE_DUSTS = of("c:dusts/redstone"),
DYES = of("c:dyes"),
WHITE_DYES = of("c:dyes/white"),
ORANGE_DYES = of("c:dyes/orange"),
MAGENTA_DYES = of("c:dyes/magenta"),
LIGHT_BLUE_DYES = of("c:dyes/light_blue"),
YELLOW_DYES = of("c:dyes/yellow"),
LIME_DYES = of("c:dyes/lime"),
PINK_DYES = of("c:dyes/pink"),
GRAY_DYES = of("c:dyes/gray"),
LIGHT_GRAY_DYES = of("c:dyes/light_gray"),
CYAN_DYES = of("c:dyes/cyan"),
PURPLE_DYES = of("c:dyes/purple"),
BLUE_DYES = of("c:dyes/blue"),
BROWN_DYES = of("c:dyes/brown"),
GREEN_DYES = of("c:dyes/green"),
RED_DYES = of("c:dyes/red"),
BLACK_DYES = of("c:dyes/black"),
EGGS = of("c:eggs"),
CHICKEN_EGGS = of("c:eggs/chicken"),
FEATHERS = of("c:feathers"),
Expand All @@ -96,6 +113,7 @@ public final class ItemTags {
VEGETABLE_FOODS = of("c:foods/vegetable"),
GEMS = of("c:gems"),
DIAMOND_GEMS = of("c:gems/diamond"),
LAPIS_GEMS = of("c:gems/lapis"),
GLASS_BLOCKS = of("c:glass_blocks"),
COLORLESS_GLASS_BLOCKS = of("c:glass_blocks/colorless"),
GRASS_BLOCKS = of("c:grass_blocks"),
Expand All @@ -110,7 +128,13 @@ public final class ItemTags {
LEATHERS = of("c:leathers"),
COW_LEATHERS = of("c:leathers/cow"),
LEAVES = of("c:leaves"),
OAK_LEAVES = of("c:leaves/oak"),
SPRUCE_LEAVES = of("c:leaves/spruce"),
BIRCH_LEAVES = of("c:leaves/birch"),
LOGS = of("c:logs"),
OAK_LOGS = of("c:logs/oak"),
SPRUCE_LOGS = of("c:logs/spruce"),
BIRCH_LOGS = of("c:logs/birch"),
MUSHROOMS = of("c:mushrooms"),
BROWN_MUSHROOMS = of("c:mushrooms/brown"),
RED_MUSHROOMS = of("c:mushrooms/red"),
Expand Down Expand Up @@ -141,17 +165,26 @@ public final class ItemTags {
SANDSTONE_BLOCKS = of("c:sandstone/blocks"),
NORMAL_SANDSTONE_BLOCKS = of("c:sandstone/normal_blocks"),
SAPLINGS = of("c:saplings"),
OAK_SAPLINGS = of("c:saplings/oak"),
SPRUCE_SAPLINGS = of("c:saplings/spruce"),
BIRCH_SAPLINGS = of("c:saplings/birch"),
SEEDS = of("c:seeds"),
WHEAT_SEEDS = of("c:seeds/wheat"),
SIGNS = of("c:signs"),
WOODEN_SIGNS = of("c:signs/wooden"),
OAK_SIGNS = of("c:signs/wooden/oak"),
OAK_STANDING_SIGNS = of("c:signs/wooden/oak/standing"),
OAK_WALL_SIGNS = of("c:signs/wooden/oak/wall"),
SLABS = of("c:slabs"),
STONE_SLABS = of("c:slabs/stone"),
SANDSTONE_SLABS = of("c:slabs/sandstone"),
OAK_SLABS = of("c:slabs/wooden/oak"),
COBBLESTONE_SLABS = of("c:slabs/cobblestone"),
SLIME_BALLS = of("c:slime_balls"),
SNOW = of("c:snow"),
STAIRS = of("c:stairs"),
COBBLESTONE_STAIRS = of("c:stairs/cobblestone"),
NORMAL_COBBLESTONE_STAIRS = of("c:stairs/cobblestone/normal"),
WOODEN_STAIRS = of("c:stairs/wooden"),
OAK_STAIRS = of("c:stairs/wooden/oak"),
STICKS = of("c:sticks"),
Expand All @@ -171,6 +204,7 @@ public final class ItemTags {
STONE_AXES = of("c:tools/axes/stone"),
WOODEN_AXES = of("c:tools/axes/wooden"),
BOWS = of("c:tools/bows"),
FISHING_RODS = of("c:tools/fishing_rods"),
HOES = of("c:tools/hoes"),
DIAMOND_HOES = of("c:tools/hoes/diamond"),
GOLD_HOES = of("c:tools/hoes/gold"),
Expand All @@ -197,10 +231,29 @@ public final class ItemTags {
IRON_SWORDS = of("c:tools/swords/iron"),
STONE_SWORDS = of("c:tools/swords/stone"),
WOODEN_SWORDS = of("c:tools/swords/wooden"),
TORCHES = of("c:torches"),
NORMAL_TORCHES = of("c:torches/normal"),
REDSTONE_TORCHES = of("c:torches/redstone"),
TRAPDOORS = of("c:trapdoors"),
WOODEN_TRAPDOORS = of("c:trapdoors/wooden"),
OAK_TRAPDOORS = of("c:trapdoors/wooden/oak"),
WOOLS = of("c:wools");
WOOLS = of("c:wools"),
WHITE_WOOLS = of("c:wools/white"),
ORANGE_WOOLS = of("c:wools/orange"),
MAGENTA_WOOLS = of("c:wools/magenta"),
LIGHT_BLUE_WOOLS = of("c:wools/light_blue"),
YELLOW_WOOLS = of("c:wools/yellow"),
LIME_WOOLS = of("c:wools/lime"),
PINK_WOOLS = of("c:wools/pink"),
GRAY_WOOLS = of("c:wools/gray"),
LIGHT_GRAY_WOOLS = of("c:wools/light_gray"),
CYAN_WOOLS = of("c:wools/cyan"),
PURPLE_WOOLS = of("c:wools/purple"),
BLUE_WOOLS = of("c:wools/blue"),
BROWN_WOOLS = of("c:wools/brown"),
GREEN_WOOLS = of("c:wools/green"),
RED_WOOLS = of("c:wools/red"),
BLACK_WOOLS = of("c:wools/black");

private static TagKey<Item> of(String id) {
return TagKey.of(ItemRegistry.KEY, Identifier.of(id));
Expand Down
Loading