Loot changes - main compiles

This commit is contained in:
modmuss50 2023-05-11 20:55:17 +01:00 committed by modmuss
parent d1e62b2fed
commit 876c6154e1
2 changed files with 22 additions and 8 deletions

View file

@ -30,6 +30,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameterSet;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.registry.tag.BlockTags;
@ -96,12 +97,18 @@ public class BlockBreakerProcessor extends BlockBreakerNbt implements BlockProce
if (!handleBlockInFrontRemoved(blockInFront)) return status;
Item currentBreakingItem = processable.getInventory().getStack(fakeInputSlot).getItem();
ItemStack item = blockInFront.getBlock().asItem().getDefaultStack();
final List<ItemStack> blockDrops;
if (world instanceof ServerWorld serverWorld) {
LootContextParameterSet.Builder builder = new LootContextParameterSet.Builder(serverWorld)
.add(LootContextParameters.ORIGIN, Vec3d.ofCenter(positionInFront))
.add(LootContextParameters.TOOL, TRContent.Machine.BLOCK_BREAKER.getStack());
blockDrops = blockInFront.getDroppedStacks(builder);
} else {
blockDrops = Collections.singletonList(item);
}
List<ItemStack> blockDrops = world instanceof ServerWorld
? blockInFront.getDroppedStacks((new LootContext.Builder((ServerWorld) world)).random(world.random).parameter(LootContextParameters.ORIGIN, Vec3d.ofCenter(positionInFront)).parameter(LootContextParameters.TOOL, TRContent.Machine.BLOCK_BREAKER.getStack()))
: Collections.singletonList(item);
ItemStack blockDrop = blockDrops.isEmpty() ? null : blockDrops.get(0);
if (blockDrop != null) {
blockDrop.setCount(1);

View file

@ -24,6 +24,7 @@
package techreborn.blockentity.machine.tier2;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
@ -32,6 +33,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.LootTables;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameterSet;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.nbt.NbtCompound;
@ -100,7 +102,7 @@ public class FishingStationBlockEntity extends PowerAcceptorBlockEntity implemen
@Override
public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) {
super.tick(world, pos, state, blockEntity);
if (!(world instanceof ServerWorld) || getStored() <= TechRebornConfig.fishingStationEnergyPerCatch || !isActive(RedstoneConfiguration.POWER_IO)) {
if (!(world instanceof ServerWorld serverWorld) || getStored() <= TechRebornConfig.fishingStationEnergyPerCatch || !isActive(RedstoneConfiguration.POWER_IO)) {
return;
}
@ -115,9 +117,14 @@ public class FishingStationBlockEntity extends PowerAcceptorBlockEntity implemen
}
if (getStored() > TechRebornConfig.fishingStationEnergyPerCatch) {
LootContext.Builder builder = (new LootContext.Builder((ServerWorld)this.world)).parameter(LootContextParameters.ORIGIN, new Vec3d(frontPos.getX()+0.5,frontPos.getY()-0.5,frontPos.getZ()+0.5)).parameter(LootContextParameters.TOOL, TRContent.Machine.FISHING_STATION.getStack()).random(world.random);
LootTable lootTable = this.world.getServer().getLootManager().getTable(LootTables.FISHING_GAMEPLAY);
List<ItemStack> list = lootTable.generateLoot(builder.build(LootContextTypes.FISHING));
final LootContextParameterSet lootContextParameterSet = new LootContextParameterSet.Builder(serverWorld)
.add(LootContextParameters.BLOCK_ENTITY, this)
.add(LootContextParameters.ORIGIN, Vec3d.ofCenter(frontPos))
.add(LootContextParameters.TOOL, TRContent.Machine.FISHING_STATION.getStack())
.build(LootContextTypes.FISHING);
final LootTable lootTable = this.getWorld().getServer().getLootManager().getLootTable(LootTables.FISHING_GAMEPLAY);
final ObjectArrayList<ItemStack> list = lootTable.generateLoot(lootContextParameterSet);
insertIntoInv(list);
useEnergy(TechRebornConfig.fishingStationEnergyPerCatch);
}