Add deaths in pocket stat
This commit is contained in:
parent
fa9e5502a4
commit
d71bd136a1
12 changed files with 165 additions and 42 deletions
|
@ -24,6 +24,10 @@ import net.minecraft.text.LiteralText;
|
|||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ScreenGenerator {
|
||||
public static Screen create(Screen parent, Object config, Runnable saveAction) {
|
||||
Class<?> configClass = config.getClass();
|
||||
|
@ -34,6 +38,7 @@ public class ScreenGenerator {
|
|||
ConfigEntryBuilder entryBuilder = configBuilder.entryBuilder();
|
||||
configBuilder.setTitle(new TranslatableText(configClass.getAnnotation(Title.class).value()));
|
||||
configBuilder.setSavingRunnable(saveAction);
|
||||
configBuilder.setParentScreen(parent);
|
||||
GetStrategy strategy = configClass.getAnnotation(GetStrategy.class);
|
||||
for (Field field : configClass.getDeclaredFields()) {
|
||||
if (!field.isAnnotationPresent(Category.class)
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.dimdev.dimdoors.block.ModBlocks;
|
|||
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
||||
import org.dimdev.dimdoors.command.ModCommands;
|
||||
import org.dimdev.dimdoors.entity.ModEntityTypes;
|
||||
import org.dimdev.dimdoors.entity.stat.ModStats;
|
||||
import org.dimdev.dimdoors.fluid.ModFluids;
|
||||
import org.dimdev.dimdoors.item.ModItems;
|
||||
import org.dimdev.dimdoors.pockets.SchematicHandler;
|
||||
|
@ -65,6 +66,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
|||
ModBiomes.init();
|
||||
ModDimensions.init();
|
||||
ModEntityTypes.init();
|
||||
ModStats.init();
|
||||
ModBlockEntityTypes.init();
|
||||
ModCommands.init();
|
||||
ModFluids.init();
|
||||
|
|
|
@ -13,7 +13,6 @@ public enum DefaultTransformation implements Transformer {
|
|||
DIMENSIONAL_PORTAL {
|
||||
@Override
|
||||
public void transform(MatrixStack matrices) {
|
||||
// TODO
|
||||
matrices.translate(0, 0, 0.5F);
|
||||
}
|
||||
},
|
||||
|
@ -44,12 +43,6 @@ public enum DefaultTransformation implements Transformer {
|
|||
matrices.multiply(Vector3f.NEGATIVE_Y.getDegreesQuaternion(90.0F));
|
||||
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();
|
||||
|
|
|
@ -34,9 +34,7 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
|
|||
|
||||
@Override
|
||||
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);
|
||||
} else {
|
||||
long timeLeft = RiftBlockEntity.showRiftCoreUntil - System.currentTimeMillis();
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
package org.dimdev.dimdoors.client;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import com.flowpowered.math.vector.VectorNi;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import org.dimdev.dimdoors.mixin.DirectionAccessor;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.block.enums.DoorHinge;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
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 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 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);
|
||||
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");
|
||||
|
@ -36,37 +27,69 @@ public class MyRenderLayer extends RenderLayer {
|
|||
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()
|
||||
.cull(DISABLE_CULLING)
|
||||
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
|
||||
.texture(NO_TEXTURE)
|
||||
.transparency(new Transparency("crack_transparency", () -> {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
}, () -> {
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
}))
|
||||
.build(false));
|
||||
public static RenderLayer CRACK = RenderLayer.of("crack",
|
||||
VertexFormats.POSITION_COLOR,
|
||||
GL11.GL_TRIANGLES,
|
||||
256,
|
||||
MultiPhaseParameters.builder()
|
||||
.cull(DISABLE_CULLING)
|
||||
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
|
||||
.texture(NO_TEXTURE)
|
||||
.transparency(new Transparency("crack_transparency",
|
||||
() -> {
|
||||
RenderSystem.enableBlend();
|
||||
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()
|
||||
.cull(DISABLE_CULLING)
|
||||
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
|
||||
.texture(new Texture(DetachedRiftBlockEntityRenderer.TESSERACT_PATH, false, false))
|
||||
.alpha(Alpha.HALF_ALPHA)
|
||||
.build(false));
|
||||
public static RenderLayer TESSERACT = RenderLayer.of("tesseract",
|
||||
VertexFormats.POSITION_COLOR_TEXTURE,
|
||||
GL11.GL_QUADS,
|
||||
256,
|
||||
MultiPhaseParameters.builder()
|
||||
.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) {
|
||||
RenderPhase.Transparency transparency;
|
||||
RenderPhase.Texture texture;
|
||||
if (layer <= 1) {
|
||||
transparency = TRANSLUCENT_TRANSPARENCY;
|
||||
texture = new RenderPhase.Texture(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false, false);
|
||||
texture = new RenderPhase.Texture(EndPortalBlockEntityRenderer.PORTAL_TEXTURE,
|
||||
false,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
transparency = ADDITIVE_TRANSPARENCY;
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
14
src/main/java/org/dimdev/dimdoors/entity/stat/ModStats.java
Normal file
14
src/main/java/org/dimdev/dimdoors/entity/stat/ModStats.java
Normal 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
|
||||
}
|
||||
}
|
|
@ -1,19 +1,30 @@
|
|||
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.ModDimensions;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@Mixin(value = PlayerEntity.class, priority = 900)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -23,4 +34,20 @@ public abstract class PlayerEntityMixin extends LivingEntity {
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
16
src/main/java/org/dimdev/dimdoors/mixin/StatsAccessor.java
Normal file
16
src/main/java/org/dimdev/dimdoors/mixin/StatsAccessor.java
Normal 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();
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ import net.minecraft.util.registry.SimpleRegistry;
|
|||
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.
|
||||
*/
|
||||
public abstract class VirtualTarget implements Target {
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package org.dimdev.dimdoors.util;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -37,6 +40,19 @@ public final class TeleportUtil {
|
|||
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) {
|
||||
double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale();
|
||||
teleport(
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
"ListTagAccessor",
|
||||
"PlayerEntityMixin",
|
||||
"RedstoneWireBlockAccessor",
|
||||
"RegistryKeyMixin"
|
||||
"RegistryKeyMixin",
|
||||
"ServerPlayerEntityMixin",
|
||||
"StatsAccessor"
|
||||
],
|
||||
"client": [
|
||||
"client.GlStateManagerAccessor",
|
||||
|
|
Loading…
Reference in a new issue