class ModItem -> interface ExtendedItem
This commit is contained in:
parent
505445681f
commit
32026bf812
4 changed files with 11 additions and 15 deletions
|
@ -1,24 +1,19 @@
|
||||||
package org.dimdev.dimdoors.item;
|
package org.dimdev.dimdoors.api.item;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.TypedActionResult;
|
import net.minecraft.util.TypedActionResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ModItem extends Item {
|
public interface ExtendedItem {
|
||||||
|
|
||||||
public ModItem(Settings settings) {
|
|
||||||
super(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add javadocs
|
// TODO: add javadocs
|
||||||
// true -> send packet to server
|
// true -> send packet to server
|
||||||
// false -> don't send packet to server
|
// false -> don't send packet to server
|
||||||
// boolean value currently does nothing server-side
|
// boolean value currently does nothing server-side
|
||||||
public TypedActionResult<Boolean> onAttackBlock(World world, PlayerEntity player, Hand hand, BlockPos pos, Direction direction) {
|
default TypedActionResult<Boolean> onAttackBlock(World world, PlayerEntity player, Hand hand, BlockPos pos, Direction direction) {
|
||||||
return TypedActionResult.pass(false);
|
return TypedActionResult.pass(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.dimdev.dimdoors.api.item.ExtendedItem;
|
||||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||||
import org.dimdev.dimdoors.network.ServerPacketHandler;
|
import org.dimdev.dimdoors.network.ServerPacketHandler;
|
||||||
import org.dimdev.dimdoors.rift.targets.IdMarker;
|
import org.dimdev.dimdoors.rift.targets.IdMarker;
|
||||||
|
@ -31,7 +32,7 @@ import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
import static net.fabricmc.api.EnvType.CLIENT;
|
import static net.fabricmc.api.EnvType.CLIENT;
|
||||||
|
|
||||||
public class RiftConfigurationToolItem extends ModItem {
|
public class RiftConfigurationToolItem extends Item implements ExtendedItem {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
public static final String ID = "rift_configuration_tool";
|
public static final String ID = "rift_configuration_tool";
|
||||||
|
|
|
@ -9,7 +9,7 @@ import net.minecraft.util.TypedActionResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.dimdev.dimdoors.item.ModItem;
|
import org.dimdev.dimdoors.api.item.ExtendedItem;
|
||||||
import org.dimdev.dimdoors.network.client.ClientPacketHandler;
|
import org.dimdev.dimdoors.network.client.ClientPacketHandler;
|
||||||
import org.dimdev.dimdoors.network.packet.c2s.HitBlockWithItemC2SPacket;
|
import org.dimdev.dimdoors.network.packet.c2s.HitBlockWithItemC2SPacket;
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ public class AttackBlockCallbackListener implements AttackBlockCallback {
|
||||||
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||||
if (!world.isClient) return ActionResult.PASS;
|
if (!world.isClient) return ActionResult.PASS;
|
||||||
Item item = player.getStackInHand(hand).getItem();
|
Item item = player.getStackInHand(hand).getItem();
|
||||||
if (!(item instanceof ModItem)) {
|
if (!(item instanceof ExtendedItem)) {
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
TypedActionResult<Boolean> result = ((ModItem) item).onAttackBlock(world, player, hand, pos, direction);
|
TypedActionResult<Boolean> result = ((ExtendedItem) item).onAttackBlock(world, player, hand, pos, direction);
|
||||||
if (result.getValue()) {
|
if (result.getValue()) {
|
||||||
if (!ClientPacketHandler.sendPacket(new HitBlockWithItemC2SPacket(hand, pos, direction))) {
|
if (!ClientPacketHandler.sendPacket(new HitBlockWithItemC2SPacket(hand, pos, direction))) {
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.util.registry.RegistryKey;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dimdev.dimdoors.item.ModItem;
|
import org.dimdev.dimdoors.api.item.ExtendedItem;
|
||||||
import org.dimdev.dimdoors.network.packet.c2s.HitBlockWithItemC2SPacket;
|
import org.dimdev.dimdoors.network.packet.c2s.HitBlockWithItemC2SPacket;
|
||||||
import org.dimdev.dimdoors.network.packet.c2s.NetworkHandlerInitializedC2SPacket;
|
import org.dimdev.dimdoors.network.packet.c2s.NetworkHandlerInitializedC2SPacket;
|
||||||
import org.dimdev.dimdoors.network.packet.s2c.PlayerInventorySlotUpdateS2CPacket;
|
import org.dimdev.dimdoors.network.packet.s2c.PlayerInventorySlotUpdateS2CPacket;
|
||||||
|
@ -136,8 +136,8 @@ public class ServerPacketHandler implements ServerPacketListener {
|
||||||
public void onAttackBlock(HitBlockWithItemC2SPacket packet) {
|
public void onAttackBlock(HitBlockWithItemC2SPacket packet) {
|
||||||
getServer().execute(() -> {
|
getServer().execute(() -> {
|
||||||
Item item = getPlayer().getStackInHand(packet.getHand()).getItem();
|
Item item = getPlayer().getStackInHand(packet.getHand()).getItem();
|
||||||
if (item instanceof ModItem) {
|
if (item instanceof ExtendedItem) {
|
||||||
((ModItem) item).onAttackBlock(getPlayer().world, getPlayer(), packet.getHand(), packet.getPos(), packet.getDirection());
|
((ExtendedItem) item).onAttackBlock(getPlayer().world, getPlayer(), packet.getHand(), packet.getPos(), packet.getDirection());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue