Fully working port to 1.15

This commit is contained in:
Motschen
2020-06-16 18:37:44 +02:00
committed by GitHub
parent 67f47d0135
commit 8525e5bd38
8 changed files with 501 additions and 498 deletions

View File

@@ -1,13 +1,13 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropBlock;
public class Crop extends CropBlock {
public Crop() {
super(FabricBlockSettings.copy(Blocks.CARROTS));
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropBlock;
public class Crop extends CropBlock {
public Crop() {
super(FabricBlockSettings.copy(Blocks.CARROTS));
}
}

View File

@@ -1,106 +1,107 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import static net.minecraft.state.property.Properties.BITES;
public class Dish extends HorizontalFacingBlock {
private static final VoxelShape NORTH_SHAPE;
private static final VoxelShape EAST_SHAPE;
private static final VoxelShape SOUTH_SHAPE;
private static final VoxelShape WEST_SHAPE;
public Dish() {
super(FabricBlockSettings.copy(Blocks.CAKE).nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(BITES, 0));
}
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getHungerManager().isNotFull()) {
switch (state.get(BITES)) {
case 0: world.setBlockState(pos, state.with(BITES, 1));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 1: world.setBlockState(pos, state.with(BITES, 2));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 2: world.setBlockState(pos, state.with(BITES, 3));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 3: world.setBlockState(pos, state.with(BITES, 4));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 4: world.setBlockState(pos,DishesMain.Plate.getDefaultState());
player.getHungerManager().add(2, 1);
return ActionResult.SUCCESS;
}
return ActionResult.SUCCESS;
}
else {
return ActionResult.FAIL;
}
}
@Override
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
return super.getPlacementState(itemPlacementContext)
.with(FACING, itemPlacementContext.getPlayerFacing().getOpposite())
.with(BITES, 0);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(BITES);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
switch (state.get(FACING)) {
case NORTH: return NORTH_SHAPE;
case EAST: return EAST_SHAPE;
case SOUTH: return SOUTH_SHAPE;
case WEST: return WEST_SHAPE;
default: return super.getOutlineShape(state, view, pos, context);
}
}
static {
VoxelShape shape = createCuboidShape(0, 0, 0, 16, 5, 16);
EAST_SHAPE = shape;
NORTH_SHAPE = shape;
SOUTH_SHAPE = shape;
WEST_SHAPE = shape;
}
private static VoxelShape rotate(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
return buffer[0];
}
public boolean canPlaceAt(BlockState state, WorldView worldView, BlockPos pos) {
return !worldView.isAir(pos.down());
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import static net.minecraft.state.property.Properties.BITES;
public class Dish extends HorizontalFacingBlock {
private static final VoxelShape NORTH_SHAPE;
private static final VoxelShape EAST_SHAPE;
private static final VoxelShape SOUTH_SHAPE;
private static final VoxelShape WEST_SHAPE;
public Dish() {
super(FabricBlockSettings.copyOf(Blocks.CAKE).nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(BITES, 0));
}
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getHungerManager().isNotFull()) {
switch (state.get(BITES)) {
case 0: world.setBlockState(pos, state.with(BITES, 1));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 1: world.setBlockState(pos, state.with(BITES, 2));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 2: world.setBlockState(pos, state.with(BITES, 3));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 3: world.setBlockState(pos, state.with(BITES, 4));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 4: world.setBlockState(pos,DishesMain.Plate.getDefaultState());
player.getHungerManager().add(2, 1);
return ActionResult.SUCCESS;
}
return ActionResult.SUCCESS;
}
else {
return ActionResult.FAIL;
}
}
@Override
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
return super.getPlacementState(itemPlacementContext)
.with(FACING, itemPlacementContext.getPlayerFacing().getOpposite())
.with(BITES, 0);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(BITES);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
switch (state.get(FACING)) {
case NORTH: return NORTH_SHAPE;
case EAST: return EAST_SHAPE;
case SOUTH: return SOUTH_SHAPE;
case WEST: return WEST_SHAPE;
default: return super.getOutlineShape(state, view, pos, context);
}
}
static {
VoxelShape shape = createCuboidShape(0, 0, 0, 16, 5, 16);
EAST_SHAPE = shape;
NORTH_SHAPE = shape;
SOUTH_SHAPE = shape;
WEST_SHAPE = shape;
}
private static VoxelShape rotate(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
return buffer[0];
}
public boolean canPlaceAt(BlockState state, WorldView worldView, BlockPos pos) {
return !worldView.isAir(pos.down());
}
}

