From ed2176516aab7e10dbaf07ec8699140d7ac200ca Mon Sep 17 00:00:00 2001 From: MeowMC Date: Mon, 4 Apr 2022 13:23:39 -0400 Subject: [PATCH] fix the anims and stuff --- build.gradle | 16 +- gradle.properties | 10 +- .../portalgun/client/PortalgunClient.java | 2 +- .../renderer/PortalOverlayRenderer.java | 4 +- .../portalgun/entities/CustomPortal.java | 147 +++++++++++++++++- .../portalgun/entities/PortalOverlay.java | 2 +- .../portalgun/mixin/MinecraftClientMixin.java | 5 +- .../portalgun/mixin/PortalAnimMixin.java | 13 ++ src/main/resources/portalgun.accesswidener | 1 - src/main/resources/portalgun.mixins.json | 1 + 10 files changed, 173 insertions(+), 28 deletions(-) create mode 100644 src/main/java/tk/meowmc/portalgun/mixin/PortalAnimMixin.java diff --git a/build.gradle b/build.gradle index 696926f..80dbe2f 100644 --- a/build.gradle +++ b/build.gradle @@ -60,14 +60,14 @@ allprojects { compileOnly 'com.google.code.findbugs:jsr305:3.0.2' - modImplementation 'software.bernie.geckolib:geckolib-fabric-1.18:3.0.27' + modImplementation 'software.bernie.geckolib:geckolib-fabric-1.18:3.0.35' - modImplementation('com.terraformersmc:modmenu:3.0.1') + modImplementation('com.terraformersmc:modmenu:3.1.0') - modApi("me.shedaniel.cloth:cloth-config-fabric:6.1.48") { + modApi("me.shedaniel.cloth:cloth-config-fabric:6.2.57") { exclude(group: "net.fabricmc.fabric-api") } - include("me.shedaniel.cloth:cloth-config-fabric:6.1.48") + include("me.shedaniel.cloth:cloth-config-fabric:6.2.57") // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. @@ -117,13 +117,7 @@ jar { publishing { publications { mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } + from components.java } } diff --git a/gradle.properties b/gradle.properties index faaccbd..1efa550 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx3G +org.gradle.jvmargs=-Xmx1G # Done to allow multiple tasks to run at once. org.gradle.parallel=true # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.18.1 -yarn_mappings=1.18.1+build.22 -loader_version=0.12.2 -fabric_version=0.46.2+1.18 +minecraft_version=1.18.2 +yarn_mappings=1.18.2+build.2 +loader_version=0.13.3 +fabric_version=0.48.0+1.18.2 # Mod Properties mod_version=3.0.1 maven_group=tk.meowmc diff --git a/src/main/java/tk/meowmc/portalgun/client/PortalgunClient.java b/src/main/java/tk/meowmc/portalgun/client/PortalgunClient.java index 03d2088..3dc672d 100644 --- a/src/main/java/tk/meowmc/portalgun/client/PortalgunClient.java +++ b/src/main/java/tk/meowmc/portalgun/client/PortalgunClient.java @@ -74,7 +74,7 @@ public void onInitializeClient() { }); ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (client.options.keyAttack.isPressed() && !client.player.getItemCooldownManager().isCoolingDown(Portalgun.PORTALGUN)) { + if (client.options.attackKey.isPressed() && !client.player.getItemCooldownManager().isCoolingDown(Portalgun.PORTALGUN)) { RemoteCallables.playAnim(); McRemoteProcedureCall.tellServerToInvoke("tk.meowmc.portalgun.misc.RemoteCallables.portal1Place"); } diff --git a/src/main/java/tk/meowmc/portalgun/client/renderer/PortalOverlayRenderer.java b/src/main/java/tk/meowmc/portalgun/client/renderer/PortalOverlayRenderer.java index ba87477..fbccdc7 100644 --- a/src/main/java/tk/meowmc/portalgun/client/renderer/PortalOverlayRenderer.java +++ b/src/main/java/tk/meowmc/portalgun/client/renderer/PortalOverlayRenderer.java @@ -1,6 +1,5 @@ package tk.meowmc.portalgun.client.renderer; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderer; @@ -8,13 +7,12 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3f; -import org.apache.logging.log4j.Level; import tk.meowmc.portalgun.client.PortalgunClient; import tk.meowmc.portalgun.client.renderer.models.PortalOverlayModel; import tk.meowmc.portalgun.entities.PortalOverlay; import static net.minecraft.client.render.OverlayTexture.DEFAULT_UV; -import static tk.meowmc.portalgun.Portalgun.*; +import static tk.meowmc.portalgun.Portalgun.id; public class PortalOverlayRenderer extends EntityRenderer { private final PortalOverlayModel model; diff --git a/src/main/java/tk/meowmc/portalgun/entities/CustomPortal.java b/src/main/java/tk/meowmc/portalgun/entities/CustomPortal.java index 944c092..d893aca 100644 --- a/src/main/java/tk/meowmc/portalgun/entities/CustomPortal.java +++ b/src/main/java/tk/meowmc/portalgun/entities/CustomPortal.java @@ -1,5 +1,7 @@ package tk.meowmc.portalgun.entities; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -8,18 +10,23 @@ import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtList; +import net.minecraft.nbt.NbtString; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Quaternion; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.apache.logging.log4j.Level; import org.jetbrains.annotations.NotNull; import qouteall.imm_ptl.core.McHelper; import qouteall.imm_ptl.core.PehkuiInterface; -import qouteall.imm_ptl.core.portal.Portal; -import qouteall.imm_ptl.core.portal.PortalManipulation; +import qouteall.imm_ptl.core.mc_utils.IPEntityEventListenableEntity; +import qouteall.imm_ptl.core.portal.*; +import qouteall.q_misc_util.Helper; +import qouteall.q_misc_util.dimension.DimId; import qouteall.q_misc_util.my_util.SignalArged; import qouteall.q_misc_util.my_util.SignalBiArged; import tk.meowmc.portalgun.Portalgun; @@ -27,11 +34,12 @@ import java.util.Objects; import java.util.UUID; +import java.util.stream.Collectors; import static tk.meowmc.portalgun.items.PortalGunItem.portal1Exists; import static tk.meowmc.portalgun.items.PortalGunItem.portal2Exists; -public class CustomPortal extends Portal { +public class CustomPortal extends Portal implements PortalLike, IPEntityEventListenableEntity { public static final SignalArged clientPortalTickSignal = new SignalArged(); public static final SignalArged serverPortalTickSignal = new SignalArged(); public static final SignalArged portalCacheUpdateSignal = new SignalArged(); @@ -39,12 +47,140 @@ public class CustomPortal extends Portal { public static final SignalBiArged readPortalDataSignal = new SignalBiArged(); public static final SignalBiArged writePortalDataSignal = new SignalBiArged(); public static final TrackedData outline = DataTracker.registerData(CustomPortal.class, TrackedDataHandlerRegistry.STRING); + public static final PortalAnimation defaultAnimation = null; public static EntityType entityType; + protected PortalAnimation animation = null; + private boolean interactable = true; public CustomPortal(@NotNull EntityType entityType, World world) { super(entityType, world); } + private void initDefaultCullableRange() { + cullableXStart = -(width / 2); + cullableXEnd = (width / 2); + cullableYStart = -(height / 2); + cullableYEnd = (height / 2); + } + + @Override + protected void readCustomDataFromNbt(NbtCompound compoundTag) { + + width = compoundTag.getDouble("width"); + height = compoundTag.getDouble("height"); + axisW = Helper.getVec3d(compoundTag, "axisW").normalize(); + axisH = Helper.getVec3d(compoundTag, "axisH").normalize(); + dimensionTo = DimId.getWorldId(compoundTag, "dimensionTo", world.isClient); + destination = (Helper.getVec3d(compoundTag, "destination")); + specificPlayerId = Helper.getUuid(compoundTag, "specificPlayer"); + if (compoundTag.contains("specialShape")) { + specialShape = new GeometryPortalShape( + compoundTag.getList("specialShape", 6) + ); + + if (specialShape.triangles.isEmpty()) { + specialShape = null; + } else { + if (!specialShape.isValid()) { + Helper.err("Portal shape invalid "); + specialShape = null; + } + } + } else { + specialShape = null; + } + if (compoundTag.contains("teleportable")) { + teleportable = compoundTag.getBoolean("teleportable"); + } + if (compoundTag.contains("cullableXStart")) { + cullableXStart = compoundTag.getDouble("cullableXStart"); + cullableXEnd = compoundTag.getDouble("cullableXEnd"); + cullableYStart = compoundTag.getDouble("cullableYStart"); + cullableYEnd = compoundTag.getDouble("cullableYEnd"); + + cullableXEnd = Math.min(cullableXEnd, width / 2); + cullableXStart = Math.max(cullableXStart, -width / 2); + cullableYEnd = Math.min(cullableYEnd, height / 2); + cullableYStart = Math.max(cullableYStart, -height / 2); + } else { + if (specialShape != null) { + cullableXStart = 0; + cullableXEnd = 0; + cullableYStart = 0; + cullableYEnd = 0; + } else { + initDefaultCullableRange(); + } + } + if (compoundTag.contains("rotationA")) { + rotation = new Quaternion( + compoundTag.getFloat("rotationB"), + compoundTag.getFloat("rotationC"), + compoundTag.getFloat("rotationD"), + compoundTag.getFloat("rotationA") + ); + } else { + rotation = null; + } + + if (compoundTag.contains("interactable")) { + interactable = compoundTag.getBoolean("interactable"); + } + + if (compoundTag.contains("scale")) { + scaling = compoundTag.getDouble("scale"); + } + if (compoundTag.contains("teleportChangesScale")) { + teleportChangesScale = compoundTag.getBoolean("teleportChangesScale"); + } + if (compoundTag.contains("teleportChangesGravity")) { + teleportChangesGravity = compoundTag.getBoolean("teleportChangesGravity"); + } + + if (compoundTag.contains("portalTag")) { + portalTag = compoundTag.getString("portalTag"); + } + + if (compoundTag.contains("fuseView")) { + fuseView = compoundTag.getBoolean("fuseView"); + } + + if (compoundTag.contains("renderingMergable")) { + renderingMergable = compoundTag.getBoolean("renderingMergable"); + } + + if (compoundTag.contains("hasCrossPortalCollision")) { + hasCrossPortalCollision = compoundTag.getBoolean("hasCrossPortalCollision"); + } + + if (compoundTag.contains("commandsOnTeleported")) { + NbtList list = compoundTag.getList("commandsOnTeleported", 8); + commandsOnTeleported = list.stream() + .map(t -> ((NbtString) t).asString()).collect(Collectors.toList()); + } else { + commandsOnTeleported = null; + } + + if (compoundTag.contains("doRenderPlayer")) { + doRenderPlayer = compoundTag.getBoolean("doRenderPlayer"); + } + + readPortalDataSignal.emit(this, compoundTag); + + updateCache(); + } + + @Environment(EnvType.CLIENT) + private void acceptDataSync(Vec3d pos, NbtCompound customData) { + + setPosition(pos); + readCustomDataFromNbt(customData); + } + + @Environment(EnvType.CLIENT) + private void startAnimationClient(PortalState animationStartState) { + } + @Override protected void initDataTracker() { getDataTracker().startTracking(outline, "null"); @@ -71,7 +207,7 @@ public void transformVelocity(@NotNull Entity entity) { McHelper.setWorldVelocity(entity, transformLocalVec(oldVelocity)); } - final double maxVelocity = 0.96; + final double maxVelocity = 0.85; if (oldVelocity.length() > maxVelocity) { // cannot be too fast McHelper.setWorldVelocity( @@ -89,6 +225,9 @@ public void transformVelocity(@NotNull Entity entity) { @Override public void tick() { super.tick(); + if (this.animation != null) + this.animation = null; + if (!world.isClient) { BlockPos portalUpperPos = new BlockPos( diff --git a/src/main/java/tk/meowmc/portalgun/entities/PortalOverlay.java b/src/main/java/tk/meowmc/portalgun/entities/PortalOverlay.java index 64b5d05..749076a 100644 --- a/src/main/java/tk/meowmc/portalgun/entities/PortalOverlay.java +++ b/src/main/java/tk/meowmc/portalgun/entities/PortalOverlay.java @@ -64,7 +64,7 @@ public Packet createSpawnPacket() { PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); buf.writeVarInt( - Registry.ENTITY_TYPE.getRawId(this.getType())) + Registry.ENTITY_TYPE.getRawId(this.getType())) .writeUuid(this.getUuid()) .writeVarInt(this.getId()) .writeDouble(this.getX()) diff --git a/src/main/java/tk/meowmc/portalgun/mixin/MinecraftClientMixin.java b/src/main/java/tk/meowmc/portalgun/mixin/MinecraftClientMixin.java index a1fcc94..f84ab2e 100644 --- a/src/main/java/tk/meowmc/portalgun/mixin/MinecraftClientMixin.java +++ b/src/main/java/tk/meowmc/portalgun/mixin/MinecraftClientMixin.java @@ -12,6 +12,7 @@ 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 tk.meowmc.portalgun.misc.MinecraftClientMethods; import static tk.meowmc.portalgun.Portalgun.PORTALGUN; @@ -54,12 +55,12 @@ private void onHandleBlockBreaking(boolean isKeyPressed, CallbackInfo ci) { at = @At("HEAD"), cancellable = true ) - private void onDoAttack(CallbackInfo ci) { + private void onDoAttack(CallbackInfoReturnable cir) { if (attackCooldown <= 0 && MinecraftClientMethods.isPointingToPortal() && !player.isHolding(PORTALGUN)) MinecraftClientMethods.myAttackBlock(); else if (!player.isHolding(PORTALGUN)) MinecraftClientMethods.doAttack(); - ci.cancel(); + cir.cancel(); } } diff --git a/src/main/java/tk/meowmc/portalgun/mixin/PortalAnimMixin.java b/src/main/java/tk/meowmc/portalgun/mixin/PortalAnimMixin.java new file mode 100644 index 0000000..dd3cf66 --- /dev/null +++ b/src/main/java/tk/meowmc/portalgun/mixin/PortalAnimMixin.java @@ -0,0 +1,13 @@ +package tk.meowmc.portalgun.mixin; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import qouteall.imm_ptl.core.portal.PortalAnimation; + +@Mixin(PortalAnimation.class) +public abstract class PortalAnimMixin { + @Final + @Shadow + public int durationTicks = 0; +} diff --git a/src/main/resources/portalgun.accesswidener b/src/main/resources/portalgun.accesswidener index 17b1ffa..bca10c2 100644 --- a/src/main/resources/portalgun.accesswidener +++ b/src/main/resources/portalgun.accesswidener @@ -8,4 +8,3 @@ extendable class net/minecraft/entity/Entity accessible field net/minecraft/entity/Entity yaw F accessible field net/minecraft/entity/Entity pitch F extendable method net/minecraft/entity/Entity getLerpedPos (F)Lnet/minecraft/util/math/Vec3d; - diff --git a/src/main/resources/portalgun.mixins.json b/src/main/resources/portalgun.mixins.json index fbb9279..b6aa8ab 100644 --- a/src/main/resources/portalgun.mixins.json +++ b/src/main/resources/portalgun.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "EntityMixin", + "PortalAnimMixin", "ServerTeleportationManagerMixin" ], "client": [