-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d74caf0
commit a5328d2
Showing
20 changed files
with
665 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/net/anawesomguy/carnivalfoods/block/CottonCandyMachineBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
src/main/java/net/anawesomguy/carnivalfoods/block/entity/BasicInventory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.