Add deaths in pocket stat

This commit is contained in:
SD 2021-01-11 15:37:47 +05:30
parent fa9e5502a4
commit d71bd136a1
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
12 changed files with 165 additions and 42 deletions

View file

@ -24,6 +24,10 @@ import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class ScreenGenerator { public class ScreenGenerator {
public static Screen create(Screen parent, Object config, Runnable saveAction) { public static Screen create(Screen parent, Object config, Runnable saveAction) {
Class<?> configClass = config.getClass(); Class<?> configClass = config.getClass();
@ -34,6 +38,7 @@ public class ScreenGenerator {
ConfigEntryBuilder entryBuilder = configBuilder.entryBuilder(); ConfigEntryBuilder entryBuilder = configBuilder.entryBuilder();
configBuilder.setTitle(new TranslatableText(configClass.getAnnotation(Title.class).value())); configBuilder.setTitle(new TranslatableText(configClass.getAnnotation(Title.class).value()));
configBuilder.setSavingRunnable(saveAction); configBuilder.setSavingRunnable(saveAction);
configBuilder.setParentScreen(parent);
GetStrategy strategy = configClass.getAnnotation(GetStrategy.class); GetStrategy strategy = configClass.getAnnotation(GetStrategy.class);
for (Field field : configClass.getDeclaredFields()) { for (Field field : configClass.getDeclaredFields()) {
if (!field.isAnnotationPresent(Category.class) if (!field.isAnnotationPresent(Category.class)

View file

@ -6,6 +6,7 @@ import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes; import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.command.ModCommands; import org.dimdev.dimdoors.command.ModCommands;
import org.dimdev.dimdoors.entity.ModEntityTypes; import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.entity.stat.ModStats;
import org.dimdev.dimdoors.fluid.ModFluids; import org.dimdev.dimdoors.fluid.ModFluids;
import org.dimdev.dimdoors.item.ModItems; import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.pockets.SchematicHandler; import org.dimdev.dimdoors.pockets.SchematicHandler;
@ -65,6 +66,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
ModBiomes.init(); ModBiomes.init();
ModDimensions.init(); ModDimensions.init();
ModEntityTypes.init(); ModEntityTypes.init();
ModStats.init();
ModBlockEntityTypes.init(); ModBlockEntityTypes.init();
ModCommands.init(); ModCommands.init();
ModFluids.init(); ModFluids.init();

View file

@ -13,7 +13,6 @@ public enum DefaultTransformation implements Transformer {
DIMENSIONAL_PORTAL { DIMENSIONAL_PORTAL {
@Override @Override
public void transform(MatrixStack matrices) { public void transform(MatrixStack matrices) {
// TODO
matrices.translate(0, 0, 0.5F); matrices.translate(0, 0, 0.5F);
} }
}, },
@ -44,12 +43,6 @@ public enum DefaultTransformation implements Transformer {
matrices.multiply(Vector3f.NEGATIVE_Y.getDegreesQuaternion(90.0F)); matrices.multiply(Vector3f.NEGATIVE_Y.getDegreesQuaternion(90.0F));
matrices.translate(0, 0, -0.19F); matrices.translate(0, 0, -0.19F);
} }
},
TRAPDOOR {
@Override
public void transform(MatrixStack matrices) {
matrices.multiply(Vector3f.NEGATIVE_Z.getDegreesQuaternion(90.0F));
}
}; };
private static final DefaultTransformation[] VALUES = values(); private static final DefaultTransformation[] VALUES = values();

View file

@ -34,9 +34,7 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
@Override @Override
public void render(DetachedRiftBlockEntity rift, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcs, int breakProgress, int alpha) { public void render(DetachedRiftBlockEntity rift, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcs, int breakProgress, int alpha) {
Matrix4f model = matrices.peek().getModel(); if (ModConfig.INSTANCE.getGraphicsConfig().showRiftCore) {
if (ModConfig.INSTANCE.getGraphicsConfig().showRiftCore) {
this.renderTesseract(vcs.getBuffer(MyRenderLayer.TESSERACT), rift, matrices, tickDelta); this.renderTesseract(vcs.getBuffer(MyRenderLayer.TESSERACT), rift, matrices, tickDelta);
} else { } else {
long timeLeft = RiftBlockEntity.showRiftCoreUntil - System.currentTimeMillis(); long timeLeft = RiftBlockEntity.showRiftCoreUntil - System.currentTimeMillis();

View file

@ -1,22 +1,16 @@
package org.dimdev.dimdoors.client; package org.dimdev.dimdoors.client;
import java.util.Arrays;
import java.util.Random; import java.util.Random;
import com.flowpowered.math.vector.VectorNi; import com.flowpowered.math.vector.VectorNi;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import org.dimdev.dimdoors.mixin.DirectionAccessor;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import net.minecraft.block.enums.DoorHinge;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase; import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.block.entity.EndPortalBlockEntityRenderer; import net.minecraft.client.render.block.entity.EndPortalBlockEntityRenderer;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_DST_COLOR; import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_DST_COLOR;
@ -24,9 +18,6 @@ import static org.lwjgl.opengl.GL11.GL_ZERO;
public class MyRenderLayer extends RenderLayer { public class MyRenderLayer extends RenderLayer {
public static final Identifier WARP_PATH = new Identifier("dimdoors:textures/other/warp.png"); public static final Identifier WARP_PATH = new Identifier("dimdoors:textures/other/warp.png");
public static final BooleanProperty OPEN_PROPERTY = BooleanProperty.of("open");
public static final EnumProperty<DoorHinge> HINGE_PROPERTY = EnumProperty.of("hinge", DoorHinge.class);
public static final DirectionProperty FACING_PROPERTY = DirectionProperty.of("facing", Arrays.asList(DirectionAccessor.getHorizontal()));
public static final VectorNi COLORLESS = new VectorNi(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255); public static final VectorNi COLORLESS = new VectorNi(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255);
private static final Identifier KEY_PATH = new Identifier("dimdoors:textures/other/keyhole.png"); private static final Identifier KEY_PATH = new Identifier("dimdoors:textures/other/keyhole.png");
private static final Identifier KEYHOLE_LIGHT = new Identifier("dimdoors:textures/other/keyhole_light.png"); private static final Identifier KEYHOLE_LIGHT = new Identifier("dimdoors:textures/other/keyhole_light.png");
@ -36,37 +27,69 @@ public class MyRenderLayer extends RenderLayer {
super(string, vertexFormat, i, j, bl, bl2, runnable, runnable2); super(string, vertexFormat, i, j, bl, bl2, runnable, runnable2);
} }
public static RenderLayer CRACK = RenderLayer.of("crack", VertexFormats.POSITION_COLOR, GL11.GL_TRIANGLES, 256, MultiPhaseParameters.builder() public static RenderLayer CRACK = RenderLayer.of("crack",
.cull(DISABLE_CULLING) VertexFormats.POSITION_COLOR,
.lightmap(RenderPhase.DISABLE_LIGHTMAP) GL11.GL_TRIANGLES,
.texture(NO_TEXTURE) 256,
.transparency(new Transparency("crack_transparency", () -> { MultiPhaseParameters.builder()
RenderSystem.enableBlend(); .cull(DISABLE_CULLING)
RenderSystem.blendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); .lightmap(RenderPhase.DISABLE_LIGHTMAP)
}, () -> { .texture(NO_TEXTURE)
RenderSystem.disableBlend(); .transparency(new Transparency("crack_transparency",
RenderSystem.defaultBlendFunc(); () -> {
})) RenderSystem.enableBlend();
.build(false)); RenderSystem.blendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
},
() -> {
RenderSystem.disableBlend();
RenderSystem.defaultBlendFunc();
})
)
.build(false)
);
public static RenderLayer TESSERACT = RenderLayer.of("tesseract", VertexFormats.POSITION_COLOR_TEXTURE, GL11.GL_QUADS, 256, MultiPhaseParameters.builder() public static RenderLayer TESSERACT = RenderLayer.of("tesseract",
.cull(DISABLE_CULLING) VertexFormats.POSITION_COLOR_TEXTURE,
.lightmap(RenderPhase.DISABLE_LIGHTMAP) GL11.GL_QUADS,
.texture(new Texture(DetachedRiftBlockEntityRenderer.TESSERACT_PATH, false, false)) 256,
.alpha(Alpha.HALF_ALPHA) MultiPhaseParameters.builder()
.build(false)); .cull(DISABLE_CULLING)
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
.texture(new Texture(DetachedRiftBlockEntityRenderer.TESSERACT_PATH,
false,
false)
)
.alpha(Alpha.HALF_ALPHA)
.build(false)
);
public static RenderLayer getPortal(int layer) { public static RenderLayer getPortal(int layer) {
RenderPhase.Transparency transparency; RenderPhase.Transparency transparency;
RenderPhase.Texture texture; RenderPhase.Texture texture;
if (layer <= 1) { if (layer <= 1) {
transparency = TRANSLUCENT_TRANSPARENCY; transparency = TRANSLUCENT_TRANSPARENCY;
texture = new RenderPhase.Texture(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false, false); texture = new RenderPhase.Texture(EndPortalBlockEntityRenderer.PORTAL_TEXTURE,
false,
false
);
} else { } else {
transparency = ADDITIVE_TRANSPARENCY; transparency = ADDITIVE_TRANSPARENCY;
texture = new RenderPhase.Texture(WARP_PATH, false, false); texture = new RenderPhase.Texture(WARP_PATH, false, false);
} }
return of("dimensional_portal", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(transparency).texture(texture).texturing(new RenderPhase.PortalTexturing(layer)).fog(BLACK_FOG).build(false)); return of(
"dimensional_portal",
VertexFormats.POSITION_COLOR,
GL11.GL_QUADS,
256,
false,
true,
RenderLayer.MultiPhaseParameters.builder()
.transparency(transparency)
.texture(texture)
.texturing(new RenderPhase.PortalTexturing(layer))
.fog(BLACK_FOG)
.build(false)
);
} }
} }

View file

@ -0,0 +1,14 @@
package org.dimdev.dimdoors.entity.stat;
import org.dimdev.dimdoors.mixin.StatsAccessor;
import net.minecraft.stat.StatFormatter;
import net.minecraft.util.Identifier;
public class ModStats {
public static final Identifier DEATHS_IN_POCKETS = StatsAccessor.invokeRegister("dimdoors:deaths_in_pocket", StatFormatter.DEFAULT);
public static void init() {
// just loads the class
}
}

View file

@ -1,19 +1,30 @@
package org.dimdev.dimdoors.mixin; package org.dimdev.dimdoors.mixin;
import org.dimdev.dimdoors.entity.stat.ModStats;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModBiomes; import org.dimdev.dimdoors.world.ModBiomes;
import org.dimdev.dimdoors.world.ModDimensions;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; 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.CallbackInfoReturnable;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.world.World; import net.minecraft.world.World;
@Mixin(value = PlayerEntity.class, priority = 900) @Mixin(value = PlayerEntity.class, priority = 900)
public abstract class PlayerEntityMixin extends LivingEntity { public abstract class PlayerEntityMixin extends LivingEntity {
private PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) { @Shadow
public abstract void incrementStat(Identifier stat);
public PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world); super(entityType, world);
} }
@ -23,4 +34,20 @@ public abstract class PlayerEntityMixin extends LivingEntity {
cir.setReturnValue(false); cir.setReturnValue(false);
} }
} }
@Inject(method = "onDeath", at = @At("HEAD"), cancellable = true)
public void checkDeath(DamageSource source, CallbackInfo ci) {
this.doOnDeathStuff(source, ci);
}
@Unique
protected void doOnDeathStuff(DamageSource source, CallbackInfo ci) {
if (ModDimensions.isPocketDimension(this.world)) {
this.removed = false;
this.dead = false;
this.setHealth(this.getMaxHealth());
this.incrementStat(ModStats.DEATHS_IN_POCKETS);
ci.cancel();
}
}
} }

View file

@ -0,0 +1,27 @@
package org.dimdev.dimdoors.mixin;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModDimensions;
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;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
@Mixin(value = ServerPlayerEntity.class, priority = 900)
public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
public ServerPlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}
@Inject(method = "onDeath", at = @At("HEAD"), cancellable = true)
public void checkDeath(DamageSource source, CallbackInfo ci) {
this.doOnDeathStuff(source, ci);
TeleportUtil.teleportRandom(this, ModDimensions.LIMBO_DIMENSION, 384);
}
}

View file

@ -0,0 +1,16 @@
package org.dimdev.dimdoors.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.stat.StatFormatter;
import net.minecraft.stat.Stats;
import net.minecraft.util.Identifier;
@Mixin(Stats.class)
public interface StatsAccessor {
@Invoker
static Identifier invokeRegister(String string, StatFormatter statFormatter) {
throw new UnsupportedOperationException();
}
}

View file

@ -16,7 +16,7 @@ import net.minecraft.util.registry.SimpleRegistry;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
/** /**
* A target that is not an actual object in the game such as a block or a tile * A target that is not an actual object in the game such as a block or a block
* entity. Only virtual targets can be saved to NBT. * entity. Only virtual targets can be saved to NBT.
*/ */
public abstract class VirtualTarget implements Target { public abstract class VirtualTarget implements Target {

View file

@ -1,11 +1,14 @@
package org.dimdev.dimdoors.util; package org.dimdev.dimdoors.util;
import java.util.concurrent.ThreadLocalRandom;
import org.dimdev.dimdoors.DimensionalDoorsInitializer; import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget; import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -37,6 +40,19 @@ public final class TeleportUtil {
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw); teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw);
} }
public static void teleportRandom(Entity entity, World world, double y) {
double scale = ThreadLocalRandom.current().nextGaussian() * ThreadLocalRandom.current().nextInt(90);
teleport(
entity,
world,
entity.getPos()
.subtract(0, entity.getY(), 0)
.add(0, y, 0)
.multiply(scale, 1, scale),
entity.yaw
);
}
public static void teleportUntargeted(Entity entity, World world) { public static void teleportUntargeted(Entity entity, World world) {
double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale(); double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale();
teleport( teleport(

View file

@ -13,7 +13,9 @@
"ListTagAccessor", "ListTagAccessor",
"PlayerEntityMixin", "PlayerEntityMixin",
"RedstoneWireBlockAccessor", "RedstoneWireBlockAccessor",
"RegistryKeyMixin" "RegistryKeyMixin",
"ServerPlayerEntityMixin",
"StatsAccessor"
], ],
"client": [ "client": [
"client.GlStateManagerAccessor", "client.GlStateManagerAccessor",