mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-05 21:33:54 +00:00
Change tools to also be peripherals
This commit is contained in:
parent
359c8d6652
commit
00c27c2f3b
@ -63,6 +63,7 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
|
||||
private @Nullable Item craftingItem;
|
||||
private @Nullable Float damageMultiplier = null;
|
||||
private @Nullable TagKey<Block> breakable;
|
||||
private String peripheralType = "";
|
||||
private boolean allowEnchantments = false;
|
||||
private TurtleToolDurability consumeDurability = TurtleToolDurability.NEVER;
|
||||
|
||||
@ -96,6 +97,11 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToolBuilder peripheralType(String peripheralType) {
|
||||
this.peripheralType = peripheralType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount of damage a swing of this tool will do. This is multiplied by {@link Attributes#ATTACK_DAMAGE} to
|
||||
* get the final damage.
|
||||
@ -162,6 +168,7 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
|
||||
if (consumeDurability != TurtleToolDurability.NEVER) {
|
||||
s.addProperty("consumeDurability", consumeDurability.getSerializedName());
|
||||
}
|
||||
s.addProperty("peripheralType", peripheralType);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ class TurtleUpgradeProvider extends TurtleUpgradeDataProvider {
|
||||
simpleWithCustomItem(id("wireless_modem_normal"), TurtleSerialisers.WIRELESS_MODEM_NORMAL.get(), Items.WIRELESS_MODEM_NORMAL.get()).add(addUpgrade);
|
||||
simpleWithCustomItem(id("wireless_modem_advanced"), TurtleSerialisers.WIRELESS_MODEM_ADVANCED.get(), Items.WIRELESS_MODEM_ADVANCED.get()).add(addUpgrade);
|
||||
|
||||
tool(vanilla("diamond_axe"), net.minecraft.world.item.Items.DIAMOND_AXE).damageMultiplier(6.0f).add(addUpgrade);
|
||||
tool(vanilla("diamond_pickaxe"), net.minecraft.world.item.Items.DIAMOND_PICKAXE).add(addUpgrade);
|
||||
tool(vanilla("diamond_hoe"), net.minecraft.world.item.Items.DIAMOND_HOE).breakable(Blocks.TURTLE_HOE_BREAKABLE).add(addUpgrade);
|
||||
tool(vanilla("diamond_shovel"), net.minecraft.world.item.Items.DIAMOND_SHOVEL).breakable(Blocks.TURTLE_SHOVEL_BREAKABLE).add(addUpgrade);
|
||||
tool(vanilla("diamond_sword"), net.minecraft.world.item.Items.DIAMOND_SWORD).breakable(Blocks.TURTLE_SWORD_BREAKABLE).damageMultiplier(9.0f).add(addUpgrade);
|
||||
tool(vanilla("diamond_axe"), net.minecraft.world.item.Items.DIAMOND_AXE).peripheralType("axe").damageMultiplier(6.0f).add(addUpgrade);
|
||||
tool(vanilla("diamond_pickaxe"), net.minecraft.world.item.Items.DIAMOND_PICKAXE).peripheralType("pickaxe").add(addUpgrade);
|
||||
tool(vanilla("diamond_hoe"), net.minecraft.world.item.Items.DIAMOND_HOE).breakable(Blocks.TURTLE_HOE_BREAKABLE).peripheralType("hoe").add(addUpgrade);
|
||||
tool(vanilla("diamond_shovel"), net.minecraft.world.item.Items.DIAMOND_SHOVEL).breakable(Blocks.TURTLE_SHOVEL_BREAKABLE).peripheralType("shovel").add(addUpgrade);
|
||||
tool(vanilla("diamond_sword"), net.minecraft.world.item.Items.DIAMOND_SWORD).breakable(Blocks.TURTLE_SWORD_BREAKABLE).peripheralType("sword").damageMultiplier(9.0f).add(addUpgrade);
|
||||
}
|
||||
|
||||
private static ResourceLocation id(String id) {
|
||||
|
@ -0,0 +1,70 @@
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.api.lua.MethodResult;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.shared.turtle.core.InteractDirection;
|
||||
import dan200.computercraft.shared.turtle.core.TurtleToolCommand;
|
||||
|
||||
public class ToolPeripheral implements IPeripheral{
|
||||
private final ITurtleAccess turtle;
|
||||
private final TurtleSide side;
|
||||
private final String type;
|
||||
|
||||
public ToolPeripheral(ITurtleAccess turtle, TurtleSide side, String type) {
|
||||
this.turtle = turtle;
|
||||
this.side = side;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
public final MethodResult digDown() throws LuaException {
|
||||
return turtle.executeCommand(TurtleToolCommand.dig(InteractDirection.DOWN, side));
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
public final MethodResult digUp() throws LuaException {
|
||||
return turtle.executeCommand(TurtleToolCommand.dig(InteractDirection.UP, side));
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
public final MethodResult dig() throws LuaException {
|
||||
return turtle.executeCommand(TurtleToolCommand.dig(InteractDirection.FORWARD, side));
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
public final MethodResult attackDown() throws LuaException {
|
||||
return turtle.executeCommand(TurtleToolCommand.attack(InteractDirection.DOWN, side));
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
public final MethodResult attackUp() throws LuaException {
|
||||
return turtle.executeCommand(TurtleToolCommand.attack(InteractDirection.UP, side));
|
||||
}
|
||||
|
||||
@LuaFunction
|
||||
public final MethodResult attack() throws LuaException {
|
||||
return turtle.executeCommand(TurtleToolCommand.attack(InteractDirection.FORWARD, side));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable IPeripheral other) {
|
||||
return other instanceof ToolPeripheral && type.equals(other.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTarget() {
|
||||
return turtle;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftTags;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||
import dan200.computercraft.shared.turtle.TurtleUtil;
|
||||
@ -55,17 +56,19 @@ public class TurtleTool extends AbstractTurtleUpgrade {
|
||||
final boolean allowEnchantments;
|
||||
final TurtleToolDurability consumeDurability;
|
||||
final @Nullable TagKey<Block> breakable;
|
||||
final String peripheralType;
|
||||
|
||||
public TurtleTool(
|
||||
ResourceLocation id, String adjective, Item craftItem, ItemStack toolItem, float damageMulitiplier,
|
||||
boolean allowEnchantments, TurtleToolDurability consumeDurability, @Nullable TagKey<Block> breakable
|
||||
boolean allowEnchantments, TurtleToolDurability consumeDurability, @Nullable TagKey<Block> breakable, String peripheralType
|
||||
) {
|
||||
super(id, TurtleUpgradeType.TOOL, adjective, new ItemStack(craftItem));
|
||||
super(id, TurtleUpgradeType.BOTH, adjective, new ItemStack(craftItem));
|
||||
item = toolItem;
|
||||
this.damageMulitiplier = damageMulitiplier;
|
||||
this.allowEnchantments = allowEnchantments;
|
||||
this.consumeDurability = consumeDurability;
|
||||
this.breakable = breakable;
|
||||
this.peripheralType = peripheralType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,6 +107,11 @@ public class TurtleTool extends AbstractTurtleUpgrade {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPeripheral createPeripheral(ITurtleAccess turtle, TurtleSide side) {
|
||||
return new ToolPeripheral(turtle, side, peripheralType);
|
||||
}
|
||||
|
||||
private ItemStack getToolStack(ITurtleAccess turtle, TurtleSide side) {
|
||||
return getUpgradeItem(turtle.getUpgradeNBTData(side)).copy();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
||||
var craftingItem = GsonHelper.getAsItem(object, "craftingItem", toolItem);
|
||||
var damageMultiplier = GsonHelper.getAsFloat(object, "damageMultiplier", 3.0f);
|
||||
var allowEnchantments = GsonHelper.getAsBoolean(object, "allowEnchantments", false);
|
||||
var peripheralType = GsonHelper.getAsString(object, "peripheralType", "");
|
||||
var consumeDurability = TurtleToolDurability.CODEC.byName(GsonHelper.getAsString(object, "consumeDurability", null), TurtleToolDurability.NEVER);
|
||||
|
||||
TagKey<Block> breakable = null;
|
||||
@ -40,7 +41,7 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
||||
breakable = TagKey.create(Registries.BLOCK, tag);
|
||||
}
|
||||
|
||||
return new TurtleTool(id, adjective, craftingItem, new ItemStack(toolItem), damageMultiplier, allowEnchantments, consumeDurability, breakable);
|
||||
return new TurtleTool(id, adjective, craftingItem, new ItemStack(toolItem), damageMultiplier, allowEnchantments, consumeDurability, breakable, peripheralType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,9 +55,10 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
||||
var damageMultiplier = buffer.readFloat();
|
||||
var allowsEnchantments = buffer.readBoolean();
|
||||
var consumesDurability = buffer.readEnum(TurtleToolDurability.class);
|
||||
var peripheralType = buffer.readUtf();
|
||||
|
||||
var breakable = buffer.readNullable(b -> TagKey.create(Registries.BLOCK, b.readResourceLocation()));
|
||||
return new TurtleTool(id, adjective, craftingItem, toolItem, damageMultiplier, allowsEnchantments, consumesDurability, breakable);
|
||||
return new TurtleTool(id, adjective, craftingItem, toolItem, damageMultiplier, allowsEnchantments, consumesDurability, breakable, peripheralType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,6 +69,7 @@ public final class TurtleToolSerialiser implements TurtleUpgradeSerialiser<Turtl
|
||||
buffer.writeFloat(upgrade.damageMulitiplier);
|
||||
buffer.writeBoolean(upgrade.allowEnchantments);
|
||||
buffer.writeEnum(upgrade.consumeDurability);
|
||||
buffer.writeUtf(upgrade.peripheralType);
|
||||
buffer.writeNullable(upgrade.breakable, (b, x) -> b.writeResourceLocation(x.location()));
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
{"type": "computercraft:tool", "damageMultiplier": 6.0, "item": "minecraft:diamond_axe"}
|
||||
{"type": "computercraft:tool", "damageMultiplier": 6.0, "item": "minecraft:diamond_axe", "peripheralType": "axe"}
|
||||
|
@ -1 +1,6 @@
|
||||
{"type": "computercraft:tool", "breakable": "computercraft:turtle_hoe_harvestable", "item": "minecraft:diamond_hoe"}
|
||||
{
|
||||
"type": "computercraft:tool",
|
||||
"breakable": "computercraft:turtle_hoe_harvestable",
|
||||
"item": "minecraft:diamond_hoe",
|
||||
"peripheralType": "hoe"
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
{"type": "computercraft:tool", "item": "minecraft:diamond_pickaxe"}
|
||||
{"type": "computercraft:tool", "item": "minecraft:diamond_pickaxe", "peripheralType": "pickaxe"}
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"type": "computercraft:tool",
|
||||
"breakable": "computercraft:turtle_shovel_harvestable",
|
||||
"item": "minecraft:diamond_shovel"
|
||||
"item": "minecraft:diamond_shovel",
|
||||
"peripheralType": "shovel"
|
||||
}
|
||||
|
@ -2,5 +2,6 @@
|
||||
"type": "computercraft:tool",
|
||||
"breakable": "computercraft:turtle_sword_harvestable",
|
||||
"damageMultiplier": 9.0,
|
||||
"item": "minecraft:diamond_sword"
|
||||
"item": "minecraft:diamond_sword",
|
||||
"peripheralType": "sword"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user