further progressing
This commit is contained in:
@ -9,7 +9,7 @@
|
|||||||
loader_version=0.14.9
|
loader_version=0.14.9
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.19.2.2
|
mod_version = 1.19.2.3
|
||||||
maven_group = de.jottyfan.minecraft
|
maven_group = de.jottyfan.minecraft
|
||||||
archives_base_name = quickiefabric
|
archives_base_name = quickiefabric
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import java.util.Iterator;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.container.ImplementedInventory;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ItemScatterer;
|
||||||
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
@ -13,14 +16,51 @@ import net.minecraft.world.World;
|
|||||||
* @author jotty
|
* @author jotty
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BlockSpreaderEntity extends BlockEntity {
|
public class BlockSpreaderEntity extends BlockEntity implements ImplementedInventory {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(BlockSpreaderEntity.class);
|
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(9, ItemStack.EMPTY);
|
||||||
|
|
||||||
public BlockSpreaderEntity(BlockPos blockPos, BlockState blockState) {
|
public BlockSpreaderEntity(BlockPos blockPos, BlockState blockState) {
|
||||||
super(QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY, blockPos, blockState);
|
super(QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY, blockPos, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tick(World world, BlockPos pos, BlockState state, BlockSpreaderEntity entity) {
|
public static void tick(World world, BlockPos pos, BlockState state, BlockSpreaderEntity entity) {
|
||||||
LOGGER.debug("not yet implemented");
|
if (!world.isClient) {
|
||||||
|
ItemStack stack = entity.plopNextItemStack();
|
||||||
|
if (stack != null) {
|
||||||
|
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find the next itemstack
|
||||||
|
*
|
||||||
|
* @return the next item stack
|
||||||
|
*/
|
||||||
|
public ItemStack plopNextItemStack() {
|
||||||
|
Iterator<ItemStack> i = inventory.iterator();
|
||||||
|
Integer index = 0;
|
||||||
|
while (i.hasNext()) {
|
||||||
|
ItemStack stack = i.next();
|
||||||
|
if (stack != null && stack.getItem() != null && stack.getCount() > 0) {
|
||||||
|
inventory.get(index).decrement(8);
|
||||||
|
if (stack.getCount() > 8) {
|
||||||
|
stack.setCount(8);
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultedList<ItemStack> getItems() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return inventory.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -96,7 +97,7 @@ public class BlockStackerEntity extends BlockEntity implements NamedScreenHandle
|
|||||||
Item item = findNextItem(entity.getItems(), checked);
|
Item item = findNextItem(entity.getItems(), checked);
|
||||||
while(!found && item != null) {
|
while(!found && item != null) {
|
||||||
checked.add(item);
|
checked.add(item);
|
||||||
Boolean whitelist = true;
|
Boolean whitelist = hasAnyItem(entity.getItems());
|
||||||
found = transferOneStack(lootableSource, lootableDest, item, whitelist);
|
found = transferOneStack(lootableSource, lootableDest, item, whitelist);
|
||||||
item = findNextItem(entity.getItems(), checked);
|
item = findNextItem(entity.getItems(), checked);
|
||||||
}
|
}
|
||||||
@ -104,6 +105,17 @@ public class BlockStackerEntity extends BlockEntity implements NamedScreenHandle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Boolean hasAnyItem(DefaultedList<ItemStack> list) {
|
||||||
|
Iterator<ItemStack> i = list.iterator();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
ItemStack s = i.next();
|
||||||
|
if (s != null && s.getCount() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static final Boolean transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest,
|
private static final Boolean transferOneStack(LootableContainerBlockEntity source, LootableContainerBlockEntity dest,
|
||||||
Item filterItem, Boolean whitelist) {
|
Item filterItem, Boolean whitelist) {
|
||||||
Boolean result = false;
|
Boolean result = false;
|
||||||
@ -189,8 +201,8 @@ public class BlockStackerEntity extends BlockEntity implements NamedScreenHandle
|
|||||||
while (counter > 0) {
|
while (counter > 0) {
|
||||||
counter--;
|
counter--;
|
||||||
ItemStack stack = lcbe.getStack(counter);
|
ItemStack stack = lcbe.getStack(counter);
|
||||||
Boolean found = item.equals(stack.getItem());
|
Boolean found = whitelist ? item.equals(stack.getItem()) : true;
|
||||||
if (whitelist ? found : !found) {
|
if (found) {
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockSpreaderEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockSpreaderEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.QuickieFabricBlockEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.QuickieFabricBlockEntity;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
@ -10,6 +12,8 @@ import net.minecraft.block.Material;
|
|||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.block.entity.BlockEntityTicker;
|
import net.minecraft.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.loot.context.LootContext.Builder;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
@ -40,4 +44,9 @@ public class BlockSpreader extends BlockWithEntity {
|
|||||||
return checkType(type, QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY,
|
return checkType(type, QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY,
|
||||||
(world1, pos, state1, be) -> BlockSpreaderEntity.tick(world1, pos, state1, be));
|
(world1, pos, state1, be) -> BlockSpreaderEntity.tick(world1, pos, state1, be));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSPREADER.asItem()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
@ -60,9 +59,7 @@ public class BlockStackerDown extends BlockWithEntity implements BlockStacker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
List<ItemStack> list = new ArrayList<>();
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERDOWN.asItem()));
|
||||||
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERDOWN.asItem()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
@ -60,9 +59,7 @@ public class BlockStackerEast extends BlockWithEntity implements BlockStacker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
List<ItemStack> list = new ArrayList<>();
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKEREAST.asItem()));
|
||||||
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKEREAST.asItem()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
@ -60,9 +59,7 @@ public class BlockStackerNorth extends BlockWithEntity implements BlockStacker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
List<ItemStack> list = new ArrayList<>();
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERNORTH.asItem()));
|
||||||
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERNORTH.asItem()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
@ -60,9 +59,7 @@ public class BlockStackerSouth extends BlockWithEntity implements BlockStacker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
List<ItemStack> list = new ArrayList<>();
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERSOUTH.asItem()));
|
||||||
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERSOUTH.asItem()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
@ -60,9 +59,7 @@ public class BlockStackerUp extends BlockWithEntity implements BlockStacker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
List<ItemStack> list = new ArrayList<>();
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERUP.asItem()));
|
||||||
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERUP.asItem()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
@ -38,6 +37,11 @@ public class BlockStackerWest extends BlockWithEntity implements BlockStacker {
|
|||||||
super(FabricBlockSettings.of(Material.STONE).hardness(2.5f));
|
super(FabricBlockSettings.of(Material.STONE).hardness(2.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||||
|
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERWEST.asItem()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Direction getSourceOffset() {
|
public Direction getSourceOffset() {
|
||||||
return Direction.EAST;
|
return Direction.EAST;
|
||||||
@ -58,13 +62,6 @@ public class BlockStackerWest extends BlockWithEntity implements BlockStacker {
|
|||||||
return BlockRenderType.MODEL;
|
return BlockRenderType.MODEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
|
||||||
List<ItemStack> list = new ArrayList<>();
|
|
||||||
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERWEST.asItem()));
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
|
||||||
BlockEntityType<T> type) {
|
BlockEntityType<T> type) {
|
||||||
|
@ -6,6 +6,7 @@ import java.util.function.Predicate;
|
|||||||
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.BlockSpreaderEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.DrillBlockDownEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.DrillBlockDownEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.DrillBlockEastEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.DrillBlockEastEntity;
|
||||||
@ -219,6 +220,8 @@ public class RegistryManager {
|
|||||||
"blockstackerentity", BlockStackerEntity::new, QuickieBlocks.BLOCKSTACKERUP, QuickieBlocks.BLOCKSTACKERDOWN,
|
"blockstackerentity", BlockStackerEntity::new, QuickieBlocks.BLOCKSTACKERUP, QuickieBlocks.BLOCKSTACKERDOWN,
|
||||||
QuickieBlocks.BLOCKSTACKEREAST, QuickieBlocks.BLOCKSTACKERWEST, QuickieBlocks.BLOCKSTACKERNORTH,
|
QuickieBlocks.BLOCKSTACKEREAST, QuickieBlocks.BLOCKSTACKERWEST, QuickieBlocks.BLOCKSTACKERNORTH,
|
||||||
QuickieBlocks.BLOCKSTACKERSOUTH);
|
QuickieBlocks.BLOCKSTACKERSOUTH);
|
||||||
|
QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY = (BlockEntityType<BlockSpreaderEntity>) registerBlockEntity(
|
||||||
|
"blockspreaderentity", BlockSpreaderEntity::new, QuickieBlocks.BLOCKSPREADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void registerBlocks() {
|
public static final void registerBlocks() {
|
||||||
|
Reference in New Issue
Block a user