Compare commits
5 Commits
1.21.4
...
1.21.4.fin
Author | SHA1 | Date | |
---|---|---|---|
17a11ce56a | |||
81e45c56ce | |||
c2558a5324 | |||
46a21b03c0 | |||
4ae1e998b0 |
@ -9,7 +9,7 @@ yarn_mappings=1.21.4+build.1
|
|||||||
loader_version=0.16.9
|
loader_version=0.16.9
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.21.4.0
|
mod_version=1.21.4.5
|
||||||
maven_group=de.jottyfan.quickiemod
|
maven_group=de.jottyfan.quickiemod
|
||||||
archives_base_name=quickiemod
|
archives_base_name=quickiemod
|
||||||
|
|
||||||
|
@ -65,9 +65,13 @@ public class Quickiemod implements ModInitializer {
|
|||||||
registerComposterItems();
|
registerComposterItems();
|
||||||
registerLootTableChanges();
|
registerLootTableChanges();
|
||||||
ModItemGroup.registerItemGroup(items, blocks);
|
ModItemGroup.registerItemGroup(items, blocks);
|
||||||
PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> {
|
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
|
||||||
Block oldBlock = state.getBlock();
|
Block oldBlock = state.getBlock();
|
||||||
new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock);
|
if (new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -41,10 +41,11 @@ import net.minecraft.world.World;
|
|||||||
public class BlockDrill extends FallingBlock implements BlockEntityProvider {
|
public class BlockDrill extends FallingBlock implements BlockEntityProvider {
|
||||||
private static final Integer MAX_FUEL = 255;
|
private static final Integer MAX_FUEL = 255;
|
||||||
public static final IntProperty FUEL = IntProperty.of("fuel", 0, MAX_FUEL);
|
public static final IntProperty FUEL = IntProperty.of("fuel", 0, MAX_FUEL);
|
||||||
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("direction", Direction.class, Direction.values());
|
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("direction", Direction.class,
|
||||||
|
Direction.values());
|
||||||
|
|
||||||
public BlockDrill(Identifier identifier, Direction direction) {
|
public BlockDrill(Identifier identifier, Direction direction) {
|
||||||
super(AbstractBlock.Settings.create().hardness(2.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
|
super(AbstractBlock.Settings.create().hardness(0.5f).registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
|
||||||
setDefaultState(getDefaultState().with(FUEL, 0).with(DIRECTION, direction));
|
setDefaultState(getDefaultState().with(FUEL, 0).with(DIRECTION, direction));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,8 +69,20 @@ public class BlockDrill extends FallingBlock implements BlockEntityProvider {
|
|||||||
@Override
|
@Override
|
||||||
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||||
Integer fuelLeft = state.get(FUEL);
|
Integer fuelLeft = state.get(FUEL);
|
||||||
|
Direction dir = state.get(DIRECTION);
|
||||||
world.spawnEntity(
|
world.spawnEntity(
|
||||||
new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.ITEM_CANOLABOTTLE, fuelLeft)));
|
new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModItems.ITEM_CANOLABOTTLE, fuelLeft)));
|
||||||
|
Block thisBlock = ModBlocks.BLOCK_DRILL_DOWN;
|
||||||
|
if (Direction.EAST.equals(dir)) {
|
||||||
|
thisBlock = ModBlocks.BLOCK_DRILL_EAST;
|
||||||
|
} else if (Direction.SOUTH.equals(dir)) {
|
||||||
|
thisBlock = ModBlocks.BLOCK_DRILL_SOUTH;
|
||||||
|
} else if (Direction.WEST.equals(dir)) {
|
||||||
|
thisBlock = ModBlocks.BLOCK_DRILL_WEST;
|
||||||
|
} else if (Direction.NORTH.equals(dir)) {
|
||||||
|
thisBlock = ModBlocks.BLOCK_DRILL_NORTH;
|
||||||
|
}
|
||||||
|
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(thisBlock)));
|
||||||
return super.onBreak(world, pos, state, player);
|
return super.onBreak(world, pos, state, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import net.minecraft.world.World;
|
|||||||
*/
|
*/
|
||||||
public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
|
public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
|
||||||
|
|
||||||
|
|
||||||
private DefaultedList<ItemStack> stacks;
|
private DefaultedList<ItemStack> stacks;
|
||||||
private float suckradius;
|
private float suckradius;
|
||||||
|
|
||||||
@ -44,9 +43,17 @@ public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
|
|||||||
|
|
||||||
public final static boolean setStackToSlots(ItemStack stack, List<ItemStack> stacks) {
|
public final static boolean setStackToSlots(ItemStack stack, List<ItemStack> stacks) {
|
||||||
for (ItemStack slot : stacks) {
|
for (ItemStack slot : stacks) {
|
||||||
|
Integer sum = stack.getCount() + slot.getCount();
|
||||||
if (slot.getItem().equals(stack.getItem())) {
|
if (slot.getItem().equals(stack.getItem())) {
|
||||||
|
if (slot.getItem().getMaxCount() >= sum) {
|
||||||
slot.increment(stack.getCount());
|
slot.increment(stack.getCount());
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
Integer transferSize = 64 - stack.getCount();
|
||||||
|
stack.setCount(stack.getCount() - transferSize);
|
||||||
|
slot.setCount(64);
|
||||||
|
// to not return sth. here so that the next loop will sum up the result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // if not found, seek for an empty stack instead
|
} // if not found, seek for an empty stack instead
|
||||||
for (ItemStack slot : stacks) {
|
for (ItemStack slot : stacks) {
|
||||||
|
@ -7,7 +7,6 @@ import de.jottyfan.quickiemod.Quickiemod;
|
|||||||
import de.jottyfan.quickiemod.item.HarvestRange;
|
import de.jottyfan.quickiemod.item.HarvestRange;
|
||||||
import de.jottyfan.quickiemod.item.ModItems;
|
import de.jottyfan.quickiemod.item.ModItems;
|
||||||
import de.jottyfan.quickiemod.item.ToolRangeable;
|
import de.jottyfan.quickiemod.item.ToolRangeable;
|
||||||
import de.jottyfan.quickiemod.item.ToolSpeedpowderAxe;
|
|
||||||
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;
|
||||||
@ -29,23 +28,40 @@ public class EventBlockBreak {
|
|||||||
UPWARDS, ALL;
|
UPWARDS, ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Block oldBlock) {
|
/**
|
||||||
|
* break surrounding block if item is of ToolRangeable
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* @param blockPos
|
||||||
|
* @param blockState
|
||||||
|
* @param playerEntity
|
||||||
|
* @param oldBlock
|
||||||
|
* @return true if this range breaking routine has been used, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Block oldBlock) {
|
||||||
ItemStack mainHandItemStack = playerEntity.getEquippedStack(EquipmentSlot.MAINHAND);
|
ItemStack mainHandItemStack = playerEntity.getEquippedStack(EquipmentSlot.MAINHAND);
|
||||||
if (mainHandItemStack != null) {
|
if (mainHandItemStack != null) {
|
||||||
Item item = mainHandItemStack.getItem();
|
Item item = mainHandItemStack.getItem();
|
||||||
if (item instanceof ToolRangeable) {
|
if (item instanceof ToolRangeable) {
|
||||||
ToolRangeable tool = (ToolRangeable) item;
|
ToolRangeable tool = (ToolRangeable) item;
|
||||||
if (!world.getBlockState(blockPos).getBlock().equals(oldBlock)) {
|
// not needed when added to before block break
|
||||||
// recreate old block to make it breakable; otherwise, the recursive algorithm stops directly
|
// if (!world.getBlockState(blockPos).getBlock().equals(oldBlock)) {
|
||||||
world.setBlockState(blockPos, oldBlock.getDefaultState());
|
// // recreate old block to make it breakable; otherwise, the recursive algorithm stops directly
|
||||||
}
|
// // this leads to the BUG that blocks with no neighbour will respawn and drop -> unlimited items.
|
||||||
|
// world.setBlockState(blockPos, oldBlock.getDefaultState());
|
||||||
|
// }
|
||||||
int handled = handleRangeableTools(tool, mainHandItemStack, world, oldBlock, blockPos, playerEntity);
|
int handled = handleRangeableTools(tool, mainHandItemStack, world, oldBlock, blockPos, playerEntity);
|
||||||
if (handled >= 255) {
|
if (handled >= 255) {
|
||||||
// reward for using rangeable tool very successful
|
// reward for using rangeable tool very successful
|
||||||
world.spawnEntity(
|
world.spawnEntity(
|
||||||
new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255));
|
new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255));
|
||||||
}
|
}
|
||||||
|
return handled > 0; // this way, a rangeable pickaxe can break a dirt block
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +83,7 @@ public class EventBlockBreak {
|
|||||||
if (tool instanceof Item) {
|
if (tool instanceof Item) {
|
||||||
Item toolItem = (Item) tool; // a rangeable tool should always be an item
|
Item toolItem = (Item) tool; // a rangeable tool should always be an item
|
||||||
List<String> visitedBlocks = new ArrayList<>();
|
List<String> visitedBlocks = new ArrayList<>();
|
||||||
if (tool instanceof ToolSpeedpowderAxe) {
|
if (ModItems.TOOL_SPEEDPOWDERAXE.getName().equals(toolItem.getName())) {
|
||||||
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
|
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
|
||||||
player, true);
|
player, true);
|
||||||
} else if (ModItems.TOOL_SPEEDPOWDERPICKAXE.getName().equals(toolItem.getName())) {
|
} else if (ModItems.TOOL_SPEEDPOWDERPICKAXE.getName().equals(toolItem.getName())) {
|
||||||
@ -116,7 +132,7 @@ public class EventBlockBreak {
|
|||||||
private int breakBlockRecursive(List<String> visitedBlocks, World world, List<Block> validBlocks, BlockPos pos,
|
private int breakBlockRecursive(List<String> visitedBlocks, World world, List<Block> validBlocks, BlockPos pos,
|
||||||
ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, PlayerEntity player,
|
ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, PlayerEntity player,
|
||||||
boolean breakLeaves) {
|
boolean breakLeaves) {
|
||||||
boolean ignoreSpawn = visitedBlocks.size() < 1; // with this, the already broken block can be omitted to spawn
|
// boolean ignoreSpawn = visitedBlocks.size() < 1; // with this, the already broken block can be omitted to spawn
|
||||||
if (visitedBlocks.contains(pos.toString())) {
|
if (visitedBlocks.contains(pos.toString())) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (validBlocks == null) {
|
} else if (validBlocks == null) {
|
||||||
@ -129,9 +145,9 @@ public class EventBlockBreak {
|
|||||||
if (tool.canBreakNeighbors(blockState)) {
|
if (tool.canBreakNeighbors(blockState)) {
|
||||||
Block currentBlock = blockState.getBlock();
|
Block currentBlock = blockState.getBlock();
|
||||||
if (validBlocks.contains(currentBlock)) {
|
if (validBlocks.contains(currentBlock)) {
|
||||||
if (!ignoreSpawn) {
|
// if (!ignoreSpawn) {
|
||||||
Block.dropStacks(blockState, world, pos); // includes xorbs
|
Block.dropStacks(blockState, world, pos); // includes xorbs
|
||||||
}
|
// }
|
||||||
affected += 1;
|
affected += 1;
|
||||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||||
if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) {
|
if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) {
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shapeless",
|
||||||
|
"ingredients": [
|
||||||
|
"quickiemod:speedpowder",
|
||||||
|
"minecraft:moss_block"
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "quickiemod:quickiepowder",
|
||||||
|
"count": 1
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user