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.item.Item;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ModItem extends Item {
|
||||
|
||||
public ModItem(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
public interface ExtendedItem {
|
||||
|
||||
// TODO: add javadocs
|
||||
// true -> send packet to server
|
||||
// false -> don't send packet to server
|
||||
// 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);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dimdev.dimdoors.api.item.ExtendedItem;
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
import org.dimdev.dimdoors.network.ServerPacketHandler;
|
||||
import org.dimdev.dimdoors.rift.targets.IdMarker;
|
||||
|
@ -31,7 +32,7 @@ import net.fabricmc.api.Environment;
|
|||
|
||||
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();
|
||||
|
||||
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.Direction;
|
||||
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.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) {
|
||||
if (!world.isClient) return ActionResult.PASS;
|
||||
Item item = player.getStackInHand(hand).getItem();
|
||||
if (!(item instanceof ModItem)) {
|
||||
if (!(item instanceof ExtendedItem)) {
|
||||
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 (!ClientPacketHandler.sendPacket(new HitBlockWithItemC2SPacket(hand, pos, direction))) {
|
||||
return ActionResult.FAIL;
|
||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.util.registry.RegistryKey;
|
|||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
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.NetworkHandlerInitializedC2SPacket;
|
||||
import org.dimdev.dimdoors.network.packet.s2c.PlayerInventorySlotUpdateS2CPacket;
|
||||
|
@ -136,8 +136,8 @@ public class ServerPacketHandler implements ServerPacketListener {
|
|||
public void onAttackBlock(HitBlockWithItemC2SPacket packet) {
|
||||
getServer().execute(() -> {
|
||||
Item item = getPlayer().getStackInHand(packet.getHand()).getItem();
|
||||
if (item instanceof ModItem) {
|
||||
((ModItem) item).onAttackBlock(getPlayer().world, getPlayer(), packet.getHand(), packet.getPos(), packet.getDirection());
|
||||
if (item instanceof ExtendedItem) {
|
||||
((ExtendedItem) item).onAttackBlock(getPlayer().world, getPlayer(), packet.getHand(), packet.getPos(), packet.getDirection());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue