generated from TropheusJ/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
288 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/io/github/fusionflux/portalcubed/content/portal/PortalType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.fusionflux.portalcubed.content.portal; | ||
|
||
public enum PortalType { | ||
PRIMARY, SECONDARY; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/github/fusionflux/portalcubed/content/portal/gun/PortalGunItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.fusionflux.portalcubed.content.portal.gun; | ||
|
||
import io.github.fusionflux.portalcubed.content.portal.PortalType; | ||
import io.github.fusionflux.portalcubed.framework.item.DirectClickItem; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
|
||
import org.quiltmc.qsl.base.api.util.TriState; | ||
|
||
public class PortalGunItem extends Item implements DirectClickItem { | ||
public PortalGunItem(Properties settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public TriState onAttack(Level level, Player player, ItemStack stack) { | ||
shoot(level, player, stack, InteractionHand.MAIN_HAND, PortalType.PRIMARY); | ||
return TriState.TRUE; | ||
} | ||
|
||
@Override | ||
public TriState onUse(Level level, Player player, ItemStack stack, InteractionHand hand) { | ||
shoot(level, player, stack, hand, PortalType.SECONDARY); | ||
return TriState.TRUE; | ||
} | ||
|
||
public void shoot(Level level, Player player, ItemStack stack, InteractionHand hand, PortalType type) { | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/io/github/fusionflux/portalcubed/content/portal/gun/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@MethodsReturnNonnullByDefault | ||
package io.github.fusionflux.portalcubed.content.portal.gun; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/github/fusionflux/portalcubed/framework/item/DirectClickItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.fusionflux.portalcubed.framework.item; | ||
|
||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
|
||
import org.quiltmc.qsl.base.api.util.TriState; | ||
|
||
/** | ||
* An item that directly listens for use and attacking. | ||
*/ | ||
public interface DirectClickItem { | ||
/** | ||
* @return DEFAULT to fall back to vanilla, FALSE to cancel, TRUE to continue to server / cancel | ||
*/ | ||
TriState onAttack(Level level, Player player, ItemStack stack); | ||
|
||
/** | ||
* @return DEFAULT to fall back to vanilla, FALSE to cancel, TRUE to continue to server / cancel | ||
*/ | ||
TriState onUse(Level level, Player player, ItemStack stack, InteractionHand hand); | ||
} |
6 changes: 3 additions & 3 deletions
6
...x/portalcubed/registration/Registrar.java → ...bed/framework/registration/Registrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...portalcubed/registration/RenderTypes.java → ...d/framework/registration/RenderTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...ubed/registration/block/BlockBuilder.java → ...work/registration/block/BlockBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
.../registration/block/BlockBuilderImpl.java → .../registration/block/BlockBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ubed/registration/block/BlockFactory.java → ...work/registration/block/BlockFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...cubed/registration/block/BlockHelper.java → ...ework/registration/block/BlockHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
...registration/block/BlockItemProvider.java → ...registration/block/BlockItemProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lcubed/registration/item/ItemBuilder.java → ...mework/registration/item/ItemBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ed/registration/item/ItemBuilderImpl.java → ...rk/registration/item/ItemBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lcubed/registration/item/ItemFactory.java → ...mework/registration/item/ItemFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...alcubed/registration/item/ItemHelper.java → ...amework/registration/item/ItemHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/io/github/fusionflux/portalcubed/mixin/MinecraftMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.github.fusionflux.portalcubed.mixin; | ||
|
||
import io.github.fusionflux.portalcubed.framework.item.DirectClickItem; | ||
import io.github.fusionflux.portalcubed.packet.PortalCubedPackets; | ||
import io.github.fusionflux.portalcubed.packet.serverbound.DirectClickItemPacket; | ||
import net.minecraft.client.Minecraft; | ||
|
||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.quiltmc.qsl.base.api.util.TriState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MinecraftMixin { | ||
@Shadow | ||
@Nullable | ||
public ClientLevel level; | ||
|
||
@Shadow | ||
@Nullable | ||
public LocalPlayer player; | ||
|
||
@Inject( | ||
method = "startAttack", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/phys/HitResult;getType()Lnet/minecraft/world/phys/HitResult$Type;" | ||
), | ||
locals = LocalCapture.CAPTURE_FAILHARD, | ||
cancellable = true | ||
) | ||
private void onAttack(CallbackInfoReturnable<Boolean> cir, ItemStack stack) { | ||
if (stack.getItem() instanceof DirectClickItem direct) { | ||
TriState result = direct.onAttack(level, player, stack); | ||
if (result != TriState.DEFAULT) { | ||
if (result == TriState.TRUE) { | ||
PortalCubedPackets.sendToServer(new DirectClickItemPacket(true, InteractionHand.MAIN_HAND)); | ||
} | ||
cir.setReturnValue(result.toBoolean()); | ||
} | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "startUseItem", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/phys/HitResult;getType()Lnet/minecraft/world/phys/HitResult$Type;" | ||
), | ||
locals = LocalCapture.CAPTURE_FAILHARD, | ||
cancellable = true | ||
) | ||
private void onUse(CallbackInfo ci, InteractionHand[] hands, int var2, int var3, InteractionHand hand, ItemStack stack) { | ||
if (stack.getItem() instanceof DirectClickItem direct) { | ||
TriState result = direct.onUse(level, player, stack, hand); | ||
if (result != TriState.DEFAULT) { | ||
if (result == TriState.TRUE) { | ||
PortalCubedPackets.sendToServer(new DirectClickItemPacket(false, hand)); | ||
} | ||
ci.cancel(); | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/github/fusionflux/portalcubed/packet/ClientboundPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.fusionflux.portalcubed.packet; | ||
|
||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.minecraft.client.player.LocalPlayer; | ||
|
||
import org.quiltmc.loader.api.minecraft.ClientOnly; | ||
|
||
public interface ClientboundPacket extends FabricPacket { | ||
@ClientOnly | ||
void handle(LocalPlayer player, PacketSender responder); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/io/github/fusionflux/portalcubed/packet/PortalCubedPackets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.fusionflux.portalcubed.packet; | ||
|
||
import io.github.fusionflux.portalcubed.PortalCubed; | ||
import io.github.fusionflux.portalcubed.packet.serverbound.DirectClickItemPacket; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketType; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
import org.quiltmc.loader.api.minecraft.ClientOnly; | ||
import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader; | ||
|
||
import java.util.function.Function; | ||
|
||
public class PortalCubedPackets { | ||
public static final PacketType<DirectClickItemPacket> DIRECT_CLICK_ITEM = serverbound("direct_click_item", DirectClickItemPacket::new); | ||
|
||
public static void init() { | ||
} | ||
|
||
private static <T extends ClientboundPacket> PacketType<T> clientbound(String name, Function<FriendlyByteBuf, T> factory) { | ||
PacketType<T> type = PacketType.create(PortalCubed.id(name), factory); | ||
if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT) { | ||
registerClientReceiver(type); | ||
} | ||
return type; | ||
} | ||
|
||
private static <T extends ServerboundPacket> PacketType<T> serverbound(String name, Function<FriendlyByteBuf, T> factory) { | ||
PacketType<T> type = PacketType.create(PortalCubed.id(name), factory); | ||
ServerPlayNetworking.registerGlobalReceiver(type, ServerboundPacket::handle); | ||
return type; | ||
} | ||
|
||
private static <T extends ClientboundPacket> void registerClientReceiver(PacketType<T> type) { | ||
ClientPlayNetworking.registerGlobalReceiver(type, ClientboundPacket::handle); | ||
} | ||
|
||
public static <T extends FabricPacket> void sendToClient(ServerPlayer player, T packet) { | ||
ServerPlayNetworking.send(player, packet); | ||
} | ||
|
||
@ClientOnly | ||
public static <T extends FabricPacket> void sendToServer(T packet) { | ||
ClientPlayNetworking.send(packet); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/io/github/fusionflux/portalcubed/packet/ServerboundPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.github.fusionflux.portalcubed.packet; | ||
|
||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
public interface ServerboundPacket extends FabricPacket { | ||
void handle(ServerPlayer player, PacketSender responder); | ||
} |
Oops, something went wrong.