Black hole improvements
This commit is contained in:
parent
f9fb9124b7
commit
c101edaee4
@ -18,6 +18,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||
@ -58,6 +59,10 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
setChanged();
|
||||
gravitation_strength = mass.divide(NORMAL_MASS, MatteryCapability.ROUND_RULES).doubleValue();
|
||||
|
||||
if (gravitation_strength > 1) {
|
||||
gravitation_strength = Math.min(20, Math.log(gravitation_strength));
|
||||
}
|
||||
|
||||
if (level != null && !level.isClientSide && !suppress_updates)
|
||||
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
|
||||
|
||||
@ -179,7 +184,7 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
tile.setDeltaMovement(living, center, distance);
|
||||
}
|
||||
|
||||
if (distance < tile.gravitation_strength * 2) {
|
||||
if (distance < tile.gravitation_strength + 1) {
|
||||
living.hurt(Registry.DAMAGE_EVENT_HORIZON, (float) (tile.gravitation_strength / distance));
|
||||
}
|
||||
}
|
||||
@ -188,7 +193,7 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
final double distance = item.position().distanceTo(center);
|
||||
tile.setDeltaMovement(item, center, distance);
|
||||
|
||||
if (distance < tile.gravitation_strength * 2) {
|
||||
if (distance < tile.gravitation_strength + 1) {
|
||||
if (item.hurt(Registry.DAMAGE_EVENT_HORIZON, (float) (tile.gravitation_strength / distance)) && item.isRemoved()) {
|
||||
var mass = MatterRegistry.getMatterValue(item.getItem());
|
||||
|
||||
|
@ -132,6 +132,8 @@ public class BlockEntityMatterDecomposer extends BlockEntityMatteryWorker implem
|
||||
if (!stack.isEmpty()) {
|
||||
ItemStack copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
|
||||
if (MatterRegistry.canDecompose(copy)) {
|
||||
BigDecimal matter_value = MatterRegistry.getMatterValue(copy);
|
||||
|
||||
if (!matter_value.equals(BigDecimal.ZERO) && matter.canReceiveAll(matter_value)) {
|
||||
@ -139,6 +141,7 @@ public class BlockEntityMatterDecomposer extends BlockEntityMatteryWorker implem
|
||||
return new MachineJob(copy, matter_value.doubleValue() * 12_500d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ package ru.dbotthepony.mc.otm.client.render;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityBlackHole;
|
||||
|
||||
import static org.lwjgl.opengl.GL33.*;
|
||||
@ -14,6 +16,7 @@ public class BlackHoleRenderer implements BlockEntityRenderer<BlockEntityBlackHo
|
||||
public void render(BlockEntityBlackHole blockEntityBlackHole, float v, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int i1) {
|
||||
RenderHelper.setDrawColor(RGBAColor.BLACK);
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.depthFunc(GL_LESS);
|
||||
RenderSystem.depthMask(true);
|
||||
|
||||
@ -21,9 +24,9 @@ public class BlackHoleRenderer implements BlockEntityRenderer<BlockEntityBlackHo
|
||||
RenderSystem.disableCull();
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(0.5, -0.25, blockEntityBlackHole.getGravitationStrength() * 0.5);
|
||||
poseStack.translate(0.5, -blockEntityBlackHole.getGravitationStrength() / 2, 0.5);
|
||||
|
||||
RenderHelper.colorSphere(poseStack, 1f);
|
||||
RenderHelper.colorSphere(poseStack, (float) blockEntityBlackHole.getGravitationStrength());
|
||||
|
||||
poseStack.popPose();
|
||||
|
||||
@ -31,6 +34,21 @@ public class BlackHoleRenderer implements BlockEntityRenderer<BlockEntityBlackHo
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderOffScreen(BlockEntityBlackHole p_112306_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(BlockEntityBlackHole p_173568_, Vec3 p_173569_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewDistance() {
|
||||
return 512;
|
||||
}
|
||||
|
||||
public BlackHoleRenderer(BlockEntityRendererProvider.Context context) {
|
||||
|
||||
}
|
||||
|
@ -94,9 +94,8 @@ public class RenderHelper {
|
||||
}
|
||||
|
||||
public static void colorSphere(Matrix4f matrix, float radius) {
|
||||
final int fragments = Math.round(radius * 16);
|
||||
final int fragments = 32;
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
|
||||
@ -123,9 +122,6 @@ public class RenderHelper {
|
||||
final float y_pre = (float) (Math.sin(tilt_pre) + 0.5) * radius;
|
||||
final float y_post = (float) (Math.sin(tilt_post) + 0.5) * radius;
|
||||
|
||||
//final float y_pre = (float) ((double) top_frag / (double) fragments) * 8;
|
||||
//final float y_post = (float) ((double) (top_frag + 1) / (double) fragments) * 8;
|
||||
|
||||
builder.vertex(matrix, x_pre * (float) Math.cos(tilt_post), y_post, z_pre * (float) Math.cos(tilt_post))
|
||||
.color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a())
|
||||
.endVertex();
|
||||
|
@ -43,18 +43,52 @@ public class MatterRegistry {
|
||||
}
|
||||
|
||||
public static boolean hasMatterValue(ItemStack item) {
|
||||
if (item.getCapability(MatteryCapability.DRIVE).isPresent() || item.getCapability(MatteryCapability.MATTER).isPresent())
|
||||
return true;
|
||||
|
||||
return hasMatterValue(item.getItem());
|
||||
}
|
||||
|
||||
public static boolean canDecompose(ItemStack stack) {
|
||||
if (stack.getCapability(MatteryCapability.DRIVE).isPresent() && stack.getCapability(MatteryCapability.DRIVE).resolve().get().getStoredCount() > 0)
|
||||
return false;
|
||||
|
||||
public static BigDecimal getMatterValue(ItemStack stack) {
|
||||
Item item = stack.getItem();
|
||||
if (stack.getCapability(MatteryCapability.MATTER).isPresent() && stack.getCapability(MatteryCapability.MATTER).resolve().get().getStoredMatter().compareTo(BigDecimal.ZERO) > 0)
|
||||
return false;
|
||||
|
||||
if (item.isDamageable(stack)) {
|
||||
return getMatterValue(item).multiply(BigDecimal.ONE.subtract(new BigDecimal(item.getDamage(stack)).divide(new BigDecimal(item.getMaxDamage(stack)), ROUND_RULES)));
|
||||
return hasMatterValue(stack.getItem());
|
||||
}
|
||||
|
||||
return getMatterValue(item);
|
||||
private static BigDecimal getMatterValue(ItemStack stack, int level) {
|
||||
if (level >= 100) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
Item item = stack.getItem();
|
||||
var matter = getMatterValue(item);
|
||||
|
||||
if (item.isDamageable(stack)) {
|
||||
matter = matter.multiply(BigDecimal.ONE.subtract(new BigDecimal(item.getDamage(stack)).divide(new BigDecimal(item.getMaxDamage(stack)), ROUND_RULES)));
|
||||
}
|
||||
|
||||
var cap1 = stack.getCapability(MatteryCapability.DRIVE).resolve();
|
||||
var cap2 = stack.getCapability(MatteryCapability.MATTER).resolve();
|
||||
|
||||
if (cap1.isPresent()) {
|
||||
for (var stored : cap1.get().getItems()) {
|
||||
matter = matter.add(getMatterValue(stored.stack(), level + 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (cap2.isPresent()) {
|
||||
matter = matter.add(cap2.get().getStoredMatter());
|
||||
}
|
||||
|
||||
return matter;
|
||||
}
|
||||
|
||||
public static BigDecimal getMatterValue(ItemStack stack) {
|
||||
return getMatterValue(stack, 0);
|
||||
}
|
||||
|
||||
public static void registerInitialItems() {
|
||||
|
Loading…
Reference in New Issue
Block a user