started with itemhoarder
This commit is contained in:
parent
842f04baca
commit
a18f18ec2b
@ -17,6 +17,7 @@ public class QuickieFabric implements ModInitializer {
|
|||||||
RegistryManager.registerTools();
|
RegistryManager.registerTools();
|
||||||
RegistryManager.registerEvents();
|
RegistryManager.registerEvents();
|
||||||
RegistryManager.registerBlocks();
|
RegistryManager.registerBlocks();
|
||||||
|
RegistryManager.registerBlockEntities();
|
||||||
Registry.BIOME.forEach(RegistryManager::handleBiome);
|
Registry.BIOME.forEach(RegistryManager::handleBiome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,130 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import net.minecraft.nbt.Tag;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ItemHoarderBlockEntity extends BlockEntity {
|
||||||
|
|
||||||
|
private final String NBT_STACKS = "stacks";
|
||||||
|
private final List<ItemStack> stacks;
|
||||||
|
|
||||||
|
public ItemHoarderBlockEntity() {
|
||||||
|
super(QuickieFabricBlockEntity.ITEMHOARDER);
|
||||||
|
stacks = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Integer getNextFreeEmptyStackPosition() {
|
||||||
|
Integer emptyStackPosition = null;
|
||||||
|
Iterator<ItemStack> it = stacks.iterator();
|
||||||
|
Integer index = 0;
|
||||||
|
while (emptyStackPosition == null && it.hasNext()) {
|
||||||
|
ItemStack s = it.next();
|
||||||
|
if (s.isEmpty()) {
|
||||||
|
emptyStackPosition = index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return emptyStackPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: see https://fabricmc.net/wiki/tutorial:containers for a real chest
|
||||||
|
// TODO: find a way to suck in the surrounding items
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void tick() {
|
||||||
|
// BlockPos pos = getPos();
|
||||||
|
// World world = getWorld();
|
||||||
|
// // list all items around here
|
||||||
|
// AxisAlignedBB aabb = new AxisAlignedBB(pos).grow(4);
|
||||||
|
// List<ItemEntity> itemEntities = world.getEntitiesWithinAABB(ItemEntity.class, aabb);
|
||||||
|
// boolean dirty = false;
|
||||||
|
// for (ItemEntity itemEntity : itemEntities) {
|
||||||
|
// if (itemEntity.isAlive()) {
|
||||||
|
// ItemStack stack = itemEntity.getItem();
|
||||||
|
// if (stack != null) {
|
||||||
|
// Integer emptyStackPosition = getNextFreeEmptyStackPosition();
|
||||||
|
// if (emptyStackPosition == null) {
|
||||||
|
// } else {
|
||||||
|
// stacks.set(emptyStackPosition, stack);
|
||||||
|
// itemEntity.remove();
|
||||||
|
// dirty = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// itemEntity.getItem().getItem().getRegistryName().getPath());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (dirty) {
|
||||||
|
// resortStacks();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resort item stacks to be more efficient
|
||||||
|
*/
|
||||||
|
private void resortStacks() {
|
||||||
|
Map<Text, ItemStack> map = new HashMap<>();
|
||||||
|
Integer clearAmount = stacks.size();
|
||||||
|
for (ItemStack stack : stacks) {
|
||||||
|
ItemStack found = map.get(stack.getName());
|
||||||
|
if (found == null) {
|
||||||
|
found = stack;
|
||||||
|
map.put(stack.getName(), found);
|
||||||
|
} else {
|
||||||
|
found.setCount(found.getCount() + stack.getCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Integer i = 0; i < clearAmount; i++) {
|
||||||
|
stacks.set(i, ItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
Integer index = 0;
|
||||||
|
for (ItemStack stack : map.values()) {
|
||||||
|
stacks.set(index++, stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
|
super.toTag(tag);
|
||||||
|
ListTag listTag = new ListTag();
|
||||||
|
for (ItemStack stack : stacks) {
|
||||||
|
listTag.add(stack.toTag(tag));
|
||||||
|
}
|
||||||
|
tag.put(NBT_STACKS, listTag);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromTag(BlockState state, CompoundTag tag) {
|
||||||
|
super.fromTag(state, tag);
|
||||||
|
ListTag listTag = (ListTag) tag.get(NBT_STACKS);
|
||||||
|
ListIterator<Tag> i = listTag.listIterator();
|
||||||
|
stacks.clear();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
CompoundTag foundTag = (CompoundTag) i.next();
|
||||||
|
ItemStack stack = ItemStack.fromTag(foundTag);
|
||||||
|
stacks.add(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ItemStack> getStacks() {
|
||||||
|
return stacks;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
||||||
|
|
||||||
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class QuickieFabricBlockEntity {
|
||||||
|
public static BlockEntityType<ItemHoarderBlockEntity> ITEMHOARDER;
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.blockentity.ItemHoarderBlockEntity;
|
||||||
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
|
import net.minecraft.block.Material;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BlockItemhoarder extends Block implements BlockEntityProvider {
|
||||||
|
|
||||||
|
public BlockItemhoarder() {
|
||||||
|
super(FabricBlockSettings.of(Material.WOOD).hardness(2.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockEntity createBlockEntity(BlockView arg0) {
|
||||||
|
return new ItemHoarderBlockEntity();
|
||||||
|
}
|
||||||
|
}
|
@ -13,4 +13,5 @@ public class QuickieBlocks {
|
|||||||
public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor();
|
public static final BlockOreSulphor ORE_SULPHOR = new BlockOreSulphor();
|
||||||
public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter();
|
public static final BlockSandSalpeter SAND_SALPETER = new BlockSandSalpeter();
|
||||||
public static final BlockLavahoarder LAVAHOARDER = new BlockLavahoarder();
|
public static final BlockLavahoarder LAVAHOARDER = new BlockLavahoarder();
|
||||||
|
public static final BlockItemhoarder ITEMHOARDER = new BlockItemhoarder();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import java.util.List;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.blockentity.ItemHoarderBlockEntity;
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.blockentity.QuickieFabricBlockEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
|
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
|
||||||
import de.jottyfan.minecraft.quickiefabric.event.BreakBlockCallback;
|
import de.jottyfan.minecraft.quickiefabric.event.BreakBlockCallback;
|
||||||
import de.jottyfan.minecraft.quickiefabric.event.EventBlockBreak;
|
import de.jottyfan.minecraft.quickiefabric.event.EventBlockBreak;
|
||||||
@ -15,6 +17,7 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
@ -41,7 +44,8 @@ public class RegistryManager {
|
|||||||
|
|
||||||
private static final String QUICKIEFABRIC = "quickiefabric";
|
private static final String QUICKIEFABRIC = "quickiefabric";
|
||||||
|
|
||||||
public static final ItemGroup QUICKIEFABRIC_GROUP = FabricItemGroupBuilder.create(new Identifier(QUICKIEFABRIC, "all")).icon(() -> new ItemStack(QuickieItems.SPEEDPOWDER)).appendItems(stacks -> {
|
public static final ItemGroup QUICKIEFABRIC_GROUP = FabricItemGroupBuilder.create(new Identifier(QUICKIEFABRIC, "all")).icon(() -> new ItemStack(QuickieItems.SPEEDPOWDER))
|
||||||
|
.appendItems(stacks -> {
|
||||||
stacks.add(new ItemStack(QuickieItems.SALPETER));
|
stacks.add(new ItemStack(QuickieItems.SALPETER));
|
||||||
stacks.add(new ItemStack(QuickieItems.SULPHOR));
|
stacks.add(new ItemStack(QuickieItems.SULPHOR));
|
||||||
stacks.add(new ItemStack(QuickieItems.SPEEDPOWDER));
|
stacks.add(new ItemStack(QuickieItems.SPEEDPOWDER));
|
||||||
@ -57,6 +61,7 @@ public class RegistryManager {
|
|||||||
stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR));
|
stacks.add(new ItemStack(QuickieBlocks.ORE_SULPHOR));
|
||||||
stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER));
|
stacks.add(new ItemStack(QuickieBlocks.SAND_SALPETER));
|
||||||
stacks.add(new ItemStack(QuickieBlocks.LAVAHOARDER));
|
stacks.add(new ItemStack(QuickieBlocks.LAVAHOARDER));
|
||||||
|
stacks.add(new ItemStack(QuickieBlocks.ITEMHOARDER));
|
||||||
}).build();
|
}).build();
|
||||||
|
|
||||||
private static final void registerBlock(Block block, String name) {
|
private static final void registerBlock(Block block, String name) {
|
||||||
@ -68,6 +73,11 @@ public class RegistryManager {
|
|||||||
Registry.register(Registry.ITEM, new Identifier(QUICKIEFABRIC, name), item);
|
Registry.register(Registry.ITEM, new Identifier(QUICKIEFABRIC, name), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final void registerBlockEntities() {
|
||||||
|
QuickieFabricBlockEntity.ITEMHOARDER = Registry.register(Registry.BLOCK_ENTITY_TYPE, QUICKIEFABRIC + ":itemhoarderblockentity",
|
||||||
|
BlockEntityType.Builder.create(ItemHoarderBlockEntity::new, QuickieBlocks.ITEMHOARDER).build(null));
|
||||||
|
}
|
||||||
|
|
||||||
public static final void registerBlocks() {
|
public static final void registerBlocks() {
|
||||||
LOGGER.debug("registering quickiefabric blocks");
|
LOGGER.debug("registering quickiefabric blocks");
|
||||||
registerBlock(QuickieBlocks.DIRT_SALPETER, "dirtsalpeter");
|
registerBlock(QuickieBlocks.DIRT_SALPETER, "dirtsalpeter");
|
||||||
@ -77,6 +87,7 @@ public class RegistryManager {
|
|||||||
registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor");
|
registerBlock(QuickieBlocks.ORE_SULPHOR, "oresulphor");
|
||||||
registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter");
|
registerBlock(QuickieBlocks.SAND_SALPETER, "sandsalpeter");
|
||||||
registerBlock(QuickieBlocks.LAVAHOARDER, "lavahoarder");
|
registerBlock(QuickieBlocks.LAVAHOARDER, "lavahoarder");
|
||||||
|
registerBlock(QuickieBlocks.ITEMHOARDER, "itemhoarder");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void registerItems() {
|
public static final void registerItems() {
|
||||||
@ -106,14 +117,22 @@ public class RegistryManager {
|
|||||||
/**
|
/**
|
||||||
* generate ores
|
* generate ores
|
||||||
*
|
*
|
||||||
* @param biome the biome to generate the veins in
|
* @param biome
|
||||||
* @param target the block to be replaced
|
* the biome to generate the veins in
|
||||||
* @param block the block that is the replacement
|
* @param target
|
||||||
* @param veinsize the size of the vein
|
* the block to be replaced
|
||||||
* @param count the number of veins in a chunk
|
* @param block
|
||||||
* @param bottomOffset the lower limit
|
* the block that is the replacement
|
||||||
* @param topOffset the upper limit
|
* @param veinsize
|
||||||
* @param maximum the maximum number of blocks in a vein
|
* the size of the vein
|
||||||
|
* @param count
|
||||||
|
* the number of veins in a chunk
|
||||||
|
* @param bottomOffset
|
||||||
|
* the lower limit
|
||||||
|
* @param topOffset
|
||||||
|
* the upper limit
|
||||||
|
* @param maximum
|
||||||
|
* the maximum number of blocks in a vein
|
||||||
*/
|
*/
|
||||||
public static void generateOreForTarget(Biome biome, Target target, Block block, int veinsize, int count, int bottomOffset, int topOffset, int maximum) {
|
public static void generateOreForTarget(Biome biome, Target target, Block block, int veinsize, int count, int bottomOffset, int topOffset, int maximum) {
|
||||||
OreFeatureConfig ofc = new OreFeatureConfig(target, block.getDefaultState(), veinsize);
|
OreFeatureConfig ofc = new OreFeatureConfig(target, block.getDefaultState(), veinsize);
|
||||||
@ -124,19 +143,24 @@ public class RegistryManager {
|
|||||||
/**
|
/**
|
||||||
* generate ore instead of block
|
* generate ore instead of block
|
||||||
*
|
*
|
||||||
* @param biome the biome
|
* @param biome
|
||||||
* @param placeOn the list of blockStates underneath
|
* the biome
|
||||||
* @param placeIn the list of blockStates to be replaced
|
* @param placeOn
|
||||||
* @param placeUnder the list of blockStates above
|
* the list of blockStates underneath
|
||||||
* @param block the block to set
|
* @param placeIn
|
||||||
* @param chance the chance for the replacement
|
* the list of blockStates to be replaced
|
||||||
|
* @param placeUnder
|
||||||
|
* the list of blockStates above
|
||||||
|
* @param block
|
||||||
|
* the block to set
|
||||||
|
* @param chance
|
||||||
|
* the chance for the replacement
|
||||||
*/
|
*/
|
||||||
public static void generateOreInBlocks(Biome biome, List<BlockState> placeOn, List<BlockState> placeIn, List<BlockState> placeUnder, Block block, float chance) {
|
public static void generateOreInBlocks(Biome biome, List<BlockState> placeOn, List<BlockState> placeIn, List<BlockState> placeUnder, Block block, float chance) {
|
||||||
SimpleBlockFeatureConfig sbfc = new SimpleBlockFeatureConfig(block.getDefaultState(), placeOn, placeIn, placeUnder);
|
SimpleBlockFeatureConfig sbfc = new SimpleBlockFeatureConfig(block.getDefaultState(), placeOn, placeIn, placeUnder);
|
||||||
biome.addFeature(GenerationStep.Feature.LOCAL_MODIFICATIONS, Feature.SIMPLE_BLOCK.configure(sbfc).withChance(chance).feature);
|
biome.addFeature(GenerationStep.Feature.LOCAL_MODIFICATIONS, Feature.SIMPLE_BLOCK.configure(sbfc).withChance(chance).feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add the quickiefabric ores to the biome
|
* add the quickiefabric ores to the biome
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "quickiefabric:block/itemhoarder"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "quickiefabric:block/itemhoarder"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"parent": "quickiefabric:block/itemhoarder",
|
||||||
|
"display": {
|
||||||
|
"thirdperson": {
|
||||||
|
"rotation": [ 10, -45, 170 ],
|
||||||
|
"translation": [ 0, 1.5, -2.75 ],
|
||||||
|
"scale": [ 0.375, 0.375, 0.375 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"pattern": [
|
||||||
|
"ooo",
|
||||||
|
"oso",
|
||||||
|
"ooo"
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"o": {
|
||||||
|
"item": "quickiefabric:speedpowder"
|
||||||
|
},
|
||||||
|
"s": {
|
||||||
|
"item": "minecraft:chest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "quickiefabric:itemhoarder",
|
||||||
|
"count": 1
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user