Skip to content

Commit

Permalink
fix the anims and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
froyo4u committed Apr 4, 2022
1 parent c247736 commit ed21765
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 28 deletions.
16 changes: 5 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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;
import net.minecraft.client.render.entity.EntityRendererFactory;
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<PortalOverlay> {
private final PortalOverlayModel model;
Expand Down
147 changes: 143 additions & 4 deletions src/main/java/tk/meowmc/portalgun/entities/CustomPortal.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,43 +10,177 @@
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;
import tk.meowmc.portalgun.items.PortalGunItem;

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<CustomPortal> clientPortalTickSignal = new SignalArged();
public static final SignalArged<CustomPortal> serverPortalTickSignal = new SignalArged();
public static final SignalArged<CustomPortal> portalCacheUpdateSignal = new SignalArged();
public static final SignalArged<CustomPortal> portalDisposeSignal = new SignalArged();
public static final SignalBiArged<CustomPortal, NbtCompound> readPortalDataSignal = new SignalBiArged();
public static final SignalBiArged<CustomPortal, NbtCompound> writePortalDataSignal = new SignalBiArged();
public static final TrackedData<String> outline = DataTracker.registerData(CustomPortal.class, TrackedDataHandlerRegistry.STRING);
public static final PortalAnimation defaultAnimation = null;
public static EntityType<CustomPortal> 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");
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean> cir) {
if (attackCooldown <= 0 && MinecraftClientMethods.isPointingToPortal() && !player.isHolding(PORTALGUN))
MinecraftClientMethods.myAttackBlock();
else if (!player.isHolding(PORTALGUN))
MinecraftClientMethods.doAttack();
ci.cancel();
cir.cancel();
}

}
13 changes: 13 additions & 0 deletions src/main/java/tk/meowmc/portalgun/mixin/PortalAnimMixin.java
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 0 additions & 1 deletion src/main/resources/portalgun.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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;

1 change: 1 addition & 0 deletions src/main/resources/portalgun.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"EntityMixin",
"PortalAnimMixin",
"ServerTeleportationManagerMixin"
],
"client": [
Expand Down

0 comments on commit ed21765

Please sign in to comment.