1.0.26
All checks were successful
RelicCraft/pipeline/head This commit looks good

Improve Teleportation Restrictor
This commit is contained in:
TheBrokenRail 2020-04-18 17:27:06 -04:00
parent 60db4606d2
commit bb35c94d12
8 changed files with 86 additions and 3 deletions

View File

@ -1,5 +1,8 @@
# Changelog
**1.0.26**
* Improve Teleportation Restrictor
**1.0.25**
* Improve Teleportation Restrictor

View File

@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
fabric_loader_version = 0.7.10+build.191
# Mod Properties
mod_version = 1.0.25
mod_version = 1.0.26
maven_group = com.thebrokenrail
archives_base_name = reliccraft

View File

@ -19,6 +19,8 @@ public class TeleportationRestrictorBlock extends AbstractDragonEggHolderBlock {
boolean cannotTeleport();
void resetTeleportCooldown();
void setTeleportCooldown(byte cooldown);
}
public TeleportationRestrictorBlock() {

View File

@ -3,6 +3,7 @@ package com.thebrokenrail.reliccraft.client;
import com.thebrokenrail.reliccraft.RelicCraft;
import com.thebrokenrail.reliccraft.client.entity.RelicEntityRenderer;
import com.thebrokenrail.reliccraft.item.RelicItem;
import com.thebrokenrail.reliccraft.packet.UpdateTeleportCooldownS2CPacket;
import com.thebrokenrail.reliccraft.packet.UpdateTimeDilationS2CPacket;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
@ -56,5 +57,6 @@ public class RelicCraftClient implements ClientModInitializer {
EntityRendererRegistry.INSTANCE.register(RelicCraft.RELIC_ENTITY, (entityRenderDispatcher, context) -> new RelicEntityRenderer(entityRenderDispatcher));
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(RelicCraft.NAMESPACE, "update_time_dilation"), UpdateTimeDilationS2CPacket::handle);
ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(RelicCraft.NAMESPACE, "update_teleport_cooldown"), UpdateTeleportCooldownS2CPacket::handle);
}
}

View File

@ -2,7 +2,9 @@ package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -11,22 +13,38 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@SuppressWarnings("unused")
@Mixin(Entity.class)
public class MixinEntity implements TeleportationRestrictorBlock.TeleportingEntity {
public abstract class MixinEntity implements TeleportationRestrictorBlock.TeleportingEntity {
@Shadow
protected boolean inNetherPortal;
@Unique
private int teleportCooldown = 0;
protected byte teleportCooldown = 2;
@Override
public void resetTeleportCooldown() {
teleportCooldown = 4;
}
@Override
public void setTeleportCooldown(byte teleportCooldown) {
this.teleportCooldown = teleportCooldown;
}
@Inject(at = @At("HEAD"), method = "tick")
public void tick(CallbackInfo info) {
updateNetherPortal();
if (teleportCooldown > 0) {
teleportCooldown--;
}
}
@Unique
private void updateNetherPortal() {
if (cannotTeleport()) {
inNetherPortal = false;
}
}
@Inject(at = @At("HEAD"), method = "canUsePortals", cancellable = true)
public void canUsePortals(CallbackInfoReturnable<Boolean> info) {
if (cannotTeleport()) {
@ -38,4 +56,15 @@ public class MixinEntity implements TeleportationRestrictorBlock.TeleportingEnti
public boolean cannotTeleport() {
return teleportCooldown > 0;
}
@Inject(at = @At("HEAD"), method = "toTag")
public void toTag(CompoundTag tag, CallbackInfoReturnable<CompoundTag> info) {
tag.putByte("RelicCraftTeleportCooldown", teleportCooldown);
}
@Inject(at = @At("HEAD"), method = "fromTag")
public void fromTag(CompoundTag tag, CallbackInfo info) {
teleportCooldown = tag.getByte("RelicCraftTeleportCooldown");
updateNetherPortal();
}
}

View File

@ -0,0 +1,16 @@
package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.packet.UpdateTeleportCooldownS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerPlayerEntity.class)
public class MixinServerPlayerEntity extends MixinEntity {
@Inject(at = @At("RETURN"), method = "playerTick")
public void playerTick(CallbackInfo info) {
UpdateTeleportCooldownS2CPacket.send((ServerPlayerEntity) (Object) this, teleportCooldown);
}
}

View File

@ -0,0 +1,30 @@
package com.thebrokenrail.reliccraft.packet;
import com.thebrokenrail.reliccraft.RelicCraft;
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
@SuppressWarnings("unused")
public class UpdateTeleportCooldownS2CPacket {
public static void send(ServerPlayerEntity player, byte cooldown) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeByte(cooldown);
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(new Identifier(RelicCraft.NAMESPACE, "update_teleport_cooldown"), buf));
}
@Environment(EnvType.CLIENT)
public static void handle(PacketContext context, PacketByteBuf buf) {
byte cooldown = buf.readByte();
if (context.getPlayer() != null) {
((TeleportationRestrictorBlock.TeleportingEntity) context.getPlayer()).setTeleportCooldown(cooldown);
}
}
}

View File

@ -19,6 +19,7 @@
"MixinLocateCommand",
"MixinNetherStarItem",
"MixinServerChunkManager",
"MixinServerPlayerEntity",
"MixinServerWorld",
"MixinThrownEnderpearlEntity",
"MixinWorld"