Skip to content

Commit

Permalink
Fix bound machines not dropping a bound machine block on break
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Apr 8, 2024
1 parent 4941690 commit bb43770
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-gametests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
type: string

jobs:
datagen:
name: Data Generators
run-tests:
name: Run Game Testss
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import dev.compactmods.machines.datagen.compat.curios.CurioEntityGenerator;
import dev.compactmods.machines.datagen.compat.curios.CurioSlotGenerator;
import dev.compactmods.machines.datagen.lang.EnglishLangGenerator;
import dev.compactmods.machines.datagen.loot.BlockLootGenerator;
import dev.compactmods.machines.datagen.tags.BlockTagGenerator;
import dev.compactmods.machines.datagen.tags.ItemTagGenerator;
import dev.compactmods.machines.datagen.tags.PointOfInterestTagGenerator;
import net.minecraft.data.DataProvider;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.neoforged.bus.api.SubscribeEvent;
Expand All @@ -31,7 +31,7 @@ public static void gatherData(GatherDataEvent event) {
// Server
boolean server = event.includeServer();
generator.addProvider(server, new DatapackRegisteredStuff(packOut, holderLookup));
generator.addProvider(server, (DataProvider.Factory<LootTableProvider>) output -> new LootTableProvider(output,
generator.addProvider(server, new LootTableProvider(packOut,
Collections.emptySet(),
List.of(new LootTableProvider.SubProviderEntry(BlockLootGenerator::new, LootContextParamSets.BLOCK))
));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
package dev.compactmods.machines.datagen;
package dev.compactmods.machines.datagen.loot;

import dev.compactmods.machines.neoforge.data.functions.CopyRoomBindingFunction;
import dev.compactmods.machines.neoforge.machine.Machines;
import dev.compactmods.machines.neoforge.room.Rooms;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.data.loot.LootTableSubProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;

import java.util.Collections;
import java.util.Set;
import java.util.function.BiConsumer;

public class BlockLootGenerator implements LootTableSubProvider {
public class BlockLootGenerator extends BlockLootSubProvider {

public BlockLootGenerator() {
super(Collections.emptySet(), FeatureFlags.REGISTRY.allFlags());
}

@Override
protected Iterable<Block> getKnownBlocks() {
return Set.of(Rooms.BLOCK_BREAKABLE_WALL.get(), Machines.MACHINE_BLOCK.get());
}

@Override
public void generate(BiConsumer<ResourceLocation, LootTable.Builder> biConsumer) {
biConsumer.accept(Rooms.BLOCK_BREAKABLE_WALL.getId(), LootTable.lootTable().withPool(LootPool
protected void generate() {
this.add(Rooms.BLOCK_BREAKABLE_WALL.get(), LootTable.lootTable().withPool(LootPool
.lootPool()
.name(Rooms.BLOCK_BREAKABLE_WALL.getId().toString())
.setRolls(ConstantValue.exactly(1))
.when(ExplosionCondition.survivesExplosion())
.add(LootItem.lootTableItem(Rooms.ITEM_BREAKABLE_WALL.get()))));

// Compact Machines
biConsumer.accept(Machines.MACHINE_BLOCK.getId(), LootTable.lootTable().withPool(LootPool.lootPool()
.name(Machines.MACHINE_BLOCK.getId().toString())
var drop = LootItem.lootTableItem(Machines.BOUND_MACHINE_BLOCK_ITEM.get());

final var lootPoolCM = LootPool.lootPool()
.setRolls(ConstantValue.exactly(1))
.when(ExplosionCondition.survivesExplosion())
.apply(CopyRoomBindingFunction::new)
.add(LootItem.lootTableItem(Machines.BOUND_MACHINE_BLOCK_ITEM.get()))));
.add(drop);

final var cmLootTable = LootTable.lootTable().withPool(lootPoolCM);

this.add(Machines.MACHINE_BLOCK.get(), cmLootTable);
}
}

0 comments on commit bb43770

Please sign in to comment.