Skip to content

Commit

Permalink
feat: Add Ugly Steel Plating
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Dec 31, 2023
1 parent 2228d38 commit 742ee92
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package net.blay09.mods.forbiddensmoothies.fabric.datagen;

import net.blay09.mods.forbiddensmoothies.block.CustomBlockStateProperties;
import net.blay09.mods.forbiddensmoothies.block.ModBlocks;
import net.blay09.mods.forbiddensmoothies.item.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;

public class ModBlockLootTableProvider extends FabricBlockLootTableProvider {
protected ModBlockLootTableProvider(FabricDataOutput dataOutput) {
Expand All @@ -11,7 +17,13 @@ protected ModBlockLootTableProvider(FabricDataOutput dataOutput) {

@Override
public void generate() {
add(ModBlocks.printer, createSingleItemTable(ModBlocks.printer));
add(ModBlocks.blender, createSingleItemTable(ModBlocks.blender));
add(ModBlocks.printer, createSingleItemTable(ModBlocks.printer)
.withPool(new LootPool.Builder().add(LootItem.lootTableItem(ModItems.uglySteelPlating))
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.printer)
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(CustomBlockStateProperties.UGLY, true)))));
add(ModBlocks.blender, createSingleItemTable(ModBlocks.blender)
.withPool(new LootPool.Builder().add(LootItem.lootTableItem(ModItems.uglySteelPlating))
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.blender)
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(CustomBlockStateProperties.UGLY, true)))));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package net.blay09.mods.forbiddensmoothies.fabric.datagen;

import net.blay09.mods.forbiddensmoothies.block.CustomBlockStateProperties;
import net.blay09.mods.forbiddensmoothies.block.ModBlocks;
import net.blay09.mods.forbiddensmoothies.item.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
import net.minecraft.data.models.BlockModelGenerators;
import net.minecraft.data.models.ItemModelGenerators;
import net.minecraft.data.models.blockstates.MultiVariantGenerator;
import net.minecraft.data.models.blockstates.PropertyDispatch;
import net.minecraft.data.models.blockstates.Variant;
import net.minecraft.data.models.blockstates.VariantProperties;
import net.minecraft.data.models.model.ModelLocationUtils;
import net.minecraft.data.models.model.ModelTemplates;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;

import static net.minecraft.data.models.BlockModelGenerators.createHorizontalFacingDispatch;