View File

@@ -1,14 +1,14 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.render.RenderLayer;
public class DishesClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(),DishesMain.TomatoBush);
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(),DishesMain.LettuceBush);
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.render.RenderLayer;
public class DishesClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(),DishesMain.TomatoBush);
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(),DishesMain.LettuceBush);
}
}

View File

@@ -1,132 +1,132 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.Locale;
public class DishesMain implements ModInitializer {
public static final String MOD_ID = "dishes";
public static final ItemGroup DishesGroup = FabricItemGroupBuilder.build(new Identifier(MOD_ID, "dishes"), () -> new ItemStack(DishesMain.PizzaSalami));
public static final Block Plate = new Plate();
public static final Block PizzaBox = new Plate();
public static final Block PotatoesWithCurdCheese = new Dish();
public static final Block TinyPotatoesWithCurdCheese = new Dish();
public static final Block Schnitzel = new Dish();
public static final Block PizzaSalami = new Pizza();
public static final Block PizzaHam = new Pizza();
public static final Block PizzaTuna = new Pizza();
public static final Block PizzaBacon = new Pizza();
public static final Block SpaghettiBolognese = new Dish();
public static final Block Steak = new Dish();
public static final Block Hamburger = new Dish();
public static final Block Chickenburger = new Dish();
public static final Block Cheeseburger = new Dish();
public static final Block FishAndChips = new Dish();
public static final Item Knife = new Item(new Item.Settings().group(DishesMain.DishesGroup).recipeRemainder(DishesMain.Knife).maxCount(1));
public static final Item PotatoSlice = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(1).saturationModifier(0.5f).build()));
public static final Item RawFries = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(1).saturationModifier(1f).build()));
public static final Item Fries = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(4).saturationModifier(4f).build()));
public static final Block SaltOre = new Block(FabricBlockSettings.copyOf(Blocks.COAL_ORE));
public static final Item Salt = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Flour = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item RawSpaghetti = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Spaghetti = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Salami = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Tomato = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Block TomatoBush = new Crop();
public static final Item Lettuce = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Block LettuceBush = new Crop();
public static final Item RawBacon = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Item Bacon = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Item CheeseRoll = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Item CheeseSlice = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
@Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("dishes","salt_ore"), new BlockItem(SaltOre, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.BLOCK, new Identifier("dishes","salt_ore"), SaltOre);
Registry.register(Registry.ITEM, new Identifier("dishes","salt"), Salt);
Registry.register(Registry.ITEM, new Identifier("dishes","flour"), Flour);
Registry.register(Registry.ITEM, new Identifier("dishes","knife"), Knife);
Registry.register(Registry.ITEM, new Identifier("dishes","potato_slice"), PotatoSlice);
Registry.register(Registry.ITEM, new Identifier("dishes","raw_fries"), RawFries);
Registry.register(Registry.ITEM, new Identifier("dishes","fries"), Fries);
Registry.register(Registry.ITEM, new Identifier("dishes","raw_spaghetti"), RawSpaghetti);
Registry.register(Registry.ITEM, new Identifier("dishes","spaghetti"), Spaghetti);
Registry.register(Registry.ITEM, new Identifier("dishes","salami"), Salami);
Registry.register(Registry.ITEM, new Identifier("dishes","raw_bacon"), RawBacon);
Registry.register(Registry.ITEM, new Identifier("dishes","bacon"), Bacon);
Registry.register(Registry.ITEM, new Identifier("dishes","cheese_roll"), CheeseRoll);
Registry.register(Registry.ITEM, new Identifier("dishes","cheese_slice"), CheeseSlice);
Registry.register(Registry.ITEM, new Identifier("dishes","tomatoseed"), new AliasedBlockItem(TomatoBush, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.ITEM, new Identifier("dishes","tomato"), Tomato);
Registry.register(Registry.ITEM, new Identifier("dishes","lettuceseed"), new AliasedBlockItem(LettuceBush, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.ITEM, new Identifier("dishes","lettuce"), Lettuce);
Registry.register(Registry.BLOCK, new Identifier("dishes","tomatobush"), TomatoBush);
Registry.register(Registry.BLOCK, new Identifier("dishes","lettucebush"), LettuceBush);
Registry.register(Registry.ITEM, new Identifier("dishes","plate"), new AliasedBlockItem(Plate, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.BLOCK, new Identifier("dishes","plate"), Plate);
Registry.register(Registry.ITEM, new Identifier("dishes","potatoeswithcurdcheese"), new AliasedBlockItem(PotatoesWithCurdCheese, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","potatoeswithcurdcheese"), PotatoesWithCurdCheese);
Registry.register(Registry.ITEM, new Identifier("dishes","tinypotatoeswithcurdcheese"), new AliasedBlockItem(TinyPotatoesWithCurdCheese, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","tinypotatoeswithcurdcheese"), TinyPotatoesWithCurdCheese);
Registry.register(Registry.ITEM, new Identifier("dishes","schnitzel"), new AliasedBlockItem(Schnitzel, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","schnitzel"), Schnitzel);
Registry.register(Registry.ITEM, new Identifier("dishes","spaghetti_bolognese"), new AliasedBlockItem(SpaghettiBolognese, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","spaghetti_bolognese"), SpaghettiBolognese);
Registry.register(Registry.ITEM, new Identifier("dishes","steak"), new AliasedBlockItem(Steak, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","steak"), Steak);
Registry.register(Registry.ITEM, new Identifier("dishes","hamburger"), new AliasedBlockItem(Hamburger, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","hamburger"), Hamburger);
Registry.register(Registry.ITEM, new Identifier("dishes","chickenburger"), new AliasedBlockItem(Chickenburger, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","chickenburger"), Chickenburger);
Registry.register(Registry.ITEM, new Identifier("dishes","cheeseburger"), new AliasedBlockItem(Cheeseburger, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","cheeseburger"), Cheeseburger);
Registry.register(Registry.ITEM, new Identifier("dishes","fishandchips"), new AliasedBlockItem(FishAndChips, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","fishandchips"), FishAndChips);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzabox"), new AliasedBlockItem(PizzaBox, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzabox"), PizzaBox);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzasalami"), new AliasedBlockItem(PizzaSalami, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzasalami"), PizzaSalami);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzaham"), new AliasedBlockItem(PizzaHam, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzaham"), PizzaHam);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzatuna"), new AliasedBlockItem(PizzaTuna, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzatuna"), PizzaTuna);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzabacon"), new AliasedBlockItem(PizzaBacon, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzabacon"), PizzaBacon);
LootModifier.init();
Flags.init();
eu.midnightdust.motschen.dishes.world.SaltOre.initBiomeFeatures();
}
public enum Ores implements ItemConvertible {
SaltOre(4, 20, 40, 120);
public final String name;
public final int veinSize;
public final int veinsPerChunk;
public final int minY;
public final int maxY;
Ores(int veinSize, int veinsPerChunk, int minY, int maxY) {
name = this.toString().toLowerCase(Locale.ROOT);
this.veinSize = veinSize;
this.veinsPerChunk = veinsPerChunk;
this.minY = minY;
this.maxY = maxY;
}
@Override
public Item asItem() {
return SaltOre.asItem();
}
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.Locale;
public class DishesMain implements ModInitializer {
public static final String MOD_ID = "dishes";
public static final ItemGroup DishesGroup = FabricItemGroupBuilder.build(new Identifier(MOD_ID, "dishes"), () -> new ItemStack(DishesMain.PizzaSalami));
public static final Block Plate = new Plate();
public static final Block PizzaBox = new Plate();
public static final Block PotatoesWithCurdCheese = new Dish();
public static final Block TinyPotatoesWithCurdCheese = new Dish();
public static final Block Schnitzel = new Dish();
public static final Block PizzaSalami = new Pizza();
public static final Block PizzaHam = new Pizza();
public static final Block PizzaTuna = new Pizza();
public static final Block PizzaBacon = new Pizza();
public static final Block SpaghettiBolognese = new Dish();
public static final Block Steak = new Dish();
public static final Block Hamburger = new Dish();
public static final Block Chickenburger = new Dish();
public static final Block Cheeseburger = new Dish();
public static final Block FishAndChips = new Dish();
public static final Item Knife = new Item(new Item.Settings().group(DishesMain.DishesGroup).recipeRemainder(DishesMain.Knife).maxCount(1));
public static final Item PotatoSlice = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(1).saturationModifier(0.5f).build()));
public static final Item RawFries = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(1).saturationModifier(1f).build()));
public static final Item Fries = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(4).saturationModifier(4f).build()));
public static final Block SaltOre = new Block(FabricBlockSettings.copyOf(Blocks.COAL_ORE));
public static final Item Salt = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Flour = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item RawSpaghetti = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Spaghetti = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Salami = new Item(new Item.Settings().group(DishesMain.DishesGroup));
public static final Item Tomato = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Block TomatoBush = new Crop();
public static final Item Lettuce = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Block LettuceBush = new Crop();
public static final Item RawBacon = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Item Bacon = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Item CheeseRoll = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
public static final Item CheeseSlice = new Item(new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(3).saturationModifier(2f).build()));
@Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("dishes","salt_ore"), new BlockItem(SaltOre, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.BLOCK, new Identifier("dishes","salt_ore"), SaltOre);
Registry.register(Registry.ITEM, new Identifier("dishes","salt"), Salt);
Registry.register(Registry.ITEM, new Identifier("dishes","flour"), Flour);
Registry.register(Registry.ITEM, new Identifier("dishes","knife"), Knife);
Registry.register(Registry.ITEM, new Identifier("dishes","potato_slice"), PotatoSlice);
Registry.register(Registry.ITEM, new Identifier("dishes","raw_fries"), RawFries);
Registry.register(Registry.ITEM, new Identifier("dishes","fries"), Fries);
Registry.register(Registry.ITEM, new Identifier("dishes","raw_spaghetti"), RawSpaghetti);
Registry.register(Registry.ITEM, new Identifier("dishes","spaghetti"), Spaghetti);
Registry.register(Registry.ITEM, new Identifier("dishes","salami"), Salami);
Registry.register(Registry.ITEM, new Identifier("dishes","raw_bacon"), RawBacon);
Registry.register(Registry.ITEM, new Identifier("dishes","bacon"), Bacon);
Registry.register(Registry.ITEM, new Identifier("dishes","cheese_roll"), CheeseRoll);
Registry.register(Registry.ITEM, new Identifier("dishes","cheese_slice"), CheeseSlice);
Registry.register(Registry.ITEM, new Identifier("dishes","tomatoseed"), new AliasedBlockItem(TomatoBush, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.ITEM, new Identifier("dishes","tomato"), Tomato);
Registry.register(Registry.ITEM, new Identifier("dishes","lettuceseed"), new AliasedBlockItem(LettuceBush, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.ITEM, new Identifier("dishes","lettuce"), Lettuce);
Registry.register(Registry.BLOCK, new Identifier("dishes","tomatobush"), TomatoBush);
Registry.register(Registry.BLOCK, new Identifier("dishes","lettucebush"), LettuceBush);
Registry.register(Registry.ITEM, new Identifier("dishes","plate"), new AliasedBlockItem(Plate, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.BLOCK, new Identifier("dishes","plate"), Plate);
Registry.register(Registry.ITEM, new Identifier("dishes","potatoeswithcurdcheese"), new AliasedBlockItem(PotatoesWithCurdCheese, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","potatoeswithcurdcheese"), PotatoesWithCurdCheese);
Registry.register(Registry.ITEM, new Identifier("dishes","tinypotatoeswithcurdcheese"), new AliasedBlockItem(TinyPotatoesWithCurdCheese, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","tinypotatoeswithcurdcheese"), TinyPotatoesWithCurdCheese);
Registry.register(Registry.ITEM, new Identifier("dishes","schnitzel"), new AliasedBlockItem(Schnitzel, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","schnitzel"), Schnitzel);
Registry.register(Registry.ITEM, new Identifier("dishes","spaghetti_bolognese"), new AliasedBlockItem(SpaghettiBolognese, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","spaghetti_bolognese"), SpaghettiBolognese);
Registry.register(Registry.ITEM, new Identifier("dishes","steak"), new AliasedBlockItem(Steak, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","steak"), Steak);
Registry.register(Registry.ITEM, new Identifier("dishes","hamburger"), new AliasedBlockItem(Hamburger, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","hamburger"), Hamburger);
Registry.register(Registry.ITEM, new Identifier("dishes","chickenburger"), new AliasedBlockItem(Chickenburger, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","chickenburger"), Chickenburger);
Registry.register(Registry.ITEM, new Identifier("dishes","cheeseburger"), new AliasedBlockItem(Cheeseburger, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","cheeseburger"), Cheeseburger);
Registry.register(Registry.ITEM, new Identifier("dishes","fishandchips"), new AliasedBlockItem(FishAndChips, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","fishandchips"), FishAndChips);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzabox"), new AliasedBlockItem(PizzaBox, new Item.Settings().group(DishesMain.DishesGroup)));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzabox"), PizzaBox);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzasalami"), new AliasedBlockItem(PizzaSalami, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzasalami"), PizzaSalami);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzaham"), new AliasedBlockItem(PizzaHam, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzaham"), PizzaHam);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzatuna"), new AliasedBlockItem(PizzaTuna, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzatuna"), PizzaTuna);
Registry.register(Registry.ITEM, new Identifier("dishes","pizzabacon"), new AliasedBlockItem(PizzaBacon, new Item.Settings().group(DishesMain.DishesGroup).food(new FoodComponent.Builder().hunger(10).saturationModifier(20f).build())));
Registry.register(Registry.BLOCK, new Identifier("dishes","pizzabacon"), PizzaBacon);
LootModifier.init();
Flags.init();
eu.midnightdust.motschen.dishes.world.SaltOre.initBiomeFeatures();
}
public enum Ores implements ItemConvertible {
SaltOre(4, 20, 40, 120);
public final String name;
public final int veinSize;
public final int veinsPerChunk;
public final int minY;
public final int maxY;
Ores(int veinSize, int veinsPerChunk, int minY, int maxY) {
name = this.toString().toLowerCase(Locale.ROOT);
this.veinSize = veinSize;
this.veinsPerChunk = veinsPerChunk;
this.minY = minY;
this.maxY = maxY;
}
@Override
public Item asItem() {
return SaltOre.asItem();
}
}
}

View File

@@ -1,18 +1,18 @@
package eu.midnightdust.motschen.dishes;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class Flags {
public static Item FlagGermany = new Item(new Item.Settings());
public static Item FlagItaly = new Item(new Item.Settings());
public static Item FlagBritain = new Item(new Item.Settings());
public static Item FlagUSA = new Item(new Item.Settings());
public static void init() {
Registry.register(Registry.ITEM, new Identifier("dishes","flag_germany"), FlagGermany);
Registry.register(Registry.ITEM, new Identifier("dishes","flag_italy"), FlagItaly);
Registry.register(Registry.ITEM, new Identifier("dishes","flag_britain"), FlagBritain);
Registry.register(Registry.ITEM, new Identifier("dishes","flag_america"), FlagUSA);
}
}
package eu.midnightdust.motschen.dishes;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class Flags {
public static Item FlagGermany = new Item(new Item.Settings());
public static Item FlagItaly = new Item(new Item.Settings());
public static Item FlagBritain = new Item(new Item.Settings());
public static Item FlagUSA = new Item(new Item.Settings());
public static void init() {
Registry.register(Registry.ITEM, new Identifier("dishes","flag_germany"), FlagGermany);
Registry.register(Registry.ITEM, new Identifier("dishes","flag_italy"), FlagItaly);
Registry.register(Registry.ITEM, new Identifier("dishes","flag_britain"), FlagBritain);
Registry.register(Registry.ITEM, new Identifier("dishes","flag_america"), FlagUSA);
}
}

View File

@@ -1,31 +1,31 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.minecraft.loot.UniformLootTableRange;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
public class LootModifier {
public static void init() {
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (id.getPath().contains("chests") && id.getPath().contains("village")) {
FabricLootPoolBuilder tomato = FabricLootPoolBuilder.builder()
.rolls(UniformLootTableRange.between(0, 5))
.withCondition(RandomChanceLootCondition.builder(1.0f).build())
.with(ItemEntry.builder(DishesMain.Tomato));
supplier.pool(tomato);
}
});
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (id.getPath().contains("chests") && id.getPath().contains("village")) {
FabricLootPoolBuilder lettuce = FabricLootPoolBuilder.builder()
.rolls(UniformLootTableRange.between(0, 5))
.withCondition(RandomChanceLootCondition.builder(1.0f).build())
.with(ItemEntry.builder(DishesMain.Lettuce));
supplier.pool(lettuce);
}
});
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.minecraft.loot.UniformLootTableRange;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
public class LootModifier {
public static void init() {
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (id.getPath().contains("chests") && id.getPath().contains("village")) {
FabricLootPoolBuilder tomato = FabricLootPoolBuilder.builder()
.withRolls(UniformLootTableRange.between(0, 5))
.withCondition(RandomChanceLootCondition.builder(1.0f).build())
.withEntry(ItemEntry.builder(DishesMain.Tomato));
supplier.withPool(tomato);
}
});
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (id.getPath().contains("chests") && id.getPath().contains("village")) {
FabricLootPoolBuilder lettuce = FabricLootPoolBuilder.builder()
.withRolls(UniformLootTableRange.between(0, 5))
.withCondition(RandomChanceLootCondition.builder(1.0f).build())
.withEntry(ItemEntry.builder(DishesMain.Lettuce));
supplier.withPool(lettuce);
}
});
}
}

View File

@@ -1,113 +1,114 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import static net.minecraft.state.property.Properties.BITES;
public class Pizza extends HorizontalFacingBlock {
private static final VoxelShape NORTH_SHAPE;
private static final VoxelShape EAST_SHAPE;
private static final VoxelShape SOUTH_SHAPE;
private static final VoxelShape WEST_SHAPE;
public Pizza() {
super(FabricBlockSettings.copy(Blocks.CAKE).nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(BITES, 0));
}
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getHungerManager().isNotFull()) {
switch (state.get(BITES)) {
case 0: world.setBlockState(pos, state.with(BITES, 1));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 1: world.setBlockState(pos, state.with(BITES, 2));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 2: world.setBlockState(pos, state.with(BITES, 3));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 3: world.setBlockState(pos, state.with(BITES, 4));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 4:
switch (state.get(FACING)) {
case NORTH: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.NORTH)); return ActionResult.SUCCESS;
case EAST: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.EAST)); return ActionResult.SUCCESS;
case WEST: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.WEST)); return ActionResult.SUCCESS;
case SOUTH: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.SOUTH)); return ActionResult.SUCCESS;
}
player.getHungerManager().add(2, 1);
return ActionResult.SUCCESS;
}
return ActionResult.SUCCESS;
}
else {
return ActionResult.FAIL;
}
}
@Override
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
return super.getPlacementState(itemPlacementContext)
.with(FACING, itemPlacementContext.getPlayerFacing().getOpposite())
.with(BITES, 0);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(BITES);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
switch (state.get(FACING)) {
case NORTH: return NORTH_SHAPE;
case EAST: return EAST_SHAPE;
case SOUTH: return SOUTH_SHAPE;
case WEST: return WEST_SHAPE;
default: return super.getOutlineShape(state, view, pos, context);
}
}
static {
VoxelShape shape = createCuboidShape(0, 0, 0, 16, 5, 16);
EAST_SHAPE = shape;
NORTH_SHAPE = shape;
SOUTH_SHAPE = shape;
WEST_SHAPE = shape;
}
private static VoxelShape rotate(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
return buffer[0];
}
public boolean canPlaceAt(BlockState state, WorldView worldView, BlockPos pos) {
return !worldView.isAir(pos.down());
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import static net.minecraft.state.property.Properties.BITES;
public class Pizza extends HorizontalFacingBlock {
private static final VoxelShape NORTH_SHAPE;
private static final VoxelShape EAST_SHAPE;
private static final VoxelShape SOUTH_SHAPE;
private static final VoxelShape WEST_SHAPE;
public Pizza() {
super(FabricBlockSettings.copyOf(Blocks.CAKE).nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(BITES, 0));
}
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getHungerManager().isNotFull()) {
switch (state.get(BITES)) {
case 0: world.setBlockState(pos, state.with(BITES, 1));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 1: world.setBlockState(pos, state.with(BITES, 2));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 2: world.setBlockState(pos, state.with(BITES, 3));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 3: world.setBlockState(pos, state.with(BITES, 4));
player.getHungerManager().add(2, 4);
return ActionResult.SUCCESS;
case 4:
switch (state.get(FACING)) {
case NORTH: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.NORTH)); return ActionResult.SUCCESS;
case EAST: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.EAST)); return ActionResult.SUCCESS;
case WEST: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.WEST)); return ActionResult.SUCCESS;
case SOUTH: world.setBlockState(pos,DishesMain.PizzaBox.getDefaultState().with(FACING, Direction.SOUTH)); return ActionResult.SUCCESS;
}
player.getHungerManager().add(2, 1);
return ActionResult.SUCCESS;
}
return ActionResult.SUCCESS;
}
else {
return ActionResult.FAIL;
}
}
@Override
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
return super.getPlacementState(itemPlacementContext)
.with(FACING, itemPlacementContext.getPlayerFacing().getOpposite())
.with(BITES, 0);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(BITES);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
switch (state.get(FACING)) {
case NORTH: return NORTH_SHAPE;
case EAST: return EAST_SHAPE;
case SOUTH: return SOUTH_SHAPE;
case WEST: return WEST_SHAPE;
default: return super.getOutlineShape(state, view, pos, context);
}
}
static {
VoxelShape shape = createCuboidShape(0, 0, 0, 16, 5, 16);
EAST_SHAPE = shape;
NORTH_SHAPE = shape;
SOUTH_SHAPE = shape;
WEST_SHAPE = shape;
}
private static VoxelShape rotate(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
return buffer[0];
}
public boolean canPlaceAt(BlockState state, WorldView worldView, BlockPos pos) {
return !worldView.isAir(pos.down());
}
}

View File

@@ -1,71 +1,72 @@
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
public class Plate extends HorizontalFacingBlock {
private static final VoxelShape NORTH_SHAPE;
private static final VoxelShape EAST_SHAPE;
private static final VoxelShape SOUTH_SHAPE;
private static final VoxelShape WEST_SHAPE;
public Plate() {
super(FabricBlockSettings.copy(Blocks.CAKE).nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}
@Override
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
return super.getPlacementState(itemPlacementContext)
.with(FACING, itemPlacementContext.getPlayerFacing().getOpposite());
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
switch (state.get(FACING)) {
case NORTH: return NORTH_SHAPE;
case EAST: return EAST_SHAPE;
case SOUTH: return SOUTH_SHAPE;
case WEST: return WEST_SHAPE;
default: return super.getOutlineShape(state, view, pos, context);
}
}
static {
VoxelShape shape = createCuboidShape(0, 0, 0, 16, 2, 16);
EAST_SHAPE = shape;
NORTH_SHAPE = shape;
SOUTH_SHAPE = shape;
WEST_SHAPE = shape;
}
private static VoxelShape rotate(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
return buffer[0];
}
public boolean canPlaceAt(BlockState state, WorldView worldView, BlockPos pos) {
return !worldView.isAir(pos.down());
}
}
package eu.midnightdust.motschen.dishes;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.entity.EntityContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
public class Plate extends HorizontalFacingBlock {
private static final VoxelShape NORTH_SHAPE;
private static final VoxelShape EAST_SHAPE;
private static final VoxelShape SOUTH_SHAPE;
private static final VoxelShape WEST_SHAPE;
public Plate() {
super(FabricBlockSettings.copyOf(Blocks.CAKE).nonOpaque().sounds(BlockSoundGroup.STONE));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}
@Override
public BlockState getPlacementState(ItemPlacementContext itemPlacementContext) {
return super.getPlacementState(itemPlacementContext)
.with(FACING, itemPlacementContext.getPlayerFacing().getOpposite());
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
switch (state.get(FACING)) {
case NORTH: return NORTH_SHAPE;
case EAST: return EAST_SHAPE;
case SOUTH: return SOUTH_SHAPE;
case WEST: return WEST_SHAPE;
default: return super.getOutlineShape(state, view, pos, context);
}
}
static {
VoxelShape shape = createCuboidShape(0, 0, 0, 16, 2, 16);
EAST_SHAPE = shape;
NORTH_SHAPE = shape;
SOUTH_SHAPE = shape;
WEST_SHAPE = shape;
}
private static VoxelShape rotate(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
int times = (to.getHorizontal() - from.getHorizontal() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
return buffer[0];
}
public boolean canPlaceAt(BlockState state, WorldView worldView, BlockPos pos) {
return !worldView.isAir(pos.down());
}
}