Skip to content

Commit

Permalink
ugh its still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAwesomGuy committed Jun 16, 2024
1 parent d74caf0 commit a5328d2
Show file tree
Hide file tree
Showing 20 changed files with 665 additions and 98 deletions.
18 changes: 16 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
archivesName = project.mod_id
}

repositories {
Expand Down Expand Up @@ -45,8 +45,11 @@ processResources {

doLast {
fileTree(dir: outputs.files.asPath).each {
if (it.name.endsWith(".json"))
if (it.name.endsWith(".json")) {
def parsed = new JsonSlurper().parse(it)
parsed.remove "credits"
it.text = JsonOutput.toJson(new JsonSlurper().parse(it))
}
}
}
}
Expand All @@ -70,6 +73,15 @@ jar {
}

loom {
// splitEnvironmentSourceSets()
//
// mods {
// "${project.mod_id}" {
// sourceSet sourceSets.main
// sourceSet sourceSets.client
// }
// }

mixin {
useLegacyMixinAp = false
}
Expand All @@ -91,4 +103,6 @@ loom {
property 'mixin.debug', 'true'
}
}

accessWidenerPath = file("src/main/resources/${mod_id}.accesswidener")
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21-pre3
yarn_mappings=1.21-pre3+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11

# Mod Properties
mod_version=1.0.0
maven_group=net.anawesomguy.carnivalfoods
archives_base_name=carnival-foods
mod_id=carnival-foods
display_name=Carnival Foods

# Dependencies
fabric_version=0.99.5+1.21
fabric_version=0.100.1+1.21

# Publishing
modrinth_id=
Expand Down
49 changes: 29 additions & 20 deletions src/main/java/net/anawesomguy/carnivalfoods/CarnivalFoods.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package net.anawesomguy.carnivalfoods;

import net.anawesomguy.carnivalfoods.block.CottonCandyMachineBlock;
import net.anawesomguy.carnivalfoods.block.entity.CottonCandyMachineBlockEntity;
import net.anawesomguy.carnivalfoods.item.CottonCandyItem;
import net.fabricmc.api.ModInitializer;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.MapColor;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.component.type.FoodComponent;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.UseAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,37 +25,41 @@
import java.util.Objects;
import java.util.WeakHashMap;

public class CarnivalFoods implements ModInitializer {
public final class CarnivalFoods implements ModInitializer {
public static final String MOD_ID = "carnival-foods";
public static final Logger LOGGER = LoggerFactory.getLogger("carnival-foods");
private static final Map<Item, ModelIdentifier> HELD_ITEMS_PRIVATE = new WeakHashMap<>();
public static final Map<Item, ModelIdentifier> HELD_ITEM_MODELS = Collections.unmodifiableMap(HELD_ITEMS_PRIVATE);

public static final FoodComponent COTTON_CANDY_FOOD = new FoodComponent.Builder()
.statusEffect(new StatusEffectInstance(StatusEffects.SPEED, 5), .5F)
.statusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 2), .3F)
.statusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 3), .25F)
.statusEffect(new StatusEffectInstance(StatusEffects.SPEED, 5), .55F)
.usingConvertsTo(Items.STICK)
.nutrition(1)
.saturationModifier(.2F)
.alwaysEdible()
.snack()
.build();
public static final Item COTTON_CANDY = new Item(new Item.Settings().food(COTTON_CANDY_FOOD)) {
@Override
public UseAction getUseAction(ItemStack stack) {
return UseAction.CROSSBOW;
}
};

public static void addHeldItemModel(Item item, ModelIdentifier modelIdentifier) {
HELD_ITEMS_PRIVATE.put(Objects.requireNonNull(item), modelIdentifier);
}
public static final Block COTTON_CANDY_MACHINE = new CottonCandyMachineBlock(
AbstractBlock.Settings.create()
.mapColor(MapColor.STONE_GRAY)
.requiresTool()
.strength(2F)
.nonOpaque()
);
public static final Item
COTTON_CANDY = new CottonCandyItem(new Item.Settings().food(COTTON_CANDY_FOOD).maxDamage(3)),
COTTON_CANDY_MACHINE_ITEM = new BlockItem(COTTON_CANDY_MACHINE, new Item.Settings());

@Override
public void onInitialize() {
Registry.register(Registries.ITEM, Identifier.of("carnival-foods", "cotton_candy"), COTTON_CANDY);
Registry.register(Registries.ITEM, id("cotton_candy"), COTTON_CANDY);

Identifier cottonCandyMachine = id("cotton_candy_machine");
Registry.register(Registries.BLOCK_ENTITY_TYPE, cottonCandyMachine, CottonCandyMachineBlockEntity.TYPE);
Registry.register(Registries.BLOCK, cottonCandyMachine, COTTON_CANDY_MACHINE);
Registry.register(Registries.ITEM, cottonCandyMachine, COTTON_CANDY_MACHINE_ITEM);
}

