mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-12-01 03:48:06 +00:00
gradle=7.1.1, gradle migrateMappings
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.loot.condition.LootCondition;
|
||||
import net.minecraft.loot.condition.LootConditionType;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameter;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.util.Nameable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A loot condition which checks if the tile entity has a name.
|
||||
*/
|
||||
public final class BlockNamedEntityLootCondition implements LootCondition
|
||||
{
|
||||
public static final BlockNamedEntityLootCondition INSTANCE = new BlockNamedEntityLootCondition();
|
||||
public static final LootConditionType TYPE = ConstantLootConditionSerializer.type( INSTANCE );
|
||||
public static final Builder BUILDER = () -> INSTANCE;
|
||||
|
||||
private BlockNamedEntityLootCondition()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test( LootContext lootContext )
|
||||
{
|
||||
BlockEntity tile = lootContext.get( LootContextParameters.BLOCK_ENTITY );
|
||||
return tile instanceof Nameable && ((Nameable) tile).hasCustomName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<LootContextParameter<?>> getRequiredParameters()
|
||||
{
|
||||
return Collections.singleton( LootContextParameters.BLOCK_ENTITY );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootConditionType getType()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import net.minecraft.loot.condition.LootCondition;
|
||||
import net.minecraft.loot.condition.LootConditionType;
|
||||
import net.minecraft.util.JsonSerializer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ConstantLootConditionSerializer<T extends LootCondition> implements JsonSerializer<T>
|
||||
{
|
||||
private final T instance;
|
||||
|
||||
public ConstantLootConditionSerializer( T instance )
|
||||
{
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static <T extends LootCondition> LootConditionType type( T condition )
|
||||
{
|
||||
return new LootConditionType( new ConstantLootConditionSerializer<>( condition ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson( @Nonnull JsonObject json, @Nonnull T object, @Nonnull JsonSerializationContext context )
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public T fromJson( @Nonnull JsonObject json, @Nonnull JsonDeserializationContext context )
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.block.entity.BlockEntity;
|
||||
import net.minecraft.loot.condition.LootCondition;
|
||||
import net.minecraft.loot.condition.LootConditionType;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameter;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A loot condition which checks if the tile entity has has a non-0 ID.
|
||||
*/
|
||||
public final class HasComputerIdLootCondition implements LootCondition
|
||||
{
|
||||
public static final HasComputerIdLootCondition INSTANCE = new HasComputerIdLootCondition();
|
||||
public static final LootConditionType TYPE = ConstantLootConditionSerializer.type( INSTANCE );
|
||||
public static final Builder BUILDER = () -> INSTANCE;
|
||||
|
||||
private HasComputerIdLootCondition()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test( LootContext lootContext )
|
||||
{
|
||||
BlockEntity tile = lootContext.get( LootContextParameters.BLOCK_ENTITY );
|
||||
return tile instanceof IComputerTile && ((IComputerTile) tile).getComputerID() >= 0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<LootContextParameter<?>> getRequiredParameters()
|
||||
{
|
||||
return Collections.singleton( LootContextParameters.BLOCK_ENTITY );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootConditionType getType()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.loot.condition.LootCondition;
|
||||
import net.minecraft.loot.condition.LootConditionType;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameter;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A loot condition which checks if the entity is in creative mode.
|
||||
*/
|
||||
public final class PlayerCreativeLootCondition implements LootCondition
|
||||
{
|
||||
public static final PlayerCreativeLootCondition INSTANCE = new PlayerCreativeLootCondition();
|
||||
public static final LootConditionType TYPE = ConstantLootConditionSerializer.type( INSTANCE );
|
||||
public static final Builder BUILDER = () -> INSTANCE;
|
||||
|
||||
private PlayerCreativeLootCondition()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test( LootContext lootContext )
|
||||
{
|
||||
Entity entity = lootContext.get( LootContextParameters.THIS_ENTITY );
|
||||
return entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.creativeMode;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<LootContextParameter<?>> getRequiredParameters()
|
||||
{
|
||||
return Collections.singleton( LootContextParameters.THIS_ENTITY );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootConditionType getType()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user