1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-05 19:42:54 +00:00
CC-Tweaked/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java
Jonathan Coates 34b5ede326 Switch to Mojang mappings
ForgeGradle (probably sensibly) yells at me about doing this. However:
 - There's a reasonable number of mods doing this, which establishes
   some optimistic precedent.
 - The licence update in Aug 2020 now allows you to use them for
   "development purposes". I guess source code counts??
 - I'm fairly sure this is also compatible with the CCPL - there's an
   exception for Minecraft code.

The main motivation for this is to make the Fabric port a little
easier. Hopefully folks (maybe me in the future, we'll see) will no
longer have to deal with mapping hell when merging - only mod loader
hell.
2021-01-09 19:22:58 +00:00

51 lines
1.5 KiB
Java

/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.data;
import dan200.computercraft.shared.computer.blocks.IComputerTile;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootParameter;
import net.minecraft.world.storage.loot.LootParameters;
import net.minecraft.world.storage.loot.conditions.ILootCondition;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Set;
import net.minecraft.world.storage.loot.conditions.ILootCondition.IBuilder;
/**
* A loot condition which checks if the tile entity has has a non-0 ID.
*/
public final class HasComputerIdLootCondition implements ILootCondition
{
public static final HasComputerIdLootCondition INSTANCE = new HasComputerIdLootCondition();
private HasComputerIdLootCondition()
{
}
@Override
public boolean test( LootContext lootContext )
{
TileEntity tile = lootContext.getParamOrNull( LootParameters.BLOCK_ENTITY );
return tile instanceof IComputerTile && ((IComputerTile) tile).getComputerID() >= 0;
}
@Nonnull
@Override
public Set<LootParameter<?>> getReferencedContextParams()
{
return Collections.singleton( LootParameters.BLOCK_ENTITY );
}
public static IBuilder builder()
{
return () -> INSTANCE;
}
}