public class ModModelGenerator extends FabricModelProvider {
public ModModelGenerator(FabricDataOutput output) {
Expand All @@ -13,11 +25,22 @@ public ModModelGenerator(FabricDataOutput output) {

@Override
public void generateBlockStateModels(BlockModelGenerators blockStateModelGenerator) {
blockStateModelGenerator.createNonTemplateHorizontalBlock(ModBlocks.printer);
blockStateModelGenerator.createNonTemplateHorizontalBlock(ModBlocks.blender);
createNonTemplateUglifyableHorizontalBlock(blockStateModelGenerator, ModBlocks.printer);
createNonTemplateUglifyableHorizontalBlock(blockStateModelGenerator, ModBlocks.blender);
}

@Override
public void generateItemModels(ItemModelGenerators itemModelGenerator) {
itemModelGenerator.generateFlatItem(ModItems.uglySteelPlating, ModelTemplates.FLAT_ITEM);
}

public final void createNonTemplateUglifyableHorizontalBlock(BlockModelGenerators blockStateModelGenerator, Block block) {
final var modelLocation = ModelLocationUtils.getModelLocation(block);
final var uglyModelLocation = ModelLocationUtils.getModelLocation(block, "_ugly");
blockStateModelGenerator.blockStateOutput.accept(MultiVariantGenerator.multiVariant(block,
Variant.variant().with(VariantProperties.MODEL, ModelLocationUtils.getModelLocation(block))).with(createHorizontalFacingDispatch())
.with(PropertyDispatch.property(CustomBlockStateProperties.UGLY)
.select(false, Variant.variant().with(VariantProperties.MODEL, modelLocation))
.select(true, Variant.variant().with(VariantProperties.MODEL, uglyModelLocation))));
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{
"variants": {
"facing=east": {
"facing=east,ugly=false": {
"model": "forbiddensmoothies:block/blender",
"y": 90
},
"facing=north": {
"facing=east,ugly=true": {
"model": "forbiddensmoothies:block/blender_ugly",
"y": 90
},
"facing=north,ugly=false": {
"model": "forbiddensmoothies:block/blender"
},
"facing=south": {
"facing=north,ugly=true": {
"model": "forbiddensmoothies:block/blender_ugly"
},
"facing=south,ugly=false": {
"model": "forbiddensmoothies:block/blender",
"y": 180
},
"facing=west": {
"facing=south,ugly=true": {
"model": "forbiddensmoothies:block/blender_ugly",
"y": 180
},
"facing=west,ugly=false": {
"model": "forbiddensmoothies:block/blender",
"y": 270
},
"facing=west,ugly=true": {
"model": "forbiddensmoothies:block/blender_ugly",
"y": 270
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{
"variants": {
"facing=east": {
"facing=east,ugly=false": {
"model": "forbiddensmoothies:block/printer",
"y": 90
},
"facing=north": {
"facing=east,ugly=true": {
"model": "forbiddensmoothies:block/printer_ugly",
"y": 90
},
"facing=north,ugly=false": {
"model": "forbiddensmoothies:block/printer"
},
"facing=south": {
"facing=north,ugly=true": {
"model": "forbiddensmoothies:block/printer_ugly"
},
"facing=south,ugly=false": {
"model": "forbiddensmoothies:block/printer",
"y": 180
},
"facing=west": {
"facing=south,ugly=true": {
"model": "forbiddensmoothies:block/printer_ugly",
"y": 180
},
"facing=west,ugly=false": {
"model": "forbiddensmoothies:block/printer",
"y": 270
},
"facing=west,ugly=true": {
"model": "forbiddensmoothies:block/printer_ugly",
"y": 270
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "forbiddensmoothies:item/ugly_steel_plating"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
}
],
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "forbiddensmoothies:blender",
"condition": "minecraft:block_state_property",
"properties": {
"ugly": "true"
}
}
],
"entries": [
{
"type": "minecraft:item",
"name": "forbiddensmoothies:ugly_steel_plating"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
}
],
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "forbiddensmoothies:printer",
"condition": "minecraft:block_state_property",
"properties": {
"ugly": "true"
}
}
],
"entries": [
{
"type": "minecraft:item",
"name": "forbiddensmoothies:ugly_steel_plating"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.blay09.mods.balm.api.container.BalmContainerProvider;
import net.blay09.mods.forbiddensmoothies.block.entity.BlenderBlockEntity;
import net.blay09.mods.forbiddensmoothies.block.entity.ModBlockEntities;
import net.blay09.mods.forbiddensmoothies.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -24,6 +25,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -34,6 +36,7 @@ public class BlenderBlock extends BaseEntityBlock {

private static final VoxelShape SHAPE = box(3, 0, 3, 13, 16, 13);
private static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
private static final BooleanProperty UGLY = CustomBlockStateProperties.UGLY;

public BlenderBlock() {
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(2.5f));
Expand All @@ -42,10 +45,15 @@ public BlenderBlock() {
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(UGLY);
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
if (player.getItemInHand(hand).is(ModItems.uglySteelPlating)) {
return InteractionResult.PASS;
}

final var blockEntity = level.getBlockEntity(pos);
if (!level.isClientSide && blockEntity instanceof BlenderBlockEntity blender) {
if (player.getAbilities().instabuild && player.getItemInHand(InteractionHand.MAIN_HAND).is(Items.BAMBOO)) {
Expand Down Expand Up @@ -76,7 +84,7 @@ public RenderShape getRenderShape(BlockState state) {

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(UGLY, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.blay09.mods.forbiddensmoothies.block;

import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class CustomBlockStateProperties {
public static final BooleanProperty UGLY = BooleanProperty.create("ugly");
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blay09.mods.balm.api.container.BalmContainerProvider;
import net.blay09.mods.forbiddensmoothies.block.entity.ModBlockEntities;
import net.blay09.mods.forbiddensmoothies.block.entity.PrinterBlockEntity;
import net.blay09.mods.forbiddensmoothies.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -22,13 +23,15 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

public class PrinterBlock extends BaseEntityBlock {

private static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
private static final BooleanProperty UGLY = CustomBlockStateProperties.UGLY;

public PrinterBlock() {
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(2.5f));
Expand All @@ -37,10 +40,15 @@ public PrinterBlock() {
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(UGLY);
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
if (player.getItemInHand(hand).is(ModItems.uglySteelPlating)) {
return InteractionResult.PASS;
}

final var blockEntity = level.getBlockEntity(pos);
if (!level.isClientSide && blockEntity instanceof PrinterBlockEntity printer) {
if (player.getAbilities().instabuild && player.getItemInHand(InteractionHand.MAIN_HAND).is(Items.BAMBOO)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void load(CompoundTag tag) {
progress = tag.getInt("Progress");
maxProgress = tag.getInt("MaxProgress");
lockedInputs = tag.getBoolean("LockedInputs");
energyCostPerTick = tag.getInt("EnergyCostPerTick");
}

protected void saveAdditional(CompoundTag tag) {
Expand All @@ -176,8 +177,7 @@ protected void saveAdditional(CompoundTag tag) {
protected void writeUpdateTag(CompoundTag tag) {
super.writeUpdateTag(tag);
tag.put("Items", container.serialize());
tag.putInt("Progress", this.progress);
tag.putInt("MaxProgress", this.maxProgress);
tag.putInt("EnergyCostPerTick", energyCostPerTick);
}

@Override
Expand All @@ -191,7 +191,7 @@ public Container getContainer(Direction side) {
}

public void serverTick() {
if (ticksSinceLastSync >= 20 && dirtyForSync) {
if (ticksSinceLastSync >= 10 && dirtyForSync) {
sync();
dirtyForSync = false;
ticksSinceLastSync = 0;
Expand All @@ -203,7 +203,11 @@ public void serverTick() {

final var recipe = selectRecipe(randomSource).orElse(null);
maxProgress = getTotalProcessingTicks();
final var lastEnergyCostPerTick = energyCostPerTick;
energyCostPerTick = recipe != null ? determineEnergyCostPerTick() : 0;
if (lastEnergyCostPerTick != energyCostPerTick) {
dirtyForSync = true;
}
if (recipe != null && canFitRecipeResults(recipe) && energyStorage.drain(energyCostPerTick, true) >= energyCostPerTick) {
progress++;
energyStorage.drain(energyCostPerTick, false);
Expand Down Expand Up @@ -290,7 +294,9 @@ public void setChanged() {
}

public float animate(float partialTicks) {
animationTicks += partialTicks;
if (energyCostPerTick > 0) {
animationTicks += partialTicks;
}
return animationTicks;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.blay09.mods.forbiddensmoothies.client.render;

import com.mojang.blaze3d.vertex.PoseStack;
import net.blay09.mods.forbiddensmoothies.block.CustomBlockStateProperties;
import net.blay09.mods.forbiddensmoothies.block.entity.BlenderBlockEntity;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
Expand All @@ -15,6 +16,11 @@ public BlenderRenderer(BlockEntityRendererProvider.Context context) {

@Override
public void render(BlenderBlockEntity blockEntity, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int combinedLight, int combinedOverlayIn) {
final var state = blockEntity.getBlockState();
if (state.hasProperty(CustomBlockStateProperties.UGLY) && state.getValue(CustomBlockStateProperties.UGLY)) {
return;
}

final var inputContainer = blockEntity.getInputContainer();
poseStack.pushPose();
final var itemScale = 0.2f;
Expand All @@ -30,7 +36,7 @@ public void render(BlenderBlockEntity blockEntity, float partialTicks, PoseStack
final var sinah = Math.sin(animationTime * speedH) * offsetH;
for (int i = 0; i < inputContainer.getContainerSize(); i++) {
poseStack.pushPose();
poseStack.translate(i * 0.2f - 0.5f, i * 0.2f - 0.5f, 0f);
poseStack.translate(i * 0.1f - 0.5f, i * 0.15f - 0.5f, i * 0.1f - 0.5f);
double sinav = Math.sin(i * animationTime * speedV) * offsetV;
if (i % 2 == 0) {
poseStack.translate(cosah, sinav, sinah);
Expand Down
Loading

0 comments on commit 742ee92

Please sign in to comment.