further progressing

This commit is contained in:
Jottyfan 2022-11-30 22:25:35 +01:00
parent dedcd63fdb
commit f8fea314bd
11 changed files with 83 additions and 37 deletions

View File

@ -9,7 +9,7 @@
loader_version=0.14.9
# Mod Properties
mod_version = 1.19.2.2
mod_version = 1.19.2.3
maven_group = de.jottyfan.minecraft
archives_base_name = quickiefabric

View File

@ -1,10 +1,13 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Iterator;
import de.jottyfan.minecraft.quickiefabric.container.ImplementedInventory;
import net.minecraft.block.BlockState;
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.world.World;
@ -13,14 +16,51 @@ import net.minecraft.world.World;
* @author jotty
*
*/
public class BlockSpreaderEntity extends BlockEntity {
private static final Logger LOGGER = LogManager.getLogger(BlockSpreaderEntity.class);
public class BlockSpreaderEntity extends BlockEntity implements ImplementedInventory {
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(9, ItemStack.EMPTY);
public BlockSpreaderEntity(BlockPos blockPos, BlockState blockState) {
super(QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY, blockPos, blockState);
}
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();
}
}

View File

@ -1,6 +1,7 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
@ -96,7 +97,7 @@ public class BlockStackerEntity extends BlockEntity implements NamedScreenHandle
Item item = findNextItem(entity.getItems(), checked);
while(!found && item != null) {
checked.add(item);
Boolean whitelist = true;
Boolean whitelist = hasAnyItem(entity.getItems());
found = transferOneStack(lootableSource, lootableDest, item, whitelist);
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,
Item filterItem, Boolean whitelist) {
Boolean result = false;
@ -189,8 +201,8 @@ public class BlockStackerEntity extends BlockEntity implements NamedScreenHandle
while (counter > 0) {
counter--;
ItemStack stack = lcbe.getStack(counter);
Boolean found = item.equals(stack.getItem());
if (whitelist ? found : !found) {
Boolean found = whitelist ? item.equals(stack.getItem()) : true;
if (found) {
return counter;
}
}

View File

@ -1,5 +1,7 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockSpreaderEntity;
import de.jottyfan.minecraft.quickiefabric.blockentity.QuickieFabricBlockEntity;
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.BlockEntityTicker;
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.world.World;
@ -40,4 +44,9 @@ public class BlockSpreader extends BlockWithEntity {
return checkType(type, QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY,
(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()));
}
}

View File

@ -1,6 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
@ -60,9 +59,7 @@ public class BlockStackerDown extends BlockWithEntity implements BlockStacker {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERDOWN.asItem()));
return list;
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERDOWN.asItem()));
}
@Override

View File

@ -1,6 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
@ -60,9 +59,7 @@ public class BlockStackerEast extends BlockWithEntity implements BlockStacker {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKEREAST.asItem()));
return list;
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKEREAST.asItem()));
}
@Override

View File

@ -1,6 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
@ -60,9 +59,7 @@ public class BlockStackerNorth extends BlockWithEntity implements BlockStacker {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERNORTH.asItem()));
return list;
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERNORTH.asItem()));
}
@Override

View File

@ -1,6 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
@ -60,9 +59,7 @@ public class BlockStackerSouth extends BlockWithEntity implements BlockStacker {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERSOUTH.asItem()));
return list;
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERSOUTH.asItem()));
}
@Override

View File

@ -1,6 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blockentity.BlockStackerEntity;
@ -60,9 +59,7 @@ public class BlockStackerUp extends BlockWithEntity implements BlockStacker {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
list.add(new ItemStack(QuickieBlocks.BLOCKSTACKERUP.asItem()));
return list;
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERUP.asItem()));
}
@Override

View File

@ -1,6 +1,5 @@
package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList;
import java.util.List;
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));
}
@Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
return List.of(new ItemStack(QuickieBlocks.BLOCKSTACKERWEST.asItem()));
}
@Override
public Direction getSourceOffset() {
return Direction.EAST;
@ -58,13 +62,6 @@ public class BlockStackerWest extends BlockWithEntity implements BlockStacker {
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
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state,
BlockEntityType<T> type) {

View File

@ -6,6 +6,7 @@ import java.util.function.Predicate;
import org.apache.logging.log4j.LogManager;
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.DrillBlockDownEntity;
import de.jottyfan.minecraft.quickiefabric.blockentity.DrillBlockEastEntity;
@ -219,6 +220,8 @@ public class RegistryManager {
"blockstackerentity", BlockStackerEntity::new, QuickieBlocks.BLOCKSTACKERUP, QuickieBlocks.BLOCKSTACKERDOWN,
QuickieBlocks.BLOCKSTACKEREAST, QuickieBlocks.BLOCKSTACKERWEST, QuickieBlocks.BLOCKSTACKERNORTH,
QuickieBlocks.BLOCKSTACKERSOUTH);
QuickieFabricBlockEntity.BLOCKSPREADER_ENTITY = (BlockEntityType<BlockSpreaderEntity>) registerBlockEntity(
"blockspreaderentity", BlockSpreaderEntity::new, QuickieBlocks.BLOCKSPREADER);
}
public static final void registerBlocks() {