-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with handheld storage not opening
- Loading branch information
kyrptonaught
committed
Dec 30, 2019
1 parent
12507d2
commit a5f2346
Showing
15 changed files
with
221 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/net/kyrptonaught/linkedstorage/block/OpenableBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package net.kyrptonaught.linkedstorage.block; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.api.EnvironmentInterface; | ||
import net.fabricmc.api.EnvironmentInterfaces; | ||
import net.kyrptonaught.linkedstorage.inventory.LinkedContainer; | ||
import net.minecraft.block.ChestBlock; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.block.enums.ChestType; | ||
import net.minecraft.client.block.ChestAnimationProgress; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.Tickable; | ||
import net.minecraft.util.math.Box; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.List; | ||
|
||
@EnvironmentInterfaces({@EnvironmentInterface(value = EnvType.CLIENT, itf = ChestAnimationProgress.class)}) | ||
public class OpenableBlockEntity extends BlockEntity implements ChestAnimationProgress, Tickable { | ||
OpenableBlockEntity(BlockEntityType<?> blockEntityType) { | ||
super(blockEntityType); | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
private static int countViewers(World world, OpenableBlockEntity instance, int x, int y, int z) { | ||
int viewers = 0; | ||
List<PlayerEntity> playersInRange = world.getNonSpectatingEntities(PlayerEntity.class, new Box(x - 5, y - 5, z - 5, x + 6, y + 6, z + 6)); | ||
|
||
for (PlayerEntity player : playersInRange) { | ||
if (player.container instanceof LinkedContainer && instance.isPlayerViewing(player)) | ||
viewers++; | ||
} | ||
return viewers; | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
public boolean isPlayerViewing(PlayerEntity playe) { | ||
return true; | ||
} | ||
|
||
@Override | ||
@Environment(EnvType.CLIENT) | ||
public float getAnimationProgress(float f) { | ||
return MathHelper.lerp(f, lastAnimationAngle, animationAngle); | ||
} | ||
|
||
private float animationAngle; | ||
private float lastAnimationAngle; | ||
|
||
@Override | ||
public void tick() { | ||
if (world != null && world.isClient) { | ||
int viewerCount = countViewers(world, this, pos.getX(), pos.getY(), pos.getZ()); | ||
lastAnimationAngle = animationAngle; | ||
if (viewerCount > 0 && animationAngle == 0.0F) playSound(SoundEvents.BLOCK_CHEST_OPEN); | ||
if (viewerCount == 0 && animationAngle > 0.0F || viewerCount > 0 && animationAngle < 1.0F) { | ||
float float_2 = animationAngle; | ||
if (viewerCount > 0) animationAngle += 0.1F; | ||
else animationAngle -= 0.1F; | ||
animationAngle = MathHelper.clamp(animationAngle, 0, 1); | ||
if (animationAngle < 0.5F && float_2 >= 0.5F) playSound(SoundEvents.BLOCK_CHEST_CLOSE); | ||
} | ||
} | ||
} | ||
|
||
private void playSound(SoundEvent soundEvent) { | ||
double d = (double) this.pos.getX() + 0.5D; | ||
double e = (double) this.pos.getY() + 0.5D; | ||
double f = (double) this.pos.getZ() + 0.5D; | ||
this.world.playSound(null, d, e, f, soundEvent, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/net/kyrptonaught/linkedstorage/client/LinkedChestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.kyrptonaught.linkedstorage.client; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.model.Model; | ||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.render.RenderLayer; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class LinkedChestModel extends Model { | ||
private ModelPart lid; | ||
protected ModelPart base; | ||
private ModelPart latch; | ||
public ModelPart button1, button2, button3; | ||
|
||
public LinkedChestModel() { | ||
super(RenderLayer::getEntityCutout); | ||
this.textureWidth = 64; | ||
this.textureHeight = 64; | ||
this.base = new ModelPart(64, 64, 0, 19); // 818 | ||
this.base.addCuboid(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F); | ||
this.lid = new ModelPart(64, 64, 0, 0); | ||
this.lid.addCuboid(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);//817 | ||
this.lid.pivotY = 9.0F; | ||
this.lid.pivotZ = 1.0F; | ||
this.latch = new ModelPart(64, 64, 0, 0); | ||
this.latch.addCuboid(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F); //819 | ||
this.latch.pivotY = 8.0F; | ||
button1 = new ModelPart(64, 64, 0, 19); | ||
button2 = new ModelPart(64, 64, 0, 19); | ||
button3 = new ModelPart(64, 64, 0, 19); | ||
button1.addCuboid(4, 5, 5, 2, 1, 4, 0); | ||
button2.addCuboid(7, 5, 5, 2, 1, 4, 0); | ||
button3.addCuboid(10, 5, 5, 2, 1, 4, 0); | ||
button1.pivotY = 9f; | ||
button1.pivotZ = 1f; | ||
button2.pivotY = 9f; | ||
button2.pivotZ = 1f; | ||
button3.pivotY = 9f; | ||
button3.pivotZ = 1f; | ||
} | ||
|
||
public void setLidPitch(float pitch) { | ||
pitch = 1.0f - pitch; | ||
button1.pitch = button2.pitch = button3.pitch = latch.pitch = lid.pitch = -((1.0F - pitch * pitch * pitch) * 1.5707964F); | ||
} | ||
|
||
public void render(MatrixStack matrixStack, VertexConsumer vertexConsumer, int i, int j) { | ||
render(matrixStack, vertexConsumer, i, j, 1, 1, 1, 1); | ||
} | ||
|
||
@Override | ||
public void render(MatrixStack stack, VertexConsumer consumer, int i, int j, float r, float g, float b, float f) { | ||
base.render(stack, consumer, i, j); | ||
lid.render(stack, consumer, i, j); | ||
latch.render(stack, consumer, i, j); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/net/kyrptonaught/linkedstorage/inventory/LinkedContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.kyrptonaught.linkedstorage.inventory; | ||
|
||
import net.minecraft.container.GenericContainer; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class LinkedContainer extends GenericContainer { | ||
public BlockPos linkedBlock; | ||
|
||
public LinkedContainer(int syncId, PlayerInventory playerInventory, Inventory inventory, BlockPos linkedBlock) { | ||
super(null, syncId, playerInventory, inventory, 3); | ||
this.linkedBlock = linkedBlock; | ||
} | ||
} |
Oops, something went wrong.