Skip to content

Commit

Permalink
Change version 1.1.0a -> 1.2.0a
Browse files Browse the repository at this point in the history
- Add flopper block
- Update mod resources
- Apply fixes to tinted glass (blocktags, redstone fixes and so)
- Refactor Data Gen code
  • Loading branch information
MMonkeyKiller committed Oct 28, 2023
1 parent d0f3283 commit e7d5271
Show file tree
Hide file tree
Showing 38 changed files with 924 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.parallel=true

# Mod Properties
mod_id = v2_0_rediscovered
mod_version = 1.1.0a
mod_version = 1.2.0a
maven_group = me.monkeykiller
archives_base_name = v2_0_rediscovered

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.SneakyThrows;
import me.monkeykiller.v2_0_rediscovered.common.configuration.ConfigUtils;
import me.monkeykiller.v2_0_rediscovered.common.etho_slab.EthoSlabBlock;
import me.monkeykiller.v2_0_rediscovered.common.floppers.FlopperBlock;
import me.monkeykiller.v2_0_rediscovered.common.floppers.FlopperBlockEntity;
import me.monkeykiller.v2_0_rediscovered.common.pink_wither.WitherHugEntity;
import me.monkeykiller.v2_0_rediscovered.common.pink_wither.WitherLoveEntity;
import me.monkeykiller.v2_0_rediscovered.common.speech_bubbles.SpeechBubbleEntity;
Expand All @@ -16,12 +18,14 @@
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.block.AbstractBlock.Settings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.MapColor;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
Expand Down Expand Up @@ -70,6 +74,9 @@ Registries.ENTITY_TYPE, identifier("wither_love"),
public static final Block WALL_TORCH_OFF_BLOCK = register("wall_torch_off", new WallTorchOffBlock(Settings.copy(Blocks.WALL_TORCH).dropsLike(TORCH_OFF_BLOCK).luminance(state -> 0)));
public static final Item TORCH_OFF_ITEM = register("torch_off", new VerticallyAttachableBlockItem(TORCH_OFF_BLOCK, WALL_TORCH_OFF_BLOCK, new FabricItemSettings(), Direction.DOWN));

public static final Block FLOPPER_BLOCK = register("flopper", new FlopperBlock(Settings.copy(Blocks.DROPPER)));
public static final Item FLOPPER_ITEM = register("flopper", new BlockItem(FLOPPER_BLOCK, new FabricItemSettings()));

public static final Map<Identifier, BlockItem> TINTED_GLASS_ITEMS = new HashMap<>();

public static final Block WHITE_TINTED_GLASS_BLOCK = registerTintedGlass("white_tinted_glass", 0xFFFFFF, MapColor.WHITE);
Expand All @@ -89,6 +96,10 @@ Registries.ENTITY_TYPE, identifier("wither_love"),
public static final Block RED_TINTED_GLASS_BLOCK = registerTintedGlass("red_tinted_glass", 0x993333, MapColor.RED);
public static final Block BLACK_TINTED_GLASS_BLOCK = registerTintedGlass("black_tinted_glass", 0x191919, MapColor.BLACK);

public static final BlockEntityType<FlopperBlockEntity> FLOPPER_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, identifier("flopper_block_entity"),
FabricBlockEntityTypeBuilder.create(FlopperBlockEntity::new, FLOPPER_BLOCK).build()
);

public static Identifier identifier(@NotNull String path) {
return new Identifier(MOD_ID, path);
Expand All @@ -106,6 +117,10 @@ public void onInitialize() {
content.add(TORCH_OFF_ITEM);
});

ItemGroupEvents.modifyEntriesEvent(ItemGroups.REDSTONE).register(content -> {
content.add(FLOPPER_ITEM);
});

ItemGroupEvents.modifyEntriesEvent(ItemGroups.COLORED_BLOCKS).register(content -> {
TINTED_GLASS_ITEMS.values().forEach(content::add);
});
Expand All @@ -124,7 +139,11 @@ private static <T extends Block> T register(@NonNull String id, @NonNull T block
}

