Skip to content

Commit

Permalink
make waypoint is visible when player is holding waypoint or wrench
Browse files Browse the repository at this point in the history
  • Loading branch information
yor42 committed Nov 25, 2024
1 parent 7e5236b commit e6b9edc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/lulan/shincolle/block/BlockLightLiquid.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
Expand Down Expand Up @@ -64,6 +65,13 @@ public String getTranslationKey() {
return String.format("tile.%s%s", Tags.MOD_ID + ":", getUnwrappedUnlocalizedName(super.getTranslationKey()));
}

@Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) {
Material mat = world.getBlockState(pos.offset(face)).getMaterial();

return !mat.isLiquid();
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityLightBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ModelWayPoint extends ModelBase {
public final ModelRenderer waypoint;

public ModelWayPoint(){
this.textureWidth = 16;
this.textureWidth = 32;
this.textureHeight = 16;
this.waypoint = new ModelRenderer(this, 0, 0);
this.waypoint.setRotationPoint(0.0F, 0.0F, 0.0F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;

import static com.lulan.shincolle.utility.MathHelper.RadianToDegrees;

public class RenderWaypoint extends TileEntitySpecialRenderer<TileEntityWaypoint> {

private final ModelWayPoint model_waypoint;

private static final ResourceLocation TEXTURE = new ResourceLocation(Tags.TEXTURES_BLOCKS + "blockwaypoint.png");
private static final ResourceLocation TEXTURE = new ResourceLocation(Tags.TEXTURES_BLOCKS + "blockwaypointrender.png");

public RenderWaypoint(){
this.model_waypoint = new ModelWayPoint();
Expand All @@ -37,22 +39,21 @@ public void render(TileEntityWaypoint te, double x, double y, double z, float pa
return;
}


BlockPos pos = te.getPos();
double distX = pos.getX() + 0.5D - player.posX;
double distY = pos.getY() - 0.75D - player.posY;
double distY = pos.getY() - 0.5D - player.posY;
double distZ = pos.getZ() + 0.5D - player.posZ;
float f1 = MathHelper.sqrt(distX * distX + distZ * distZ);
float pitch = (float) (Math.atan2(f1, distY));
float yaw = (float) (Math.atan2(distX, distZ));

Minecraft.getMinecraft().renderEngine.bindTexture(TEXTURE);
GlStateManager.pushMatrix();
GlStateManager.depthMask(ConfigHandler.vortexDepth);
GlStateManager.depthMask(true);
GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
GlStateManager.rotate(yaw * 57.2957F, 0F, 1F, 0F);
GlStateManager.rotate(pitch * 57.2957F, 1F, 0F, 0F);
this.model_waypoint.render(0.03125F);
GlStateManager.rotate(RadianToDegrees(yaw), 0F, 1F, 0F);
GlStateManager.rotate(RadianToDegrees(pitch)+90, 1F, 0F, 0F);
this.model_waypoint.render(0.05F);
GlStateManager.depthMask(true);
GlStateManager.popMatrix();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,7 @@ public void update() {
this.tick++;

//client side
if (this.world.isRemote) {
//valid tile
this.world.getBlockState(this.pos).getBlock();
this.invalidate();
return;

//show client particle: player hold waypoint or target wrench
}//end client side
//server side
else {
if (!this.world.isRemote) {
//get owner entity
if ((this.tick & 15) == 0 && this.owner == null && this.playerUID > 0) {
this.owner = EntityHelper.getEntityPlayerByUID(this.playerUID);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/lulan/shincolle/utility/MathHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lulan.shincolle.utility;

public class MathHelper {
public static float DegreesToRadian(float degrees){
return degrees * (float)Math.PI / 180;
}

public static float RadianToDegrees(float radian){
return radian * 180 / (float)Math.PI;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6b9edc

Please sign in to comment.