Skip to content

Commit

Permalink
Merge pull request #130 from Chainmail-Studios/shnup
Browse files Browse the repository at this point in the history
Shnup
  • Loading branch information
Shnupbups authored Jul 1, 2020
2 parents eca2029 + 39b5e7a commit 41e27cf
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ api_version = 0.14.1+build.372-1.16

# Mod
mod_name = astromine
mod_version = 1.0.20
mod_version = 1.0.21
mod_group = com.github.chainmailstudios
version_meta = fabric-1.16.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;

import com.github.chainmailstudios.astromine.AstromineCommon;
import com.github.chainmailstudios.astromine.common.block.HolographicBridgeProjectorBlock;
import com.github.chainmailstudios.astromine.common.block.entity.HolographicBridgeProjectorBlockEntity;
import spinnery.client.render.layer.SpinneryLayers;
import spinnery.widget.api.Color;
Expand All @@ -27,6 +29,11 @@ public HolographicBridgeBlockEntityRenderer(BlockEntityRenderDispatcher dispatch
public void render(HolographicBridgeProjectorBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider provider, int light, int overlay) {
BlockState b = entity.getWorld().getBlockState(entity.getPos());

if(!(b.getBlock() instanceof HolographicBridgeProjectorBlock)) {
AstromineCommon.LOGGER.warn("Holo Bridge Projector BE exists in spot where it shouldn't! "+entity.getPos());
return;
}

if (entity.hasChild()) {
Vec3i pA = entity.getPos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
Expand All @@ -19,6 +21,8 @@
import nerdhub.cardinal.components.api.component.ComponentProvider;

public class HolographicBridgeInvisibleBlock extends Block {
public static final Material MATERIAL = new Material.Builder(MaterialColor.CLEAR).build();

public HolographicBridgeInvisibleBlock(AbstractBlock.Settings settings) {
super(settings);
}
Expand All @@ -41,7 +45,8 @@ public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, Bl

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos position, ShapeContext context) {
return getCollisionShape(state, world, position, context);
return VoxelShapes.empty();
//return getCollisionShape(state, world, position, context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos position, Play
HolographicBridgeProjectorBlockEntity entity = (HolographicBridgeProjectorBlockEntity) world.getBlockEntity(position);

if (entity != null) {
entity.color = Color.of(0x7e000000 >> 2 | dye.getColor().getSignColor());
entity.color = Color.of(0x7e000000 >> 2 | dye.getColor().getFireworkColor());

if (!player.isCreative()) {
stack.decrement(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ protected AstromineBlockWithEntity(AbstractBlock.Settings settings) {
public boolean onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data) {
super.onSyncedBlockEvent(state, world, pos, type, data);
BlockEntity blockEntity = world.getBlockEntity(pos);
return blockEntity == null ? false : blockEntity.onSyncedBlockEvent(type, data);
return blockEntity != null && blockEntity.onSyncedBlockEvent(type, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3i;

import com.github.chainmailstudios.astromine.common.block.HolographicBridgeInvisibleBlock;
import com.github.chainmailstudios.astromine.common.component.world.WorldBridgeComponent;
import com.github.chainmailstudios.astromine.common.utilities.LineUtilities;
import com.github.chainmailstudios.astromine.registry.AstromineBlockEntityTypes;
Expand Down Expand Up @@ -104,9 +108,9 @@ public void tick() {
}
}

public void buildBridge() {
public boolean buildBridge() {
if (this.child == null || this.world == null) {
return;
return false;
}

BlockPos bCP = this.getChild().getPos();
Expand All @@ -125,12 +129,12 @@ public void buildBridge() {
int distance = (int) Math.sqrt(this.getPos().getSquaredDistance(this.getChild().getPos()));

if (distance == 0) {
return;
return false;
}

this.segments = (ArrayList<Vector3f>) LineUtilities.getBezierSegments(new Vector3f(bOP.getX(), bOP.getY() + 1, bOP.getZ()),
new Vector3f(nCP.getX(), nCP.getY() + 1, nCP.getZ()),
new Vector3f((bOP.getX() + nCP.getX()) / 2f, (bOP.getY() + nCP.getY() + 2) / 2f, bCP.getZ()),
new Vector3f(nCP.getX(), nCP.getY() + 0.99f, nCP.getZ()),
new Vector3f((bOP.getX() + nCP.getX()) / 2f, (bOP.getY() + nCP.getY() + 2f) / 2f, bCP.getZ()),
distance * 16
);

Expand All @@ -139,18 +143,24 @@ public void buildBridge() {
for (Vector3f v : this.segments) {
BlockPos nP = new BlockPos(v.getX(), v.getY(), v.getZ());

if ((nP.getX() != bCP.getX() && nP.getX() != bOP.getX()) || (nP.getZ() != bCP.getZ() && nP.getZ() != bOP.getZ())) {
this.world.setBlockState(nP, AstromineBlocks.HOLOGRAPHIC_BRIDGE_INVISIBLE_BLOCK.getDefaultState());

this.members.add(nP);
}
Material mat = this.world.getBlockState(nP).getMaterial();
if(mat.isReplaceable() || mat.equals(HolographicBridgeInvisibleBlock.MATERIAL)) {
if ((nP.getX() != bCP.getX() && nP.getX() != bOP.getX()) || (nP.getZ() != bCP.getZ() && nP.getZ() != bOP.getZ())) {
this.world.setBlockState(nP, AstromineBlocks.HOLOGRAPHIC_BRIDGE_INVISIBLE_BLOCK.getDefaultState());
this.members.add(nP);
}

ComponentProvider componentProvider = ComponentProvider.fromWorld(world);
ComponentProvider componentProvider = ComponentProvider.fromWorld(world);

WorldBridgeComponent bridgeComponent = componentProvider.getComponent(AstromineComponentTypes.WORLD_BRIDGE_COMPONENT);
WorldBridgeComponent bridgeComponent = componentProvider.getComponent(AstromineComponentTypes.WORLD_BRIDGE_COMPONENT);

bridgeComponent.add(nP, new Vec3i((v.getX() - (int) v.getX()) * 16f, (v.getY() - (int) v.getY()) * 16f, (v.getZ() - (int) v.getZ()) * 16f));
bridgeComponent.add(nP, new Vec3i((v.getX() - (int) v.getX()) * 16f, (v.getY() - (int) v.getY()) * 16f, (v.getZ() - (int) v.getZ()) * 16f));
} else {
destroyBridge();
return false;
}
}
return true;
}

public HolographicBridgeProjectorBlockEntity getChild() {
Expand Down Expand Up @@ -208,7 +218,7 @@ public CompoundTag toTag(CompoundTag tag) {
}

if (this.childPosition != null) {
tag.putLong("parent_position", this.childPosition.asLong());
tag.putLong("child_position", this.childPosition.asLong());
}
if (this.parentPosition != null) {
tag.putLong("parent_position", this.parentPosition.asLong());
Expand Down Expand Up @@ -252,9 +262,13 @@ public void destroyBridge() {

WorldBridgeComponent bridgeComponent = componentProvider.getComponent(AstromineComponentTypes.WORLD_BRIDGE_COMPONENT);

bridgeComponent.remove((BlockPos) vec);
BlockPos pos = (BlockPos) vec;

this.world.setBlockState((BlockPos) vec, Blocks.AIR.getDefaultState());
bridgeComponent.remove(pos);

if(this.world.getBlockState(pos).getBlock() instanceof HolographicBridgeInvisibleBlock) {
this.world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ private VoxelShape getShape(Set<Vec3i> vecs) {
if (!d && vec.getZ() < 0) d = true;

shape = VoxelShapes.union(shape, Block.createCuboidShape(
Math.abs(vec.getX()) - 1,
Math.abs(vec.getX()),
Math.abs(vec.getY()) - 1,
Math.abs(vec.getZ()) - 1,
b ? 16 : Math.abs(vec.getX()),
Math.abs(vec.getZ()),
b ? 16 : Math.abs(vec.getX()+1),
Math.abs(vec.getY()) + 1,
a ? 16 : Math.abs(vec.getZ())));
a ? 16 : Math.abs(vec.getZ()+1)
));
}

if (c || d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public ActionResult interactAt(PlayerEntity player, Vec3d hitPos, Hand hand) {
if (stack.getItem() == Items.FLINT_AND_STEEL) {
this.getDataTracker().set(IS_GO, true);
return ActionResult.SUCCESS;
} else if (stack.getItem() == Items.STICK) {
this.kill();
}

if (!stack.isEmpty()) return ActionResult.CONSUME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ public ActionResult useOnBlock(ItemUsageContext context) {
parent.buildBridge();

if (world.isClient) {
CACHE.put(world, null);
context.getPlayer().sendMessage(new TranslatableText("text.astromine.message.holographic_connection_successful", toShortString(parent.getPos()), toShortString(entity.getPos())).formatted(Formatting.GREEN), true);
world.playSound(context.getPlayer(), context.getBlockPos(), AstromineSounds.HOLOGRAPHIC_CONNECTOR_CLICK, SoundCategory.PLAYERS, 0.5f, 0.33f);
}

CACHE.put(world, null);
}
} else {
if (world.isClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class GameRendererMixin {

@Inject(at = @At("RETURN"), method = "getFov(Lnet/minecraft/client/render/Camera;FZ)D", cancellable = true)
void onGetFov(Camera camera, float tickDelta, boolean changingFov, CallbackInfoReturnable<Double> callbackInformationReturnable) {
double gameFov = callbackInformationReturnable.getReturnValueD();
final double gameFov = callbackInformationReturnable.getReturnValueD();
double newFov = gameFov;

if (MinecraftClient.getInstance().player == null) return;

Expand All @@ -39,10 +40,10 @@ void onGetFov(Camera camera, float tickDelta, boolean changingFov, CallbackInfoR
if (heldItem instanceof Weapon) {
double weaponFov = ((Weapon) heldItem).getZoom();

if (gameFov > weaponFov) {
gameFov = MathHelper.lerp(tickDelta / 10, lastFov, weaponFov);
if (newFov > weaponFov) {
newFov = MathHelper.lerp(tickDelta / 10, lastFov, weaponFov);
} else {
gameFov = weaponFov;
newFov = weaponFov;
}

isTransitioning = true;
Expand All @@ -51,17 +52,18 @@ void onGetFov(Camera camera, float tickDelta, boolean changingFov, CallbackInfoR
Item heldItem = MinecraftClient.getInstance().player.getMainHandStack().getItem();

if (heldItem instanceof Weapon) {
if (isTransitioning && lastFov < gameFov) {
gameFov = MathHelper.lerp(tickDelta / 10, lastFov, gameFov);
if (isTransitioning && lastFov < newFov) {
newFov = MathHelper.lerp(tickDelta / 10, lastFov, gameFov);
} else {
isTransitioning = false;
}
}
}

callbackInformationReturnable.setReturnValue(gameFov);

lastFov = gameFov;
if(newFov != gameFov) {
callbackInformationReturnable.setReturnValue(newFov);
lastFov = newFov;
}
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;bobViewWhenHurt(Lnet/minecraft/client/util/math/MatrixStack;F)V"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class AstromineBlocks {
public static final Block HOLOGRAPHIC_BRIDGE_PROJECTOR = register("holographic_bridge_projector", new HolographicBridgeProjectorBlock(FabricBlockSettings.of(Material.METAL).requiresTool().breakByTool(FabricToolTags.PICKAXES, 4).strength(4, 16).sounds(BlockSoundGroup.METAL)), AstromineItems.getBasicSettings());
public static final Block HOLOGRAPHIC_BRIDGE_INVISIBLE_BLOCK = register("holographic_bridge_invisible", new HolographicBridgeInvisibleBlock(FabricBlockSettings.of(Material.AIR).dropsNothing().strength(-1.0F, 3600000.8F).nonOpaque().lightLevel(15).allowsSpawning((a, b, c, d) -> false)));
public static final Block HOLOGRAPHIC_BRIDGE_INVISIBLE_BLOCK = register("holographic_bridge_invisible", new HolographicBridgeInvisibleBlock(FabricBlockSettings.of(HolographicBridgeInvisibleBlock.MATERIAL).dropsNothing().strength(-1.0F, 3600000.8F).nonOpaque().lightLevel(15).allowsSpawning((a, b, c, d) -> false)));

public static final Block VENT = register("vent", new VentBlock(FabricBlockSettings.of(Material.METAL).requiresTool().breakByTool(FabricToolTags.PICKAXES, 4).strength(4, 16).sounds(BlockSoundGroup.METAL)), AstromineItems.getBasicSettings());

Expand Down

0 comments on commit 41e27cf

Please sign in to comment.