private static Block registerTintedGlass(@NonNull String id, int color, @NonNull MapColor mapColor) {
var settings = FabricBlockSettings.copy(Blocks.TINTED_GLASS).mapColor(mapColor).nonOpaque();
var settings = FabricBlockSettings.copy(Blocks.GLASS)
.mapColor(mapColor).nonOpaque()
.allowsSpawning(Blocks::never).solidBlock(Blocks::never)
.suffocates(Blocks::never)
.blockVision(Blocks::never);
var block = register(id, new ColoredTintedGlassBlock(settings, color));
TINTED_GLASS_ITEMS.put(identifier(id), register(id, new BlockItem(block, new FabricItemSettings())));
return block;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package me.monkeykiller.v2_0_rediscovered.common.floppers;

import com.mojang.logging.LogUtils;
import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered;
import net.minecraft.block.BlockState;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.DispenserBehavior;
import net.minecraft.block.entity.*;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.WorldEvents;
import org.slf4j.Logger;

public class FlopperBlock extends DispenserBlock {
private static final DispenserBehavior FLOPPER_DISPENSER_BEHAVIOR = new FlopperItemDispenserBehavior();

private static final Logger LOGGER = LogUtils.getLogger();

public FlopperBlock(Settings settings) {
super(settings);
}

@Override
protected DispenserBehavior getBehaviorForItem(ItemStack stack) {
return FLOPPER_DISPENSER_BEHAVIOR;
}

@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new FlopperBlockEntity(pos, state);
}

@Override
protected void dispense(ServerWorld world, BlockState state, BlockPos pos) {
ItemStack itemStack2;
DispenserBlockEntity dispenserBlockEntity = world.getBlockEntity(pos, V2_0_Rediscovered.FLOPPER_BLOCK_ENTITY).orElse(null);
if (dispenserBlockEntity == null) {
LOGGER.warn("Ignoring dispensing attempt for Flopper without matching block entity at {}", pos);
return;
}
BlockPointer blockPointer = new BlockPointer(world, pos, state, dispenserBlockEntity);
int i = dispenserBlockEntity.chooseNonEmptySlot(world.random);
if (i < 0) {
world.syncWorldEvent(WorldEvents.DISPENSER_FAILS, pos, 0);
return;
}
ItemStack itemStack = dispenserBlockEntity.getStack(i);
if (itemStack.isEmpty()) {
return;
}
Direction direction = world.getBlockState(pos).get(FACING);
Inventory inventory = HopperBlockEntity.getInventoryAt(world, pos.offset(direction));
if (inventory == null) {
itemStack2 = FLOPPER_DISPENSER_BEHAVIOR.dispense(blockPointer, itemStack);
} else {
itemStack2 = HopperBlockEntity.transfer(dispenserBlockEntity, inventory, itemStack.copy().split(1), direction.getOpposite());
if (itemStack2.isEmpty()) {
itemStack2 = itemStack.copy();
itemStack2.decrement(1);
} else {
itemStack2 = itemStack.copy();
}
}
dispenserBlockEntity.setStack(i, itemStack2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.monkeykiller.v2_0_rediscovered.common.floppers;

import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;

public class FlopperBlockEntity extends DispenserBlockEntity {
public FlopperBlockEntity(BlockPos pos, BlockState state) {
super(V2_0_Rediscovered.FLOPPER_BLOCK_ENTITY, pos, state);
}

@Override
protected Text getContainerName() {
return Text.translatable("container.flopper");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.monkeykiller.v2_0_rediscovered.common.floppers;

import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPointer;

public class FlopperItemDispenserBehavior extends ItemDispenserBehavior {
@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
var fishStack = new ItemStack(Items.COD, stack.getCount());
super.dispenseSilently(pointer, fishStack);
stack.decrement(1);
return stack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ModBlockLootTableProvider(FabricDataOutput dataOutput) {
public void generate() {
addDrop(ETHO_SLAB_BLOCK, createEthoSlabLootTable());
addDrop(TORCH_OFF_BLOCK, createTorchOffLootTable());
addDrop(FLOPPER_BLOCK);

for (var blockItem : TINTED_GLASS_ITEMS.values()) {
addDropWithSilkTouch(blockItem.getBlock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ protected ModLanguageProvider(FabricDataOutput dataOutput) {

@Override
public void generateTranslations(TranslationBuilder translationBuilder) {
translationBuilder.add("container.flopper", "Flopper");

translationBuilder.add(ETHO_SLAB_BLOCK, "Etho Slab");
translationBuilder.add(TORCH_OFF_BLOCK, "Torch (Burnt-out)");
translationBuilder.add(FLOPPER_BLOCK, "Flopper");

translationBuilder.add(BLACK_TINTED_GLASS_BLOCK, "Black Tinted Glass");
translationBuilder.add(RED_TINTED_GLASS_BLOCK, "Red Tinted Glass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
import net.minecraft.block.Blocks;
import net.minecraft.data.client.*;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction;

import java.util.Optional;

Expand All @@ -21,6 +23,7 @@ public ModModelProvider(FabricDataOutput output) {
public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
registerEthoSlabModel(blockStateModelGenerator);
blockStateModelGenerator.registerTorch(TORCH_OFF_BLOCK, WALL_TORCH_OFF_BLOCK);
registerFlopper(blockStateModelGenerator);

for (var tintedGlass : TINTED_GLASS_ITEMS.values()) {
blockStateModelGenerator.registerSingleton(tintedGlass.getBlock(), new TextureMap(), COLORED_TINTED_GLASS);
Expand All @@ -31,6 +34,21 @@ public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGen
public void generateItemModels(ItemModelGenerator itemModelGenerator) {
}

public final void registerFlopper(BlockStateModelGenerator blockStateModelGenerator) {
var modelCollector = blockStateModelGenerator.modelCollector;
var textureMap = new TextureMap()
.put(TextureKey.TOP, TextureMap.getSubId(Blocks.FURNACE, "_top"))
.put(TextureKey.SIDE, TextureMap.getSubId(Blocks.FURNACE, "_side"))
.put(TextureKey.FRONT, TextureMap.getSubId(Blocks.DROPPER, "_front"));
var textureMapVertical = new TextureMap()
.put(TextureKey.SIDE, TextureMap.getSubId(Blocks.FURNACE, "_top"))
.put(TextureKey.FRONT, TextureMap.getSubId(Blocks.DROPPER, "_front_vertical"));

var identifier = Models.ORIENTABLE.upload(FLOPPER_BLOCK, textureMap, modelCollector);
var identifierVertical = Models.ORIENTABLE_VERTICAL.upload(FLOPPER_BLOCK, textureMapVertical, modelCollector);
blockStateModelGenerator.blockStateCollector.accept(VariantsBlockStateSupplier.create(FLOPPER_BLOCK).coordinate(BlockStateVariantMap.create(Properties.FACING).register(Direction.DOWN, BlockStateVariant.create().put(VariantSettings.MODEL, identifierVertical).put(VariantSettings.X, VariantSettings.Rotation.R180)).register(Direction.UP, BlockStateVariant.create().put(VariantSettings.MODEL, identifierVertical)).register(Direction.NORTH, BlockStateVariant.create().put(VariantSettings.MODEL, identifier)).register(Direction.EAST, BlockStateVariant.create().put(VariantSettings.MODEL, identifier).put(VariantSettings.Y, VariantSettings.Rotation.R90)).register(Direction.SOUTH, BlockStateVariant.create().put(VariantSettings.MODEL, identifier).put(VariantSettings.Y, VariantSettings.Rotation.R180)).register(Direction.WEST, BlockStateVariant.create().put(VariantSettings.MODEL, identifier).put(VariantSettings.Y, VariantSettings.Rotation.R270))));
}

private void registerEthoSlabModel(BlockStateModelGenerator blockStateModelGenerator) {
var modelCollector = blockStateModelGenerator.modelCollector;
var tntIdentifier = ModelIds.getBlockModelId(Blocks.TNT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package me.monkeykiller.v2_0_rediscovered.datagen;

import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.block.Blocks;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
import net.minecraft.data.server.recipe.VanillaRecipeProvider;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.Items;
import net.minecraft.recipe.book.RecipeCategory;
Expand All @@ -25,7 +24,17 @@ public void generate(RecipeExporter exporter) {
.input('#', Blocks.TNT)
.criterion(hasItem(Items.TNT), conditionsFromItem(Items.TNT))
.showNotification(true)
.offerTo(exporter, V2_0_Rediscovered.identifier(getRecipeName(ETHO_SLAB_ITEM)));
.offerTo(exporter);

ShapelessRecipeJsonBuilder.create(RecipeCategory.REDSTONE, FLOPPER_BLOCK)
.input(Blocks.DROPPER)
.criterion(hasItem(Items.DROPPER), conditionsFromItem(Items.DROPPER))
.offerTo(exporter, identifier("dropper_to_flopper"));

ShapelessRecipeJsonBuilder.create(RecipeCategory.REDSTONE, Blocks.DROPPER)
.input(FLOPPER_BLOCK)
.criterion(hasItem(FLOPPER_ITEM), conditionsFromItem(FLOPPER_ITEM))
.offerTo(exporter, identifier("flopper_to_dropper"));

offerTintedGlassDyeingRecipe(exporter, WHITE_TINTED_GLASS_BLOCK, Items.WHITE_DYE);
offerTintedGlassDyeingRecipe(exporter, ORANGE_TINTED_GLASS_BLOCK, Items.ORANGE_DYE);
Expand All @@ -52,8 +61,8 @@ private void offerTintedGlassDyeingRecipe(RecipeExporter exporter, ItemConvertib
.pattern("###")
.pattern("#X#")
.pattern("###")
.group("tinted_glass") // TODO
.criterion("has_tinted_glass", VanillaRecipeProvider.conditionsFromItem(Items.TINTED_GLASS))
.group("tinted_glass")
.criterion(hasItem(Items.TINTED_GLASS), conditionsFromItem(Items.TINTED_GLASS))
.offerTo(exporter);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package me.monkeykiller.v2_0_rediscovered.datagen;

import me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBlockTags;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.BlockTags;

import java.util.concurrent.CompletableFuture;

import static me.monkeykiller.v2_0_rediscovered.common.V2_0_Rediscovered.*;

public class ModTagProvider extends FabricTagProvider.BlockTagProvider {
public ModTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, registriesFuture);
}

@Override
protected void configure(RegistryWrapper.WrapperLookup arg) {
getOrCreateTagBuilder(BlockTags.IMPERMEABLE)
.add(V2_0_Rediscovered.TINTED_GLASS_ITEMS
.values().stream()
.map(BlockItem::getBlock)
.toArray(Block[]::new));
getOrCreateTagBuilder(BlockTags.PICKAXE_MINEABLE).add(FLOPPER_BLOCK);
configureColoredTintedGlassTags();
}

private void configureColoredTintedGlassTags() {
var impermeableTag = getOrCreateTagBuilder(BlockTags.IMPERMEABLE);
var glassBlocksTag = getOrCreateTagBuilder(ConventionalBlockTags.GLASS_BLOCKS);

for (var blockItem : TINTED_GLASS_ITEMS.values()) {
var block = blockItem.getBlock();
impermeableTag.add(block);
glassBlocksTag.add(block);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"variants": {
"facing=down": {
"model": "v2_0_rediscovered:block/flopper_vertical",
"x": 180
},
"facing=east": {
"model": "v2_0_rediscovered:block/flopper",
"y": 90
},
"facing=north": {
"model": "v2_0_rediscovered:block/flopper"
},
"facing=south": {
"model": "v2_0_rediscovered:block/flopper",
"y": 180
},
"facing=up": {
"model": "v2_0_rediscovered:block/flopper_vertical"
},
"facing=west": {
"model": "v2_0_rediscovered:block/flopper",
"y": 270
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/v2_0_rediscovered/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"block.v2_0_rediscovered.brown_tinted_glass": "Brown Tinted Glass",
"block.v2_0_rediscovered.cyan_tinted_glass": "Cyan Tinted Glass",
"block.v2_0_rediscovered.etho_slab": "Etho Slab",
"block.v2_0_rediscovered.flopper": "Flopper",
"block.v2_0_rediscovered.gray_tinted_glass": "Gray Tinted Glass",
"block.v2_0_rediscovered.green_tinted_glass": "Green Tinted Glass",
"block.v2_0_rediscovered.light_blue_tinted_glass": "Light Blue Tinted Glass",
Expand All @@ -17,6 +18,7 @@
"block.v2_0_rediscovered.torch_off": "Torch (Burnt-out)",
"block.v2_0_rediscovered.white_tinted_glass": "White Tinted Glass",
"block.v2_0_rediscovered.yellow_tinted_glass": "Yellow Tinted Glass",
"container.flopper": "Flopper",
"entity.v2_0_rediscovered.wither_hug": "Pink Wither",
"entity.v2_0_rediscovered.wither_love": "Pink Wither Love"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parent": "minecraft:block/orientable",
"textures": {
"front": "minecraft:block/dropper_front",
"side": "minecraft:block/furnace_side",
"top": "minecraft:block/furnace_top"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/orientable_vertical",
"textures": {
"front": "minecraft:block/dropper_front_vertical",
"side": "minecraft:block/furnace_top"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "v2_0_rediscovered:block/flopper"
}
Loading

0 comments on commit e7d5271

Please sign in to comment.