mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-21 06:26:55 +00:00
Allow cleaning dyed turtles in a cauldron
Fixes #771. This does not allow clearing pocket computers or disks right now - neither normally responds very well to water!
This commit is contained in:
parent
9142ccfc93
commit
f96d923b2a
@ -13,14 +13,21 @@ import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputerBase;
|
||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.CauldronBlock;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -161,4 +168,27 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
|
||||
CompoundNBT tag = stack.getTag();
|
||||
return tag != null && tag.contains( NBT_FUEL ) ? tag.getInt( NBT_FUEL ) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUseFirst( ItemStack stack, ItemUseContext context )
|
||||
{
|
||||
if( context.isSecondaryUseActive() || getColour( stack ) == -1 ) return ActionResultType.PASS;
|
||||
|
||||
World level = context.getLevel();
|
||||
BlockPos pos = context.getClickedPos();
|
||||
|
||||
BlockState blockState = level.getBlockState( pos );
|
||||
if( blockState.getBlock() != Blocks.CAULDRON ) return ActionResultType.PASS;
|
||||
|
||||
int waterLevel = blockState.getValue( CauldronBlock.LEVEL );
|
||||
if( waterLevel <= 0 ) return ActionResultType.PASS;
|
||||
|
||||
if( !level.isClientSide )
|
||||
{
|
||||
((CauldronBlock) blockState.getBlock()).setWaterLevel( level, pos, blockState, waterLevel - 1 );
|
||||
IColouredItem.setColourBasic( stack, -1 );
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class TurtleTest {
|
||||
suspend fun `Place waterlogged`(context: TestContext) = context.checkComputerOk(7)
|
||||
|
||||
/**
|
||||
* Checks turtles can place when waterlogged.
|
||||
* Checks turtles can pick up lava
|
||||
*
|
||||
* @see [#297](https://github.com/SquidDev-CC/CC-Tweaked/issues/297)
|
||||
*/
|
||||
@ -41,7 +41,7 @@ class TurtleTest {
|
||||
suspend fun `Gather lava`(context: TestContext) = context.checkComputerOk(8)
|
||||
|
||||
/**
|
||||
* Checks turtles can place when waterlogged.
|
||||
* Checks turtles can hoe dirt.
|
||||
*
|
||||
* @see [#258](https://github.com/SquidDev-CC/CC-Tweaked/issues/258)
|
||||
*/
|
||||
@ -57,9 +57,15 @@ class TurtleTest {
|
||||
suspend fun `Place monitor`(context: TestContext) = context.checkComputerOk(10)
|
||||
|
||||
/**
|
||||
* Checks computers can place into compostors. These are non-typical inventories, so
|
||||
* worth ensuring.
|
||||
* Checks turtles can place into compostors. These are non-typical inventories, so
|
||||
* worth testing.
|
||||
*/
|
||||
@GameTest
|
||||
suspend fun `Use compostors`(context: TestContext) = context.checkComputerOk(11)
|
||||
|
||||
/**
|
||||
* Checks turtles can be cleaned in cauldrons.
|
||||
*/
|
||||
@GameTest
|
||||
suspend fun `Cleaned with cauldrons`(context: TestContext) = context.checkComputerOk(12)
|
||||
}
|
||||
|
@ -15,3 +15,11 @@ function test.eq(expected, actual, msg)
|
||||
if msg then message = ("%s - %s"):format(msg, message) end
|
||||
test.fail(message)
|
||||
end
|
||||
|
||||
function test.neq(expected, actual, msg)
|
||||
if expected ~= actual then return end
|
||||
|
||||
local message = ("Assertion failed:\nExpected something different to %s"):format(expected)
|
||||
if msg then message = ("%s - %s"):format(msg, message) end
|
||||
test.fail(message)
|
||||
end
|
||||
|
10
src/test/server-files/computers/computer/12/startup.lua
Normal file
10
src/test/server-files/computers/computer/12/startup.lua
Normal file
@ -0,0 +1,10 @@
|
||||
local old_details = turtle.getItemDetail(1, true)
|
||||
|
||||
test.assert(turtle.place(), "Dyed turtle")
|
||||
|
||||
local new_details = turtle.getItemDetail(1, true)
|
||||
test.eq("computercraft:turtle_normal", new_details.name, "Still a turtle")
|
||||
test.neq(old_details.nbt, new_details.nbt, "Colour has changed")
|
||||
|
||||
test.ok()
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"computer": 11
|
||||
"computer": 12
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
{
|
||||
size: [3, 3, 3],
|
||||
entities: [],
|
||||
blocks: [
|
||||
{
|
||||
pos: [0, 0, 0],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [1, 0, 0],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [2, 0, 0],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [0, 0, 1],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [1, 0, 1],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [2, 0, 1],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [0, 0, 2],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [1, 0, 2],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
pos: [2, 0, 2],
|
||||
state: 0
|
||||
},
|
||||
{
|
||||
nbt: {
|
||||
Owner: {
|
||||
UpperId: 4039158846114182220L,
|
||||
LowerId: -6876936588741668278L,
|
||||
Name: "Dev"
|
||||
},
|
||||
Fuel: 0,
|
||||
Label: "Clean turtle",
|
||||
Slot: 0,
|
||||
Items: [
|
||||
{
|
||||
Slot: 0b,
|
||||
id: "computercraft:turtle_normal",
|
||||
Count: 1b,
|
||||
tag: {
|
||||
display: {
|
||||
Name: '{"text":"Clean turtle"}'
|
||||
},
|
||||
Color: 13388876,
|
||||
ComputerId: 12
|
||||
}
|
||||
}
|
||||
],
|
||||
id: "computercraft:turtle_normal",
|
||||
ComputerId: 12,
|
||||
On: 1b
|
||||
},
|
||||
pos: [1, 1, 0],
|
||||
state: 1
|
||||
},
|
||||
{
|
||||
pos: [0, 1, 0],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [2, 1, 0],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [0, 2, 0],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [1, 2, 0],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [2, 2, 0],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [0, 1, 1],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [1, 1, 1],
|
||||
state: 3
|
||||
},
|
||||
{
|
||||
pos: [2, 1, 1],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [0, 2, 1],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [1, 2, 1],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [2, 2, 1],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [0, 1, 2],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [1, 1, 2],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [2, 1, 2],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [0, 2, 2],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [1, 2, 2],
|
||||
state: 2
|
||||
},
|
||||
{
|
||||
pos: [2, 2, 2],
|
||||
state: 2
|
||||
}
|
||||
],
|
||||
palette: [
|
||||
{
|
||||
Name: "minecraft:polished_andesite"
|
||||
},
|
||||
{
|
||||
Properties: {
|
||||
waterlogged: "false",
|
||||
facing: "south"
|
||||
},
|
||||
Name: "computercraft:turtle_normal"
|
||||
},
|
||||
{
|
||||
Name: "minecraft:air"
|
||||
},
|
||||
{
|
||||
Properties: {
|
||||
level: "3"
|
||||
},
|
||||
Name: "minecraft:cauldron"
|
||||
}
|
||||
],
|
||||
DataVersion: 2230
|
||||
}
|
Loading…
Reference in New Issue
Block a user