static {
HELD_ITEMS_PRIVATE.put(COTTON_CANDY, ModelIdentifier.ofInventoryVariant(Identifier.of("carnival-foods", "items/held_cotton_candy")));
public static Identifier id(String path) {
return Identifier.of(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package net.anawesomguy.carnivalfoods.block;

import com.mojang.serialization.MapCodec;
import net.anawesomguy.carnivalfoods.block.entity.CottonCandyMachineBlockEntity;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.ArrayVoxelShape;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class CottonCandyMachineBlock extends BlockWithEntity {
protected static final VoxelShape SHAPE = VoxelShapes.union(
createCuboidShape(1, 0, 1, 15, 1, 15), // base
createCuboidShape(0.5, 0, 1, 1.5, 2.5, 15), // outer lower
createCuboidShape(13.5, 0, 1, 15.5, 2.5, 15),
createCuboidShape(1, 0, 0.5, 15, 2.5, 1.5),
createCuboidShape(1, 0, 13.5, 15, 2.5, 15.5),
createCuboidShape(0.1, 2.5, 1, 1.1, 5, 15), // outer upper
createCuboidShape(14.9, 2.5, 1, 15.9, 5, 15),
createCuboidShape(0.1, 2.5, 1, 1.1, 5, 15),
createCuboidShape(1, 2.5, 14.9, 15, 5, 15.9)
);

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

@Override
protected MapCodec<? extends BlockWithEntity> getCodec() {
return null;
}

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

@Override
protected BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}

@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (world.isClient)
return ActionResult.PASS;
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof CottonCandyMachineBlockEntity machine) {
for (int i = 0; i < 17; i++) {

}
}

return ActionResult.SUCCESS;
}

@Override
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
}

@Override
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package net.anawesomguy.carnivalfoods.block.entity;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;
import org.jetbrains.annotations.NotNull;

/**
* A simple {@code Inventory} implementation with only default methods + an item list getter. Taken from the Fabric Wiki with minor changes.
* <p>
* Originally by Juuz
*/
public interface BasicInventory extends Inventory {
/**
* Retrieves the item list of this inventory.
* Must return the same instance every time it's called.
*/
@NotNull
DefaultedList<ItemStack> getItems();

/**
* Creates an inventory from the item list.
*/
static BasicInventory of(DefaultedList<ItemStack> items) {
return () -> items;
}

/**
* Creates a new inventory with the specified size.
*/
static BasicInventory ofSize(int size) {
return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
}

/**
* Returns the inventory size.
*/
@Override
default int size() {
return getItems().size();
}

/**
* Checks if the inventory is empty.
* @return true if this inventory has only empty stacks, false otherwise.
*/
@Override
default boolean isEmpty() {
for (int i = 0; i < size(); i++)
if (!getStack(i).isEmpty())
return false;
return true;
}

/**
* Retrieves the item in the slot.
*/
@Override
default ItemStack getStack(int slot) {
return getItems().get(slot);
}

/**
* Removes items from an inventory slot.
* @param slot The slot to remove from.
* @param count How many items to remove. If there are less items in the slot than what are requested,
* takes all items in that slot.
*/
@Override
default ItemStack removeStack(int slot, int count) {
ItemStack result = Inventories.splitStack(getItems(), slot, count);
if (!result.isEmpty())
markDirty();
return result;
}

/**
* Removes all items from an inventory slot.
* @param slot The slot to remove from.
*/
@Override
default ItemStack removeStack(int slot) {
return Inventories.removeStack(getItems(), slot);
}

/**
* Replaces the current stack in an inventory slot with the provided stack.
* @param slot The inventory slot of which to replace the itemstack.
* @param stack The replacing itemstack. If the stack is too big for
* this inventory ({@link Inventory#getMaxCountPerStack()}),
* it gets resized to this inventory's maximum amount.
*/
@Override
default void setStack(int slot, ItemStack stack) {
getItems().set(slot, stack);
if (stack.getCount() > stack.getMaxCount())
stack.setCount(stack.getMaxCount());
}

/**
* Clears the inventory.
*/
@Override
default void clear() {
getItems().clear();
}

/**
* Marks the state as dirty.
* Must be called after changes in the inventory, so that the game can properly save
* the inventory contents and notify neighboring blocks of inventory changes.
*/
@Override
default void markDirty() {
// Override if you want behavior.
}

/**
* @return true if the player can use the inventory, false otherwise.
*/
@Override
default boolean canPlayerUse(PlayerEntity player) {
return true;
}
}
Loading

0 comments on commit a5328d2

Please sign in to comment.