Compare commits
24 Commits
d4a19ef7c3
...
1.21.8-1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 49f5c0d139 | |||
| f2321145f5 | |||
| 4edb062b2a | |||
| ab8f821f8b | |||
| b74e5d2c48 | |||
| d63a899fb8 | |||
| daf1311bb3 | |||
| b24431cc55 | |||
| 85c7453e30 | |||
| 335b1596af | |||
| 7f9c20ab7d | |||
| 3000585586 | |||
| 07f940caf1 | |||
| 8163dabf2d | |||
| 999e5fb752 | |||
| b8cdeb343a | |||
| 31ea4af347 | |||
| 04f58b17da | |||
| e6c74ecded | |||
| 0e058e284e | |||
| 3e5da14735 | |||
| 188e515972 | |||
| aabd595816 | |||
| 3053a86d1b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -31,6 +31,7 @@ bin/
|
|||||||
# fabric
|
# fabric
|
||||||
|
|
||||||
run/
|
run/
|
||||||
|
.tmp-mc/
|
||||||
|
|
||||||
# java
|
# java
|
||||||
|
|
||||||
|
|||||||
202
LICENSE
Normal file
202
LICENSE
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2025-2026 DekinDev (Straice)
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
4
NOTICE
Normal file
4
NOTICE
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Smooth Double Doors
|
||||||
|
Copyright 2025-2026 DekinDev (Straice)
|
||||||
|
|
||||||
|
This product includes software developed by DekinDev, https://straice.com.
|
||||||
12
README.md
12
README.md
@@ -1,2 +1,12 @@
|
|||||||
# Smooth-Double-Doors
|

|
||||||
|
|
||||||
|
Smooth Double Doors makes **paired doors open together** and adds **fluid animations** to **doors**, **trapdoors**, and **fence gates**. It keeps vanilla behavior and works with redstone, while letting you toggle features and adjust animation speed in‑game config. The mod is **texture‑pack friendly** and does **not replace models or require resource packs**, so it plays nicely with your existing packs.
|
||||||
|
|
||||||
|
Supports all door, trapdoor, and fence gate types.
|
||||||
|
|
||||||
|
By default, double trapdoors and double fence gates are disabled, but you can enable them in the mod’s settings. Everything is fully configurable!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
Requires [Mod Menu](https://modrinth.com/mod/modmenu) for the config screen.
|
||||||
@@ -11,11 +11,7 @@ base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// Add repositories to retrieve artifacts from in here.
|
maven { url "https://maven.terraformersmc.com/releases/" }
|
||||||
// You should only use this when depending on other mods because
|
|
||||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
|
||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
|
||||||
// for more information about repositories.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
@@ -39,6 +35,8 @@ dependencies {
|
|||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
|
||||||
|
|
||||||
|
modCompileOnly "com.terraformersmc:modmenu:15.0.0"
|
||||||
|
modRuntimeOnly "com.terraformersmc:modmenu:15.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|||||||
BIN
espacio.png
Normal file
BIN
espacio.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 217 KiB |
@@ -1,10 +1,11 @@
|
|||||||
package com.straice.smoothdoors;
|
package com.straice.smoothdoors;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
|
||||||
public class SmoothDoubleDoorsClient implements ClientModInitializer {
|
public class SmoothDoubleDoorsClient implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
SddAnimator.initClientHooks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.straice.smoothdoors.client.anim;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.DoorBlock;
|
||||||
|
import net.minecraft.block.ShapeContext;
|
||||||
|
import net.minecraft.block.enums.DoorHinge;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Box;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.RotationAxis;
|
||||||
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
|
||||||
|
final class DoorAnimation {
|
||||||
|
|
||||||
|
private DoorAnimation() {}
|
||||||
|
|
||||||
|
static void apply(BlockState state, float angleDeg, MatrixStack matrices, BlockRenderView world) {
|
||||||
|
if (world == null) return;
|
||||||
|
|
||||||
|
Direction facing = state.get(DoorBlock.FACING);
|
||||||
|
DoorHinge hinge = state.get(DoorBlock.HINGE);
|
||||||
|
|
||||||
|
Direction hingeSide = (hinge == DoorHinge.RIGHT)
|
||||||
|
? facing.rotateYClockwise()
|
||||||
|
: facing.rotateYCounterclockwise();
|
||||||
|
|
||||||
|
Box bb = state.getOutlineShape(world, BlockPos.ORIGIN, ShapeContext.absent()).getBoundingBox();
|
||||||
|
|
||||||
|
float cx = (float) ((bb.minX + bb.maxX) * 0.5);
|
||||||
|
float cz = (float) ((bb.minZ + bb.maxZ) * 0.5);
|
||||||
|
|
||||||
|
float pivotX = cx;
|
||||||
|
float pivotZ = cz;
|
||||||
|
|
||||||
|
switch (hingeSide) {
|
||||||
|
case EAST -> pivotX = (float) bb.maxX;
|
||||||
|
case WEST -> pivotX = (float) bb.minX;
|
||||||
|
case SOUTH -> pivotZ = (float) bb.maxZ;
|
||||||
|
case NORTH -> pivotZ = (float) bb.minZ;
|
||||||
|
default -> {
|
||||||
|
pivotX = cx;
|
||||||
|
pivotZ = cz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float thickness = (facing == Direction.NORTH || facing == Direction.SOUTH)
|
||||||
|
? (float) (bb.maxZ - bb.minZ)
|
||||||
|
: (float) (bb.maxX - bb.minX);
|
||||||
|
float halfT = thickness * 0.5f;
|
||||||
|
|
||||||
|
float dX = 0.0f;
|
||||||
|
float dZ = 0.0f;
|
||||||
|
switch (facing) {
|
||||||
|
case NORTH -> dZ = halfT;
|
||||||
|
case SOUTH -> dZ = -halfT;
|
||||||
|
case WEST -> dX = halfT;
|
||||||
|
case EAST -> dX = -halfT;
|
||||||
|
default -> {
|
||||||
|
dX = 0.0f;
|
||||||
|
dZ = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double rad = Math.toRadians(angleDeg);
|
||||||
|
float cos = (float) Math.cos(rad);
|
||||||
|
float sin = (float) Math.sin(rad);
|
||||||
|
float rotDX = dX * cos - dZ * sin;
|
||||||
|
float rotDZ = dX * sin + dZ * cos;
|
||||||
|
float shiftX = dX - rotDX;
|
||||||
|
float shiftZ = dZ - rotDZ;
|
||||||
|
|
||||||
|
matrices.translate(shiftX, 0.0f, shiftZ);
|
||||||
|
matrices.translate(pivotX, 0.0f, pivotZ);
|
||||||
|
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(angleDeg));
|
||||||
|
matrices.translate(-pivotX, 0.0f, -pivotZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,260 @@
|
|||||||
|
package com.straice.smoothdoors.client.anim;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.FenceGateBlock;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.render.RenderLayers;
|
||||||
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
|
import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
|
import net.minecraft.client.render.block.BlockModelRenderer;
|
||||||
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
|
import net.minecraft.client.render.model.BlockModelPart;
|
||||||
|
import net.minecraft.client.render.model.BlockStateModel;
|
||||||
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.RotationAxis;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
final class FenceGateAnimation {
|
||||||
|
|
||||||
|
private static final float POST_EDGE = 2.0f / 16.0f;
|
||||||
|
private static final float EDGE_EPS = 1.0e-4f;
|
||||||
|
|
||||||
|
private FenceGateAnimation() {}
|
||||||
|
|
||||||
|
static void render(BlockState state, float angleDeg, MatrixStack matrices,
|
||||||
|
VertexConsumerProvider consumers, int light, int overlay) {
|
||||||
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
if (mc.world == null) return;
|
||||||
|
|
||||||
|
Direction facing = state.get(FenceGateBlock.FACING);
|
||||||
|
boolean leftRightIsX = facing.getAxis() == Direction.Axis.Z;
|
||||||
|
|
||||||
|
BlockStateModel baseModel = mc.getBlockRenderManager().getModel(state);
|
||||||
|
FenceGateModels models = splitFenceGateModels(baseModel, leftRightIsX);
|
||||||
|
if (models.isEmpty()) return;
|
||||||
|
|
||||||
|
int tint = mc.getBlockColors().getColor(state, null, null, 0);
|
||||||
|
float r = ((tint >> 16) & 0xFF) / 255.0f;
|
||||||
|
float g = ((tint >> 8) & 0xFF) / 255.0f;
|
||||||
|
float b = (tint & 0xFF) / 255.0f;
|
||||||
|
|
||||||
|
VertexConsumer consumer = consumers.getBuffer(RenderLayers.getEntityBlockLayer(state));
|
||||||
|
|
||||||
|
if (models.posts != null) {
|
||||||
|
BlockModelRenderer.render(matrices.peek(), consumer, models.posts, r, g, b, light, overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
float leftPivotX = leftRightIsX ? (1.0f / 16.0f) : 0.5f;
|
||||||
|
float leftPivotZ = leftRightIsX ? 0.5f : (1.0f / 16.0f);
|
||||||
|
float rightPivotX = leftRightIsX ? (15.0f / 16.0f) : 0.5f;
|
||||||
|
float rightPivotZ = leftRightIsX ? 0.5f : (15.0f / 16.0f);
|
||||||
|
|
||||||
|
float sign = (facing == Direction.SOUTH || facing == Direction.EAST) ? 1.0f : -1.0f;
|
||||||
|
float signedAngle = angleDeg * sign;
|
||||||
|
float leftAngle = leftRightIsX ? -signedAngle : signedAngle;
|
||||||
|
float rightAngle = leftRightIsX ? signedAngle : -signedAngle;
|
||||||
|
|
||||||
|
if (models.left != null) {
|
||||||
|
matrices.push();
|
||||||
|
matrices.translate(leftPivotX, 0.0f, leftPivotZ);
|
||||||
|
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(leftAngle));
|
||||||
|
matrices.translate(-leftPivotX, 0.0f, -leftPivotZ);
|
||||||
|
BlockModelRenderer.render(matrices.peek(), consumer, models.left, r, g, b, light, overlay);
|
||||||
|
matrices.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (models.right != null) {
|
||||||
|
matrices.push();
|
||||||
|
matrices.translate(rightPivotX, 0.0f, rightPivotZ);
|
||||||
|
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(rightAngle));
|
||||||
|
matrices.translate(-rightPivotX, 0.0f, -rightPivotZ);
|
||||||
|
BlockModelRenderer.render(matrices.peek(), consumer, models.right, r, g, b, light, overlay);
|
||||||
|
matrices.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FenceGateModels splitFenceGateModels(BlockStateModel model, boolean leftRightIsX) {
|
||||||
|
List<BlockModelPart> parts = model.getParts(Random.create(42L));
|
||||||
|
List<BlockModelPart> posts = new ArrayList<>();
|
||||||
|
List<BlockModelPart> left = new ArrayList<>();
|
||||||
|
List<BlockModelPart> right = new ArrayList<>();
|
||||||
|
|
||||||
|
for (BlockModelPart part : parts) {
|
||||||
|
FenceGateCollector postsCollector = new FenceGateCollector();
|
||||||
|
FenceGateCollector leftCollector = new FenceGateCollector();
|
||||||
|
FenceGateCollector rightCollector = new FenceGateCollector();
|
||||||
|
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
addFenceGateQuads(part, dir, leftRightIsX, postsCollector, leftCollector, rightCollector);
|
||||||
|
}
|
||||||
|
addFenceGateQuads(part, null, leftRightIsX, postsCollector, leftCollector, rightCollector);
|
||||||
|
|
||||||
|
if (!postsCollector.isEmpty()) posts.add(postsCollector.toPart(part));
|
||||||
|
if (!leftCollector.isEmpty()) left.add(leftCollector.toPart(part));
|
||||||
|
if (!rightCollector.isEmpty()) right.add(rightCollector.toPart(part));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FenceGateModels(
|
||||||
|
posts.isEmpty() ? null : new StaticBlockStateModel(posts, model.particleSprite()),
|
||||||
|
left.isEmpty() ? null : new StaticBlockStateModel(left, model.particleSprite()),
|
||||||
|
right.isEmpty() ? null : new StaticBlockStateModel(right, model.particleSprite())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFenceGateQuads(BlockModelPart part, Direction dir, boolean leftRightIsX,
|
||||||
|
FenceGateCollector posts, FenceGateCollector left, FenceGateCollector right) {
|
||||||
|
List<BakedQuad> quads = part.getQuads(dir);
|
||||||
|
if (quads.isEmpty()) return;
|
||||||
|
|
||||||
|
for (BakedQuad quad : quads) {
|
||||||
|
FenceGateSection section = classifyFenceGateQuad(quad, leftRightIsX);
|
||||||
|
switch (section) {
|
||||||
|
case POSTS -> posts.add(dir, quad);
|
||||||
|
case LEFT -> addDoubleSided(left, dir, quad);
|
||||||
|
case RIGHT -> addDoubleSided(right, dir, quad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FenceGateSection classifyFenceGateQuad(BakedQuad quad, boolean leftRightIsX) {
|
||||||
|
int[] data = quad.vertexData();
|
||||||
|
if (data.length < 8) return FenceGateSection.LEFT;
|
||||||
|
|
||||||
|
int stride = data.length / 4;
|
||||||
|
float min = Float.POSITIVE_INFINITY;
|
||||||
|
float max = Float.NEGATIVE_INFINITY;
|
||||||
|
int coordOffset = leftRightIsX ? 0 : 2;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
int base = i * stride + coordOffset;
|
||||||
|
float coord = Float.intBitsToFloat(data[base]);
|
||||||
|
min = Math.min(min, coord);
|
||||||
|
max = Math.max(max, coord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max <= POST_EDGE + EDGE_EPS || min >= (1.0f - POST_EDGE) - EDGE_EPS) {
|
||||||
|
return FenceGateSection.POSTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
float center = (min + max) * 0.5f;
|
||||||
|
return center <= 0.5f ? FenceGateSection.LEFT : FenceGateSection.RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum FenceGateSection { POSTS, LEFT, RIGHT }
|
||||||
|
|
||||||
|
private static void addDoubleSided(FenceGateCollector target, Direction dir, BakedQuad quad) {
|
||||||
|
target.add(dir, quad);
|
||||||
|
target.add(dir, reverseQuad(quad));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BakedQuad reverseQuad(BakedQuad quad) {
|
||||||
|
int[] data = quad.vertexData();
|
||||||
|
int stride = data.length / 4;
|
||||||
|
int[] flipped = new int[data.length];
|
||||||
|
|
||||||
|
for (int v = 0; v < 4; v++) {
|
||||||
|
int src = (3 - v) * stride;
|
||||||
|
int dst = v * stride;
|
||||||
|
System.arraycopy(data, src, flipped, dst, stride);
|
||||||
|
}
|
||||||
|
|
||||||
|
Direction face = quad.face();
|
||||||
|
Direction opposite = (face == null) ? null : face.getOpposite();
|
||||||
|
return new BakedQuad(flipped, quad.tintIndex(), opposite, quad.sprite(), quad.shade(), quad.lightEmission());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class FenceGateModels {
|
||||||
|
final BlockStateModel posts;
|
||||||
|
final BlockStateModel left;
|
||||||
|
final BlockStateModel right;
|
||||||
|
|
||||||
|
FenceGateModels(BlockStateModel posts, BlockStateModel left, BlockStateModel right) {
|
||||||
|
this.posts = posts;
|
||||||
|
this.left = left;
|
||||||
|
this.right = right;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isEmpty() {
|
||||||
|
return posts == null && left == null && right == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class FenceGateCollector {
|
||||||
|
private final EnumMap<Direction, List<BakedQuad>> faceQuads = new EnumMap<>(Direction.class);
|
||||||
|
private final List<BakedQuad> unculled = new ArrayList<>();
|
||||||
|
|
||||||
|
void add(Direction face, BakedQuad quad) {
|
||||||
|
if (face == null) {
|
||||||
|
unculled.add(quad);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
faceQuads.computeIfAbsent(face, k -> new ArrayList<>()).add(quad);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isEmpty() {
|
||||||
|
return unculled.isEmpty() && faceQuads.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockModelPart toPart(BlockModelPart template) {
|
||||||
|
return new StaticBlockModelPart(faceQuads, unculled, template.useAmbientOcclusion(), template.particleSprite());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class StaticBlockModelPart implements BlockModelPart {
|
||||||
|
private final EnumMap<Direction, List<BakedQuad>> faceQuads;
|
||||||
|
private final List<BakedQuad> unculled;
|
||||||
|
private final boolean useAo;
|
||||||
|
private final Sprite particleSprite;
|
||||||
|
|
||||||
|
StaticBlockModelPart(EnumMap<Direction, List<BakedQuad>> faceQuads, List<BakedQuad> unculled,
|
||||||
|
boolean useAo, Sprite particleSprite) {
|
||||||
|
this.faceQuads = faceQuads;
|
||||||
|
this.unculled = unculled;
|
||||||
|
this.useAo = useAo;
|
||||||
|
this.particleSprite = particleSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BakedQuad> getQuads(Direction face) {
|
||||||
|
if (face == null) return unculled;
|
||||||
|
List<BakedQuad> quads = faceQuads.get(face);
|
||||||
|
return (quads == null) ? List.of() : quads;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean useAmbientOcclusion() {
|
||||||
|
return useAo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Sprite particleSprite() {
|
||||||
|
return particleSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class StaticBlockStateModel implements BlockStateModel {
|
||||||
|
private final List<BlockModelPart> parts;
|
||||||
|
private final Sprite particleSprite;
|
||||||
|
|
||||||
|
StaticBlockStateModel(List<BlockModelPart> parts, Sprite particleSprite) {
|
||||||
|
this.parts = parts;
|
||||||
|
this.particleSprite = particleSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addParts(Random random, List<BlockModelPart> out) {
|
||||||
|
out.addAll(parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Sprite particleSprite() {
|
||||||
|
return particleSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,383 @@
|
|||||||
|
package com.straice.smoothdoors.client.anim;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.config.SddConfig;
|
||||||
|
import com.straice.smoothdoors.config.SddConfigManager;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||||
|
import net.minecraft.block.*;
|
||||||
|
import net.minecraft.block.enums.DoorHinge;
|
||||||
|
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.render.OverlayTexture;
|
||||||
|
import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
|
import net.minecraft.client.render.WorldRenderer;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public final class SddAnimator {
|
||||||
|
|
||||||
|
private static final MinecraftClient MC = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
// Base duration (seconds) at speed = 1.0x
|
||||||
|
private static final float BASE_DURATION_S = 0.35f;
|
||||||
|
|
||||||
|
private static final Long2ObjectOpenHashMap<Anim> ANIMS = new Long2ObjectOpenHashMap<>();
|
||||||
|
private static boolean hooksInit = false;
|
||||||
|
|
||||||
|
private SddAnimator() {}
|
||||||
|
|
||||||
|
/** Llamar desde SmoothDoubleDoorsClient#onInitializeClient(). */
|
||||||
|
public static void initClientHooks() {
|
||||||
|
if (hooksInit) return;
|
||||||
|
hooksInit = true;
|
||||||
|
|
||||||
|
WorldRenderEvents.AFTER_ENTITIES.register(ctx -> {
|
||||||
|
if (MC.world == null || ANIMS.isEmpty()) return;
|
||||||
|
float tickDelta = MC.getRenderTickCounter().getTickProgress(true);
|
||||||
|
renderAll(tickDelta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// === API usada por mixins ===
|
||||||
|
|
||||||
|
/** Oculta el bloque vanilla mientras animamos (evita doble puerta). */
|
||||||
|
public static boolean shouldHideInChunk(BlockPos pos, BlockState state) {
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
if (ANIMS.containsKey(pos.asLong())) return true;
|
||||||
|
|
||||||
|
if (state.getBlock() instanceof DoorBlock && state.contains(DoorBlock.HALF)) {
|
||||||
|
DoubleBlockHalf half = state.get(DoorBlock.HALF);
|
||||||
|
BlockPos other = (half == DoubleBlockHalf.LOWER) ? pos.up() : pos.down();
|
||||||
|
return ANIMS.containsKey(other.asLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAnimatingAt(BlockPos pos) {
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
return ANIMS.containsKey(pos.asLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Se llama cuando cambia el bloque (abrir/cerrar). */
|
||||||
|
public static void onBlockUpdate(BlockPos pos, BlockState oldState, BlockState newState) {
|
||||||
|
if (MC.world == null) return;
|
||||||
|
|
||||||
|
Kind kind = kindOf(oldState, newState);
|
||||||
|
if (kind == null) {
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
ANIMS.remove(pos.asLong());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isKindBlock(kind, newState)) {
|
||||||
|
removeKindAt(pos, kind);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DOOR: arrancamos solo desde la mitad LOWER para no duplicar.
|
||||||
|
if (kind == Kind.DOOR && newState.contains(DoorBlock.HALF)) {
|
||||||
|
if (newState.get(DoorBlock.HALF) == DoubleBlockHalf.UPPER) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean oldOpen = isOpen(oldState);
|
||||||
|
boolean newOpen = isOpen(newState);
|
||||||
|
if (oldOpen == newOpen) return;
|
||||||
|
|
||||||
|
SddConfig cfg = SddConfigManager.get();
|
||||||
|
if (!isAnimationEnabled(cfg, kind)) {
|
||||||
|
removeKindAt(pos, kind);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float speed = speedFor(cfg, kind);
|
||||||
|
if (speed <= 0.001f) speed = 1.0f;
|
||||||
|
|
||||||
|
long startTick = MC.world.getTime();
|
||||||
|
|
||||||
|
if (kind == Kind.DOOR) {
|
||||||
|
startDoorAnimBothHalves(pos, newState, oldOpen, newOpen, speed, startTick);
|
||||||
|
} else {
|
||||||
|
BlockState base = forceClosedModel(newState, kind);
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
ANIMS.put(pos.asLong(), new Anim(pos.toImmutable(), base, kind, oldOpen, newOpen, speed, startTick));
|
||||||
|
}
|
||||||
|
requestRerender(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Render ===
|
||||||
|
|
||||||
|
private static void renderAll(float tickDelta) {
|
||||||
|
if (MC.world == null || ANIMS.isEmpty()) return;
|
||||||
|
|
||||||
|
Vec3d camPos = MC.gameRenderer.getCamera().getPos();
|
||||||
|
MatrixStack matrices = new MatrixStack();
|
||||||
|
VertexConsumerProvider.Immediate consumers = MC.getBufferBuilders().getEntityVertexConsumers();
|
||||||
|
|
||||||
|
long worldTick = MC.world.getTime();
|
||||||
|
double nowTick = worldTick + (double) MathHelper.clamp(tickDelta, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
Anim[] snapshot;
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
snapshot = ANIMS.values().toArray(new Anim[0]);
|
||||||
|
}
|
||||||
|
for (Anim a : snapshot) {
|
||||||
|
float t = a.progress01(nowTick);
|
||||||
|
renderOne(a, t, camPos, matrices, consumers);
|
||||||
|
}
|
||||||
|
|
||||||
|
consumers.draw();
|
||||||
|
cleanupFinished(nowTick);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cleanupFinished(double nowTick) {
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
var it = ANIMS.long2ObjectEntrySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
var entry = it.next();
|
||||||
|
if (entry.getValue().isFinished(nowTick)) {
|
||||||
|
BlockPos pos = entry.getValue().pos;
|
||||||
|
it.remove();
|
||||||
|
requestRerender(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderOne(Anim anim, float t, Vec3d camPos, MatrixStack matrices, VertexConsumerProvider consumers) {
|
||||||
|
if (MC.world == null) return;
|
||||||
|
|
||||||
|
BlockPos pos = anim.pos;
|
||||||
|
BlockState state = anim.baseState;
|
||||||
|
|
||||||
|
matrices.push();
|
||||||
|
|
||||||
|
// Fijo en mundo: bloque - camara
|
||||||
|
matrices.translate(
|
||||||
|
pos.getX() - camPos.x,
|
||||||
|
pos.getY() - camPos.y,
|
||||||
|
pos.getZ() - camPos.z
|
||||||
|
);
|
||||||
|
|
||||||
|
float eased = easeInOut(t);
|
||||||
|
float angleDeg = lerpAngleDeg(anim.fromOpen, anim.toOpen, eased, anim.kind, state);
|
||||||
|
|
||||||
|
int light = WorldRenderer.getLightmapCoordinates((net.minecraft.world.BlockRenderView) MC.world, pos);
|
||||||
|
if (anim.kind == Kind.FENCE_GATE) {
|
||||||
|
FenceGateAnimation.render(state, angleDeg, matrices, consumers, light, OverlayTexture.DEFAULT_UV);
|
||||||
|
} else {
|
||||||
|
applyTransform(anim.kind, state, angleDeg, matrices);
|
||||||
|
MC.getBlockRenderManager().renderBlockAsEntity(state, matrices, consumers, light, OverlayTexture.DEFAULT_UV);
|
||||||
|
}
|
||||||
|
|
||||||
|
matrices.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// === DOOR (dos mitades) ===
|
||||||
|
|
||||||
|
private static void startDoorAnimBothHalves(BlockPos lowerPos, BlockState lowerNewState, boolean oldOpen, boolean newOpen, float speed, long startTick) {
|
||||||
|
BlockState baseLower = forceClosedModel(lowerNewState, Kind.DOOR);
|
||||||
|
|
||||||
|
BlockPos upperPos = lowerPos.up();
|
||||||
|
BlockState baseUpper = baseLower.with(DoorBlock.HALF, DoubleBlockHalf.UPPER);
|
||||||
|
|
||||||
|
Anim aLower = new Anim(lowerPos.toImmutable(), baseLower, Kind.DOOR, oldOpen, newOpen, speed, startTick);
|
||||||
|
Anim aUpper = new Anim(upperPos.toImmutable(), baseUpper, Kind.DOOR, oldOpen, newOpen, speed, startTick);
|
||||||
|
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
ANIMS.put(lowerPos.asLong(), aLower);
|
||||||
|
ANIMS.put(upperPos.asLong(), aUpper);
|
||||||
|
}
|
||||||
|
requestRerender(lowerPos);
|
||||||
|
requestRerender(upperPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void removeKindAt(BlockPos pos, Kind kind) {
|
||||||
|
synchronized (ANIMS) {
|
||||||
|
ANIMS.remove(pos.asLong());
|
||||||
|
if (kind == Kind.DOOR) {
|
||||||
|
ANIMS.remove(pos.up().asLong());
|
||||||
|
ANIMS.remove(pos.down().asLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Angulos y transforms ===
|
||||||
|
|
||||||
|
private static float lerpAngleDeg(boolean fromOpen, boolean toOpen, float t, Kind kind, BlockState state) {
|
||||||
|
float a = angleFor(kind, state, fromOpen);
|
||||||
|
float b = angleFor(kind, state, toOpen);
|
||||||
|
return MathHelper.lerp(t, a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float angleFor(Kind kind, BlockState state, boolean open) {
|
||||||
|
if (!open) return 0.0f;
|
||||||
|
|
||||||
|
return switch (kind) {
|
||||||
|
case DOOR -> {
|
||||||
|
DoorHinge hinge = state.get(DoorBlock.HINGE);
|
||||||
|
yield (hinge == DoorHinge.RIGHT) ? -90.0f : 90.0f;
|
||||||
|
}
|
||||||
|
case TRAPDOOR -> 90.0f;
|
||||||
|
case FENCE_GATE -> 90.0f;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyTransform(Kind kind, BlockState state, float angleDeg, MatrixStack matrices) {
|
||||||
|
switch (kind) {
|
||||||
|
case DOOR -> DoorAnimation.apply(state, angleDeg, matrices, MC.world);
|
||||||
|
case TRAPDOOR -> TrapdoorAnimation.apply(state, angleDeg, matrices, MC.world);
|
||||||
|
case FENCE_GATE -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Utilidades ===
|
||||||
|
|
||||||
|
private static BlockState forceClosedModel(BlockState s, Kind kind) {
|
||||||
|
return switch (kind) {
|
||||||
|
case DOOR -> s.with(DoorBlock.OPEN, false);
|
||||||
|
case TRAPDOOR -> s.with(TrapdoorBlock.OPEN, false);
|
||||||
|
case FENCE_GATE -> s.with(FenceGateBlock.OPEN, false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isKindBlock(Kind kind, BlockState state) {
|
||||||
|
Block b = state.getBlock();
|
||||||
|
return switch (kind) {
|
||||||
|
case DOOR -> b instanceof DoorBlock;
|
||||||
|
case TRAPDOOR -> b instanceof TrapdoorBlock;
|
||||||
|
case FENCE_GATE -> b instanceof FenceGateBlock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void requestRerender(BlockPos pos) {
|
||||||
|
if (MC.worldRenderer == null || MC.world == null) return;
|
||||||
|
BlockState st = MC.world.getBlockState(pos);
|
||||||
|
MC.worldRenderer.updateBlock(MC.world, pos, st, st, 0);
|
||||||
|
MC.worldRenderer.scheduleBlockRenders(
|
||||||
|
pos.getX(), pos.getY(), pos.getZ(),
|
||||||
|
pos.getX(), pos.getY(), pos.getZ()
|
||||||
|
);
|
||||||
|
MC.worldRenderer.scheduleChunkRender(
|
||||||
|
pos.getX() >> 4,
|
||||||
|
pos.getY() >> 4,
|
||||||
|
pos.getZ() >> 4
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isOpen(BlockState s) {
|
||||||
|
Block b = s.getBlock();
|
||||||
|
if (b instanceof DoorBlock) return s.get(DoorBlock.OPEN);
|
||||||
|
if (b instanceof TrapdoorBlock) return s.get(TrapdoorBlock.OPEN);
|
||||||
|
if (b instanceof FenceGateBlock) return s.get(FenceGateBlock.OPEN);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Kind kindOf(BlockState oldState, BlockState newState) {
|
||||||
|
Block b = newState.getBlock();
|
||||||
|
if (b instanceof DoorBlock) return Kind.DOOR;
|
||||||
|
if (b instanceof TrapdoorBlock) return Kind.TRAPDOOR;
|
||||||
|
if (b instanceof FenceGateBlock) return Kind.FENCE_GATE;
|
||||||
|
|
||||||
|
b = oldState.getBlock();
|
||||||
|
if (b instanceof DoorBlock) return Kind.DOOR;
|
||||||
|
if (b instanceof TrapdoorBlock) return Kind.TRAPDOOR;
|
||||||
|
if (b instanceof FenceGateBlock) return Kind.FENCE_GATE;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAnimationEnabled(SddConfig cfg, Kind kind) {
|
||||||
|
return switch (kind) {
|
||||||
|
case DOOR -> cfg.animateDoors;
|
||||||
|
case TRAPDOOR -> cfg.animateTrapdoors;
|
||||||
|
case FENCE_GATE -> getBool(cfg, "animateFenceGates", false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float speedFor(SddConfig cfg, Kind kind) {
|
||||||
|
return switch (kind) {
|
||||||
|
case DOOR -> cfg.doorSpeed;
|
||||||
|
case TRAPDOOR -> cfg.trapdoorSpeed;
|
||||||
|
case FENCE_GATE -> getFloat(cfg, "fenceGateSpeed", 1.0f);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float easeInOut(float t) {
|
||||||
|
return t * t * (3.0f - 2.0f * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Reflect helpers (por si el campo no existe) ===
|
||||||
|
|
||||||
|
private static boolean getBool(Object obj, String field, boolean def) {
|
||||||
|
try {
|
||||||
|
Field f = obj.getClass().getDeclaredField(field);
|
||||||
|
f.setAccessible(true);
|
||||||
|
Object v = f.get(obj);
|
||||||
|
return (v instanceof Boolean) ? (Boolean) v : def;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float getFloat(Object obj, String field, float def) {
|
||||||
|
try {
|
||||||
|
Field f = obj.getClass().getDeclaredField(field);
|
||||||
|
f.setAccessible(true);
|
||||||
|
Object v = f.get(obj);
|
||||||
|
if (v instanceof Float) return (Float) v;
|
||||||
|
if (v instanceof Double) return ((Double) v).floatValue();
|
||||||
|
if (v instanceof Number) return ((Number) v).floatValue();
|
||||||
|
return def;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Tipos ===
|
||||||
|
|
||||||
|
public enum Kind { DOOR, TRAPDOOR, FENCE_GATE }
|
||||||
|
|
||||||
|
private static final class Anim {
|
||||||
|
final BlockPos pos;
|
||||||
|
final BlockState baseState;
|
||||||
|
final Kind kind;
|
||||||
|
final boolean fromOpen;
|
||||||
|
final boolean toOpen;
|
||||||
|
|
||||||
|
final double startTick;
|
||||||
|
final double durationTicks;
|
||||||
|
|
||||||
|
Anim(BlockPos pos, BlockState baseState, Kind kind, boolean fromOpen, boolean toOpen, float speed, long startTick) {
|
||||||
|
this.pos = pos;
|
||||||
|
this.baseState = baseState;
|
||||||
|
this.kind = kind;
|
||||||
|
this.fromOpen = fromOpen;
|
||||||
|
this.toOpen = toOpen;
|
||||||
|
|
||||||
|
double durS = BASE_DURATION_S / speed;
|
||||||
|
if (durS < 0.05) durS = 0.05;
|
||||||
|
|
||||||
|
this.startTick = (double) startTick;
|
||||||
|
this.durationTicks = Math.max(1.0, durS * 20.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float progress01(double nowTick) {
|
||||||
|
double t = (nowTick - startTick) / durationTicks;
|
||||||
|
if (t <= 0.0) return 0.0f;
|
||||||
|
if (t >= 1.0) return 1.0f;
|
||||||
|
return (float) t;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isFinished(double nowTick) {
|
||||||
|
return (nowTick - startTick) >= durationTicks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.straice.smoothdoors.client.anim;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.ShapeContext;
|
||||||
|
import net.minecraft.block.TrapdoorBlock;
|
||||||
|
import net.minecraft.block.enums.BlockHalf;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Box;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.RotationAxis;
|
||||||
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
|
||||||
|
final class TrapdoorAnimation {
|
||||||
|
|
||||||
|
private TrapdoorAnimation() {}
|
||||||
|
|
||||||
|
static void apply(BlockState state, float baseAngleDeg, MatrixStack matrices, BlockRenderView world) {
|
||||||
|
if (world == null) return;
|
||||||
|
|
||||||
|
Direction facing = state.get(TrapdoorBlock.FACING);
|
||||||
|
BlockHalf half = state.get(TrapdoorBlock.HALF);
|
||||||
|
|
||||||
|
VoxelShape collShape = state.getCollisionShape(world, BlockPos.ORIGIN, ShapeContext.absent());
|
||||||
|
Box bb = collShape.isEmpty()
|
||||||
|
? state.getOutlineShape(world, BlockPos.ORIGIN, ShapeContext.absent()).getBoundingBox()
|
||||||
|
: collShape.getBoundingBox();
|
||||||
|
|
||||||
|
Direction hingeSide = facing.getOpposite();
|
||||||
|
|
||||||
|
float pivotX = (float) ((bb.minX + bb.maxX) * 0.5);
|
||||||
|
float pivotZ = (float) ((bb.minZ + bb.maxZ) * 0.5);
|
||||||
|
switch (hingeSide) {
|
||||||
|
case NORTH -> pivotZ = (float) bb.minZ;
|
||||||
|
case SOUTH -> pivotZ = (float) bb.maxZ;
|
||||||
|
case WEST -> pivotX = (float) bb.minX;
|
||||||
|
case EAST -> pivotX = (float) bb.maxX;
|
||||||
|
default -> {
|
||||||
|
pivotX = (float) ((bb.minX + bb.maxX) * 0.5);
|
||||||
|
pivotZ = (float) ((bb.minZ + bb.maxZ) * 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float pivotY = (half == BlockHalf.TOP) ? (float) bb.maxY : (float) bb.minY;
|
||||||
|
|
||||||
|
float angle;
|
||||||
|
switch (hingeSide) {
|
||||||
|
case NORTH, EAST -> angle = -baseAngleDeg;
|
||||||
|
case SOUTH, WEST -> angle = baseAngleDeg;
|
||||||
|
default -> angle = baseAngleDeg;
|
||||||
|
}
|
||||||
|
if (half == BlockHalf.TOP) angle = -angle;
|
||||||
|
|
||||||
|
float thickness = (float) (bb.maxY - bb.minY);
|
||||||
|
float halfT = thickness > 0.0f ? thickness * 0.5f : (3.0f / 32.0f);
|
||||||
|
float dY = (half == BlockHalf.TOP) ? -halfT : halfT;
|
||||||
|
|
||||||
|
double rad = Math.toRadians(angle);
|
||||||
|
float cos = (float) Math.cos(rad);
|
||||||
|
float sin = (float) Math.sin(rad);
|
||||||
|
|
||||||
|
float shiftX = 0.0f;
|
||||||
|
float shiftY = 0.0f;
|
||||||
|
float shiftZ = 0.0f;
|
||||||
|
if (hingeSide == Direction.NORTH || hingeSide == Direction.SOUTH) {
|
||||||
|
float rotY = dY * cos;
|
||||||
|
float rotZ = dY * sin;
|
||||||
|
shiftY = dY - rotY;
|
||||||
|
shiftZ = -rotZ;
|
||||||
|
} else {
|
||||||
|
float rotX = -dY * sin;
|
||||||
|
float rotY = dY * cos;
|
||||||
|
shiftX = -rotX;
|
||||||
|
shiftY = dY - rotY;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrices.translate(shiftX, shiftY, shiftZ);
|
||||||
|
matrices.translate(pivotX, pivotY, pivotZ);
|
||||||
|
if (hingeSide == Direction.NORTH || hingeSide == Direction.SOUTH) {
|
||||||
|
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(angle));
|
||||||
|
} else {
|
||||||
|
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(angle));
|
||||||
|
}
|
||||||
|
matrices.translate(-pivotX, -pivotY, -pivotZ);
|
||||||
|
matrices.translate(-shiftX, -shiftY, -shiftZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
package com.straice.smoothdoors.client.ui;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.config.SddConfig;
|
||||||
|
import com.straice.smoothdoors.config.SddConfigManager;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.gui.Element;
|
||||||
|
import net.minecraft.client.gui.Selectable;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SliderWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ThreePartsLayoutWidget;
|
||||||
|
import net.minecraft.screen.ScreenTexts;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class SddConfigScreen extends Screen {
|
||||||
|
private static final int ITEM_HEIGHT = 24;
|
||||||
|
private static final int ROW_WIDTH = 310;
|
||||||
|
private static final int COLUMN_WIDTH = 150;
|
||||||
|
private static final int COLUMN_GAP = 10;
|
||||||
|
private static final int GROUP_GAP = 10;
|
||||||
|
|
||||||
|
private final Screen parent;
|
||||||
|
private final SddConfig cfg;
|
||||||
|
private final ThreePartsLayoutWidget layout = new ThreePartsLayoutWidget(this);
|
||||||
|
private SettingsList list;
|
||||||
|
|
||||||
|
public SddConfigScreen(Screen parent) {
|
||||||
|
super(Text.literal("Smooth Double Doors - Settings"));
|
||||||
|
this.parent = parent;
|
||||||
|
this.cfg = SddConfigManager.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
initHeader();
|
||||||
|
initBody();
|
||||||
|
initFooter();
|
||||||
|
|
||||||
|
layout.forEachChild(this::addDrawableChild);
|
||||||
|
refreshWidgetPositions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initHeader() {
|
||||||
|
layout.addHeader(this.title, this.textRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initBody() {
|
||||||
|
if (this.client == null) return;
|
||||||
|
list = layout.addBody(new SettingsList(this.client, this.width, layout));
|
||||||
|
|
||||||
|
list.addEntry(new SettingsEntry(
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Double Doors: " + (cfg.connectDoors ? "ON" : "OFF"),
|
||||||
|
() -> cfg.connectDoors = !cfg.connectDoors),
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Redstone Activable: " + (cfg.redstoneDoubleDoors ? "ON" : "OFF"),
|
||||||
|
() -> cfg.redstoneDoubleDoors = !cfg.redstoneDoubleDoors)
|
||||||
|
));
|
||||||
|
|
||||||
|
list.addEntry(new SettingsEntry(
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Door Animation: " + (cfg.animateDoors ? "ON" : "OFF"),
|
||||||
|
() -> cfg.animateDoors = !cfg.animateDoors),
|
||||||
|
new SpeedSlider(COLUMN_WIDTH, "Animation Speed", cfg.doorSpeed, v -> {
|
||||||
|
cfg.doorSpeed = v;
|
||||||
|
SddConfigManager.save();
|
||||||
|
})
|
||||||
|
));
|
||||||
|
|
||||||
|
list.addEntry(new SettingsEntry(
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Double Trapdoors: " + (cfg.connectTrapdoors ? "ON" : "OFF"),
|
||||||
|
() -> cfg.connectTrapdoors = !cfg.connectTrapdoors),
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Redstone Activable: " + (cfg.redstoneDoubleTrapdoors ? "ON" : "OFF"),
|
||||||
|
() -> cfg.redstoneDoubleTrapdoors = !cfg.redstoneDoubleTrapdoors),
|
||||||
|
GROUP_GAP
|
||||||
|
));
|
||||||
|
|
||||||
|
list.addEntry(new SettingsEntry(
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Trapdoor Animation: " + (cfg.animateTrapdoors ? "ON" : "OFF"),
|
||||||
|
() -> cfg.animateTrapdoors = !cfg.animateTrapdoors),
|
||||||
|
new SpeedSlider(COLUMN_WIDTH, "Animation Speed", cfg.trapdoorSpeed, v -> {
|
||||||
|
cfg.trapdoorSpeed = v;
|
||||||
|
SddConfigManager.save();
|
||||||
|
}),
|
||||||
|
GROUP_GAP
|
||||||
|
));
|
||||||
|
|
||||||
|
list.addEntry(new SettingsEntry(
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Double Fence Gates: " + (cfg.connectFenceGates ? "ON" : "OFF"),
|
||||||
|
() -> cfg.connectFenceGates = !cfg.connectFenceGates),
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Redstone Activable: " + (cfg.redstoneDoubleFenceGates ? "ON" : "OFF"),
|
||||||
|
() -> cfg.redstoneDoubleFenceGates = !cfg.redstoneDoubleFenceGates),
|
||||||
|
GROUP_GAP * 2
|
||||||
|
));
|
||||||
|
|
||||||
|
list.addEntry(new SettingsEntry(
|
||||||
|
toggle(COLUMN_WIDTH, () -> "Fence Gate Animation: " + (cfg.animateFenceGates ? "ON" : "OFF"),
|
||||||
|
() -> cfg.animateFenceGates = !cfg.animateFenceGates),
|
||||||
|
new SpeedSlider(COLUMN_WIDTH, "Animation Speed", cfg.fenceGateSpeed, v -> {
|
||||||
|
cfg.fenceGateSpeed = v;
|
||||||
|
SddConfigManager.save();
|
||||||
|
}),
|
||||||
|
GROUP_GAP * 2
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initFooter() {
|
||||||
|
layout.addFooter(ButtonWidget.builder(ScreenTexts.DONE, btn -> {
|
||||||
|
SddConfigManager.save();
|
||||||
|
if (this.client != null) this.client.setScreen(parent);
|
||||||
|
}).width(200).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void refreshWidgetPositions() {
|
||||||
|
layout.refreshPositions();
|
||||||
|
if (list != null) {
|
||||||
|
list.position(this.width, layout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
SddConfigManager.save();
|
||||||
|
if (this.client != null) this.client.setScreen(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ButtonWidget toggle(int width, java.util.function.Supplier<String> label, Runnable action) {
|
||||||
|
return ButtonWidget.builder(Text.literal(label.get()), btn -> {
|
||||||
|
action.run();
|
||||||
|
btn.setMessage(Text.literal(label.get()));
|
||||||
|
SddConfigManager.save();
|
||||||
|
}).dimensions(0, 0, width, 20).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class SettingsList extends ElementListWidget<SettingsEntry> {
|
||||||
|
SettingsList(MinecraftClient client, int width, ThreePartsLayoutWidget layout) {
|
||||||
|
super(client, width, layout.getContentHeight(), layout.getHeaderHeight(), ITEM_HEIGHT);
|
||||||
|
this.centerListVertically = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addEntry(SettingsEntry entry) {
|
||||||
|
return super.addEntry(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowWidth() {
|
||||||
|
return ROW_WIDTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class SettingsEntry extends ElementListWidget.Entry<SettingsEntry> {
|
||||||
|
private final ClickableWidget left;
|
||||||
|
private final ClickableWidget right;
|
||||||
|
private final List<ClickableWidget> widgets;
|
||||||
|
private final int topPadding;
|
||||||
|
|
||||||
|
SettingsEntry(ClickableWidget left, ClickableWidget right) {
|
||||||
|
this(left, right, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsEntry(ClickableWidget left, ClickableWidget right, int topPadding) {
|
||||||
|
this.left = left;
|
||||||
|
this.right = right;
|
||||||
|
this.topPadding = topPadding;
|
||||||
|
if (left == null && right == null) {
|
||||||
|
this.widgets = List.of();
|
||||||
|
} else if (right == null) {
|
||||||
|
this.widgets = List.of(left);
|
||||||
|
} else {
|
||||||
|
this.widgets = List.of(left, right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight,
|
||||||
|
int mouseX, int mouseY, boolean hovered, float delta) {
|
||||||
|
if (left == null && right == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (right == null) {
|
||||||
|
if (left == null) return;
|
||||||
|
left.setX(x);
|
||||||
|
left.setY(y + topPadding);
|
||||||
|
left.render(context, mouseX, mouseY, delta);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int leftX = x;
|
||||||
|
int rightX = x + COLUMN_WIDTH + COLUMN_GAP;
|
||||||
|
left.setX(leftX);
|
||||||
|
left.setY(y + topPadding);
|
||||||
|
right.setX(rightX);
|
||||||
|
right.setY(y + topPadding);
|
||||||
|
left.render(context, mouseX, mouseY, delta);
|
||||||
|
right.render(context, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Element> children() {
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Selectable> selectableChildren() {
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class SpeedSlider extends SliderWidget {
|
||||||
|
private final String label;
|
||||||
|
private final java.util.function.Consumer<Float> onApply;
|
||||||
|
|
||||||
|
private static float toSpeed(double v) { return (float) (0.2 + v * 2.8); }
|
||||||
|
private static double toValue(float speed) {
|
||||||
|
double v = (speed - 0.2) / 2.8;
|
||||||
|
if (v < 0) v = 0;
|
||||||
|
if (v > 1) v = 1;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpeedSlider(int width, String label, float speed,
|
||||||
|
java.util.function.Consumer<Float> onApply) {
|
||||||
|
super(0, 0, width, 20, Text.literal(label), toValue(speed));
|
||||||
|
this.label = label;
|
||||||
|
this.onApply = onApply;
|
||||||
|
updateMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateMessage() {
|
||||||
|
float sp = toSpeed(this.value);
|
||||||
|
setMessage(Text.literal(label + ": " + String.format(Locale.ROOT, "%.2f", sp) + "x"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyValue() {
|
||||||
|
onApply.accept(toSpeed(this.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.straice.smoothdoors.compat;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.client.ui.SddConfigScreen;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
|
||||||
|
public class ModMenuIntegration implements ModMenuApi {
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return parent -> new SddConfigScreen(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.straice.smoothdoors.mixin.client;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
|
import net.minecraft.client.render.block.BlockModelRenderer;
|
||||||
|
import net.minecraft.client.render.model.BlockModelPart;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
@Mixin(BlockModelRenderer.class)
|
||||||
|
public class BlockModelRendererMixin {
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "render(Lnet/minecraft/world/BlockRenderView;Ljava/util/List;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZI)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true,
|
||||||
|
require = 0
|
||||||
|
)
|
||||||
|
private void sdd$render(BlockRenderView world, List<BlockModelPart> parts, BlockState state, BlockPos pos,
|
||||||
|
MatrixStack matrices, VertexConsumer vertices, boolean cull, int overlay,
|
||||||
|
CallbackInfo ci) {
|
||||||
|
if (SddAnimator.shouldHideInChunk(pos, state)) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "renderSmooth(Lnet/minecraft/world/BlockRenderView;Ljava/util/List;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZI)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true,
|
||||||
|
require = 0
|
||||||
|
)
|
||||||
|
private void sdd$renderSmooth(BlockRenderView world, List<BlockModelPart> parts, BlockState state, BlockPos pos,
|
||||||
|
MatrixStack matrices, VertexConsumer vertices, boolean cull, int overlay,
|
||||||
|
CallbackInfo ci) {
|
||||||
|
if (SddAnimator.shouldHideInChunk(pos, state)) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "renderFlat(Lnet/minecraft/world/BlockRenderView;Ljava/util/List;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZI)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true,
|
||||||
|
require = 0
|
||||||
|
)
|
||||||
|
private void sdd$renderFlat(BlockRenderView world, List<BlockModelPart> parts, BlockState state, BlockPos pos,
|
||||||
|
MatrixStack matrices, VertexConsumer vertices, boolean cull, int overlay,
|
||||||
|
CallbackInfo ci) {
|
||||||
|
if (SddAnimator.shouldHideInChunk(pos, state)) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.straice.smoothdoors.mixin.client;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
|
import net.minecraft.client.render.block.BlockRenderManager;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mixin(BlockRenderManager.class)
|
||||||
|
public class BlockRenderManagerMixin {
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "renderBlock(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLjava/util/List;)V",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true,
|
||||||
|
require = 0
|
||||||
|
)
|
||||||
|
private void sdd$renderBlock(BlockState state, BlockPos pos, BlockRenderView world,
|
||||||
|
MatrixStack matrices, VertexConsumer vertexConsumer,
|
||||||
|
boolean cull, List<Object> parts,
|
||||||
|
CallbackInfo ci) {
|
||||||
|
if (SddAnimator.shouldHideInChunk(pos, state)) {
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "renderBlock(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Z)Z",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
cancellable = true,
|
||||||
|
require = 0
|
||||||
|
)
|
||||||
|
private void sdd$renderBlock(BlockState state, BlockPos pos, BlockRenderView world,
|
||||||
|
MatrixStack matrices, VertexConsumer vertexConsumer,
|
||||||
|
boolean cull, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (SddAnimator.shouldHideInChunk(pos, state)) {
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
cir.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.straice.smoothdoors.mixin.client;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.client.render.chunk.ChunkRendererRegion;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(ChunkRendererRegion.class)
|
||||||
|
public class ChunkRendererRegionMixin {
|
||||||
|
|
||||||
|
@Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void sdd$getBlockState(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
|
||||||
|
if (SddAnimator.isAnimatingAt(pos)) {
|
||||||
|
cir.setReturnValue(Blocks.AIR.getDefaultState());
|
||||||
|
cir.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.straice.smoothdoors.mixin.client;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.client.anim.SddAnimator;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.world.ClientWorld;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mixin(ClientWorld.class)
|
||||||
|
public class ClientWorldMixin {
|
||||||
|
|
||||||
|
@Inject(method = "updateListeners", at = @At("TAIL"))
|
||||||
|
private void sdd$updateListeners(BlockPos pos, BlockState oldState, BlockState newState, int flags, CallbackInfo ci) {
|
||||||
|
SddAnimator.onBlockUpdate(pos, oldState, newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.straice.smoothdoors.mixin.client;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Mixin(MinecraftClient.class)
|
|
||||||
public class ExampleClientMixin {
|
|
||||||
@Inject(at = @At("HEAD"), method = "run")
|
|
||||||
private void init(CallbackInfo info) {
|
|
||||||
// This code is injected into the start of MinecraftClient.run()V
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"required": true,
|
"required": true,
|
||||||
"package": "com.straice.smoothdoors.mixin.client",
|
"package": "com.straice.smoothdoors.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"client": [
|
"client": [
|
||||||
"ExampleClientMixin"
|
"client.ClientWorldMixin",
|
||||||
],
|
"client.BlockRenderManagerMixin",
|
||||||
"injectors": {
|
"client.BlockModelRendererMixin",
|
||||||
"defaultRequire": 1
|
"client.ChunkRendererRegionMixin"
|
||||||
}
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ import net.fabricmc.api.ModInitializer;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.config.SddConfigManager;
|
||||||
|
|
||||||
public class SmoothDoubleDoors implements ModInitializer {
|
public class SmoothDoubleDoors implements ModInitializer {
|
||||||
public static final String MOD_ID = "smooth-double-doors";
|
public static final String MOD_ID = "smooth-double-doors";
|
||||||
|
|
||||||
@@ -15,10 +17,7 @@ public class SmoothDoubleDoors implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
SddConfigManager.load();
|
||||||
// However, some things (like resources) may still be uninitialized.
|
LOGGER.info("Smooth Double Doors loaded");
|
||||||
// Proceed with mild caution.
|
|
||||||
|
|
||||||
LOGGER.info("Hello Fabric world!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
20
src/main/java/com/straice/smoothdoors/config/SddConfig.java
Normal file
20
src/main/java/com/straice/smoothdoors/config/SddConfig.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.straice.smoothdoors.config;
|
||||||
|
|
||||||
|
public class SddConfig {
|
||||||
|
public boolean connectDoors = true;
|
||||||
|
public boolean redstoneDoubleDoors = true;
|
||||||
|
|
||||||
|
public boolean connectTrapdoors = false;
|
||||||
|
public boolean redstoneDoubleTrapdoors = false;
|
||||||
|
|
||||||
|
public boolean connectFenceGates = false;
|
||||||
|
public boolean redstoneDoubleFenceGates = false;
|
||||||
|
|
||||||
|
public boolean animateDoors = true;
|
||||||
|
public boolean animateTrapdoors = true;
|
||||||
|
public boolean animateFenceGates = true;
|
||||||
|
|
||||||
|
public float doorSpeed = 1.0f;
|
||||||
|
public float trapdoorSpeed = 1.0f;
|
||||||
|
public float fenceGateSpeed = 1.0f;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.straice.smoothdoors.config;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class SddConfigManager {
|
||||||
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("smooth-double-doors.json");
|
||||||
|
|
||||||
|
private static SddConfig config = new SddConfig();
|
||||||
|
|
||||||
|
private SddConfigManager() {}
|
||||||
|
|
||||||
|
public static SddConfig get() { return config; }
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
try {
|
||||||
|
if (Files.exists(PATH)) {
|
||||||
|
String json = Files.readString(PATH);
|
||||||
|
SddConfig read = GSON.fromJson(json, SddConfig.class);
|
||||||
|
if (read != null) config = read;
|
||||||
|
} else {
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
// si falla, usamos defaults
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void save() {
|
||||||
|
try {
|
||||||
|
Files.createDirectories(PATH.getParent());
|
||||||
|
Files.writeString(PATH, GSON.toJson(config));
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.straice.smoothdoors.mixin;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.config.SddConfigManager;
|
||||||
|
import com.straice.smoothdoors.util.ConnectedUtil;
|
||||||
|
import com.straice.smoothdoors.util.SyncGuard;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.DoorBlock;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.state.property.Properties;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.block.WireOrientation;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(DoorBlock.class)
|
||||||
|
public class DoorBlockMixin {
|
||||||
|
|
||||||
|
@Inject(method = "onUse", at = @At("TAIL"))
|
||||||
|
private void sdd$onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit,
|
||||||
|
CallbackInfoReturnable<ActionResult> cir) {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (!SddConfigManager.get().connectDoors) return;
|
||||||
|
if (SyncGuard.isIn()) return;
|
||||||
|
|
||||||
|
BlockPos lower = ConnectedUtil.getDoorLowerPos(pos, state);
|
||||||
|
BlockState lowerNow = world.getBlockState(lower);
|
||||||
|
if (!lowerNow.contains(Properties.OPEN)) return;
|
||||||
|
|
||||||
|
boolean openNow = lowerNow.get(Properties.OPEN);
|
||||||
|
BlockPos mateLower = ConnectedUtil.findPairedDoorLower(world, lower, lowerNow);
|
||||||
|
if (mateLower == null) return;
|
||||||
|
|
||||||
|
SyncGuard.run(() -> ConnectedUtil.setDoorOpen(world, mateLower, openNow));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.21.8+: neighborUpdate(..., @Nullable WireOrientation wireOrientation, boolean notify)
|
||||||
|
@Inject(method = "neighborUpdate", at = @At("TAIL"))
|
||||||
|
private void sdd$neighborUpdate(BlockState state, World world, BlockPos pos, Block block,
|
||||||
|
@Nullable WireOrientation wireOrientation, boolean notify, CallbackInfo ci) {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (!SddConfigManager.get().connectDoors) return;
|
||||||
|
if (!SddConfigManager.get().redstoneDoubleDoors) return;
|
||||||
|
if (SyncGuard.isIn()) return;
|
||||||
|
|
||||||
|
BlockPos lower = ConnectedUtil.getDoorLowerPos(pos, state);
|
||||||
|
BlockState lowerNow = world.getBlockState(lower);
|
||||||
|
if (!lowerNow.contains(Properties.OPEN)) return;
|
||||||
|
|
||||||
|
boolean openNow = lowerNow.get(Properties.OPEN);
|
||||||
|
BlockPos mateLower = ConnectedUtil.findPairedDoorLower(world, lower, lowerNow);
|
||||||
|
if (mateLower == null) return;
|
||||||
|
|
||||||
|
SyncGuard.run(() -> ConnectedUtil.setDoorOpen(world, mateLower, openNow));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.straice.smoothdoors.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
|
||||||
public class ExampleMixin {
|
|
||||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
|
||||||
private void init(CallbackInfo info) {
|
|
||||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.straice.smoothdoors.mixin;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.config.SddConfigManager;
|
||||||
|
import com.straice.smoothdoors.util.ConnectedUtil;
|
||||||
|
import com.straice.smoothdoors.util.SyncGuard;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.FenceGateBlock;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.state.property.Properties;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.block.WireOrientation;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(FenceGateBlock.class)
|
||||||
|
public class FenceGateBlockMixin {
|
||||||
|
|
||||||
|
@Inject(method = "onUse", at = @At("TAIL"))
|
||||||
|
private void sdd$onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit,
|
||||||
|
CallbackInfoReturnable<ActionResult> cir) {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (!SddConfigManager.get().connectFenceGates) return;
|
||||||
|
if (SyncGuard.isIn()) return;
|
||||||
|
|
||||||
|
BlockState now = world.getBlockState(pos);
|
||||||
|
if (!now.contains(Properties.OPEN)) return;
|
||||||
|
|
||||||
|
boolean openNow = now.get(Properties.OPEN);
|
||||||
|
BlockPos mate = ConnectedUtil.findPairedFenceGate(world, pos, now);
|
||||||
|
if (mate == null) return;
|
||||||
|
|
||||||
|
SyncGuard.run(() -> ConnectedUtil.setFenceGateOpen(world, mate, openNow));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.21.8+: neighborUpdate(..., @Nullable WireOrientation wireOrientation, boolean notify)
|
||||||
|
@Inject(method = "neighborUpdate", at = @At("TAIL"))
|
||||||
|
private void sdd$neighborUpdate(BlockState state, World world, BlockPos pos, Block block,
|
||||||
|
@Nullable WireOrientation wireOrientation, boolean notify, CallbackInfo ci) {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (!SddConfigManager.get().connectFenceGates) return;
|
||||||
|
if (!SddConfigManager.get().redstoneDoubleFenceGates) return;
|
||||||
|
if (SyncGuard.isIn()) return;
|
||||||
|
|
||||||
|
BlockState now = world.getBlockState(pos);
|
||||||
|
if (!now.contains(Properties.OPEN)) return;
|
||||||
|
|
||||||
|
boolean openNow = now.get(Properties.OPEN);
|
||||||
|
BlockPos mate = ConnectedUtil.findPairedFenceGate(world, pos, now);
|
||||||
|
if (mate == null) return;
|
||||||
|
|
||||||
|
SyncGuard.run(() -> ConnectedUtil.setFenceGateOpen(world, mate, openNow));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.straice.smoothdoors.mixin;
|
||||||
|
|
||||||
|
import com.straice.smoothdoors.config.SddConfigManager;
|
||||||
|
import com.straice.smoothdoors.util.ConnectedUtil;
|
||||||
|
import com.straice.smoothdoors.util.SyncGuard;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.TrapdoorBlock;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.state.property.Properties;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.block.WireOrientation;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(TrapdoorBlock.class)
|
||||||
|
public class TrapdoorBlockMixin {
|
||||||
|
|
||||||
|
@Inject(method = "onUse", at = @At("TAIL"))
|
||||||
|
private void sdd$onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit,
|
||||||
|
CallbackInfoReturnable<ActionResult> cir) {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (!SddConfigManager.get().connectTrapdoors) return;
|
||||||
|
if (SyncGuard.isIn()) return;
|
||||||
|
|
||||||
|
BlockState now = world.getBlockState(pos);
|
||||||
|
if (!now.contains(Properties.OPEN)) return;
|
||||||
|
|
||||||
|
boolean openNow = now.get(Properties.OPEN);
|
||||||
|
BlockPos mate = ConnectedUtil.findPairedTrapdoor(world, pos, now);
|
||||||
|
if (mate == null) return;
|
||||||
|
|
||||||
|
SyncGuard.run(() -> ConnectedUtil.setTrapdoorOpen(world, mate, openNow));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.21.8+: neighborUpdate(..., @Nullable WireOrientation wireOrientation, boolean notify)
|
||||||
|
@Inject(method = "neighborUpdate", at = @At("TAIL"))
|
||||||
|
private void sdd$neighborUpdate(BlockState state, World world, BlockPos pos, Block block,
|
||||||
|
@Nullable WireOrientation wireOrientation, boolean notify, CallbackInfo ci) {
|
||||||
|
if (world.isClient) return;
|
||||||
|
if (!SddConfigManager.get().connectTrapdoors) return;
|
||||||
|
if (!SddConfigManager.get().redstoneDoubleTrapdoors) return;
|
||||||
|
if (SyncGuard.isIn()) return;
|
||||||
|
|
||||||
|
BlockState now = world.getBlockState(pos);
|
||||||
|
if (!now.contains(Properties.OPEN)) return;
|
||||||
|
|
||||||
|
boolean openNow = now.get(Properties.OPEN);
|
||||||
|
BlockPos mate = ConnectedUtil.findPairedTrapdoor(world, pos, now);
|
||||||
|
if (mate == null) return;
|
||||||
|
|
||||||
|
SyncGuard.run(() -> ConnectedUtil.setTrapdoorOpen(world, mate, openNow));
|
||||||
|
}
|
||||||
|
}
|
||||||
126
src/main/java/com/straice/smoothdoors/util/ConnectedUtil.java
Normal file
126
src/main/java/com/straice/smoothdoors/util/ConnectedUtil.java
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
package com.straice.smoothdoors.util;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.DoorBlock;
|
||||||
|
import net.minecraft.block.FenceGateBlock;
|
||||||
|
import net.minecraft.block.TrapdoorBlock;
|
||||||
|
import net.minecraft.block.enums.BlockHalf;
|
||||||
|
import net.minecraft.block.enums.DoorHinge;
|
||||||
|
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||||
|
import net.minecraft.state.property.Properties;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public final class ConnectedUtil {
|
||||||
|
private ConnectedUtil() {}
|
||||||
|
|
||||||
|
// ===== DOORS =====
|
||||||
|
|
||||||
|
public static BlockPos getDoorLowerPos(BlockPos pos, BlockState state) {
|
||||||
|
DoubleBlockHalf half = state.get(Properties.DOUBLE_BLOCK_HALF);
|
||||||
|
return half == DoubleBlockHalf.LOWER ? pos : pos.down();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockPos findPairedDoorLower(World world, BlockPos lowerPos, BlockState lowerState) {
|
||||||
|
if (!(lowerState.getBlock() instanceof DoorBlock)) return null;
|
||||||
|
|
||||||
|
Direction facing = lowerState.get(Properties.HORIZONTAL_FACING);
|
||||||
|
DoorHinge hinge = lowerState.get(Properties.DOOR_HINGE);
|
||||||
|
|
||||||
|
Direction side = (hinge == DoorHinge.LEFT)
|
||||||
|
? facing.rotateYClockwise()
|
||||||
|
: facing.rotateYCounterclockwise();
|
||||||
|
|
||||||
|
BlockPos otherLower = lowerPos.offset(side);
|
||||||
|
BlockState other = world.getBlockState(otherLower);
|
||||||
|
|
||||||
|
if (other.getBlock() != lowerState.getBlock()) return null;
|
||||||
|
if (!(other.getBlock() instanceof DoorBlock)) return null;
|
||||||
|
if (other.get(Properties.DOUBLE_BLOCK_HALF) != DoubleBlockHalf.LOWER) return null;
|
||||||
|
if (other.get(Properties.HORIZONTAL_FACING) != facing) return null;
|
||||||
|
if (other.get(Properties.DOOR_HINGE) == hinge) return null;
|
||||||
|
|
||||||
|
return otherLower;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDoorOpen(World world, BlockPos doorLower, boolean open) {
|
||||||
|
BlockState lower = world.getBlockState(doorLower);
|
||||||
|
if (!(lower.getBlock() instanceof DoorBlock)) return;
|
||||||
|
|
||||||
|
BlockPos upperPos = doorLower.up();
|
||||||
|
BlockState upper = world.getBlockState(upperPos);
|
||||||
|
|
||||||
|
world.setBlockState(doorLower, lower.with(Properties.OPEN, open), Block.NOTIFY_LISTENERS);
|
||||||
|
|
||||||
|
if (upper.getBlock() == lower.getBlock()) {
|
||||||
|
world.setBlockState(upperPos, upper.with(Properties.OPEN, open), Block.NOTIFY_LISTENERS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== TRAPDOORS =====
|
||||||
|
|
||||||
|
public static BlockPos findPairedTrapdoor(World world, BlockPos pos, BlockState state) {
|
||||||
|
if (!(state.getBlock() instanceof TrapdoorBlock)) return null;
|
||||||
|
|
||||||
|
Direction facing = state.get(Properties.HORIZONTAL_FACING);
|
||||||
|
BlockHalf half = state.get(Properties.BLOCK_HALF);
|
||||||
|
|
||||||
|
BlockPos left = pos.offset(facing.rotateYCounterclockwise());
|
||||||
|
BlockPos right = pos.offset(facing.rotateYClockwise());
|
||||||
|
|
||||||
|
BlockPos mate = matchTrapdoor(world, state, left, facing, half);
|
||||||
|
if (mate != null) return mate;
|
||||||
|
return matchTrapdoor(world, state, right, facing, half);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockPos matchTrapdoor(World world, BlockState a, BlockPos candidate, Direction facing, BlockHalf half) {
|
||||||
|
BlockState b = world.getBlockState(candidate);
|
||||||
|
if (b.getBlock() != a.getBlock()) return null;
|
||||||
|
if (!(b.getBlock() instanceof TrapdoorBlock)) return null;
|
||||||
|
|
||||||
|
if (b.get(Properties.HORIZONTAL_FACING) != facing) return null;
|
||||||
|
if (b.get(Properties.BLOCK_HALF) != half) return null;
|
||||||
|
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setTrapdoorOpen(World world, BlockPos pos, boolean open) {
|
||||||
|
BlockState st = world.getBlockState(pos);
|
||||||
|
if (!(st.getBlock() instanceof TrapdoorBlock)) return;
|
||||||
|
|
||||||
|
world.setBlockState(pos, st.with(Properties.OPEN, open), Block.NOTIFY_LISTENERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== FENCE GATES =====
|
||||||
|
|
||||||
|
public static BlockPos findPairedFenceGate(World world, BlockPos pos, BlockState state) {
|
||||||
|
if (!(state.getBlock() instanceof FenceGateBlock)) return null;
|
||||||
|
|
||||||
|
Direction facing = state.get(Properties.HORIZONTAL_FACING);
|
||||||
|
|
||||||
|
BlockPos left = pos.offset(facing.rotateYCounterclockwise());
|
||||||
|
BlockPos right = pos.offset(facing.rotateYClockwise());
|
||||||
|
|
||||||
|
BlockPos mate = matchFenceGate(world, state, left, facing);
|
||||||
|
if (mate != null) return mate;
|
||||||
|
return matchFenceGate(world, state, right, facing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockPos matchFenceGate(World world, BlockState a, BlockPos candidate, Direction facing) {
|
||||||
|
BlockState b = world.getBlockState(candidate);
|
||||||
|
if (b.getBlock() != a.getBlock()) return null;
|
||||||
|
if (!(b.getBlock() instanceof FenceGateBlock)) return null;
|
||||||
|
|
||||||
|
if (b.get(Properties.HORIZONTAL_FACING) != facing) return null;
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setFenceGateOpen(World world, BlockPos pos, boolean open) {
|
||||||
|
BlockState st = world.getBlockState(pos);
|
||||||
|
if (!(st.getBlock() instanceof FenceGateBlock)) return;
|
||||||
|
|
||||||
|
world.setBlockState(pos, st.with(Properties.OPEN, open), Block.NOTIFY_LISTENERS);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main/java/com/straice/smoothdoors/util/SyncGuard.java
Normal file
16
src/main/java/com/straice/smoothdoors/util/SyncGuard.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.straice.smoothdoors.util;
|
||||||
|
|
||||||
|
public final class SyncGuard {
|
||||||
|
private static final ThreadLocal<Boolean> IN = ThreadLocal.withInitial(() -> false);
|
||||||
|
|
||||||
|
private SyncGuard() {}
|
||||||
|
|
||||||
|
public static boolean isIn() { return IN.get(); }
|
||||||
|
|
||||||
|
public static void run(Runnable r) {
|
||||||
|
if (isIn()) return;
|
||||||
|
IN.set(true);
|
||||||
|
try { r.run(); }
|
||||||
|
finally { IN.set(false); }
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 958 KiB |
@@ -1,38 +1,32 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "smooth-double-doors",
|
"id": "smooth-double-doors",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
"name": "Smooth Double Doors",
|
"name": "Smooth Double Doors",
|
||||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
"description": "Make double doors, trapdoors, and fence gates open together with fluid smooth animations, fully configurable and texture-pack friendly.",
|
||||||
"authors": [
|
"authors": ["DekinDev"],
|
||||||
"Me!"
|
"contact": {
|
||||||
],
|
"sources": "https://git.straice.com/DekinDev/Smooth-Double-Doors",
|
||||||
"contact": {
|
"issues": "https://git.straice.com/DekinDev/Smooth-Double-Doors/issues",
|
||||||
"homepage": "https://fabricmc.net/",
|
"homepage": "https://modrinth.com/project/smooth-double-doors"
|
||||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
},
|
||||||
},
|
"license": "Apache-2.0",
|
||||||
"license": "CC0-1.0",
|
"icon": "assets/smooth-double-doors/icon.png",
|
||||||
"icon": "assets/smooth-double-doors/icon.png",
|
"environment": "*",
|
||||||
"environment": "*",
|
"entrypoints": {
|
||||||
"entrypoints": {
|
"main": ["com.straice.smoothdoors.SmoothDoubleDoors"],
|
||||||
"main": [
|
"client": ["com.straice.smoothdoors.SmoothDoubleDoorsClient"],
|
||||||
"com.straice.smoothdoors.SmoothDoubleDoors"
|
"modmenu": ["com.straice.smoothdoors.compat.ModMenuIntegration"]
|
||||||
],
|
},
|
||||||
"client": [
|
"mixins": [
|
||||||
"com.straice.smoothdoors.SmoothDoubleDoorsClient"
|
"smooth-double-doors.mixins.json",
|
||||||
]
|
"smooth-double-doors.client.mixins.json"
|
||||||
},
|
],
|
||||||
"mixins": [
|
"depends": {
|
||||||
"smooth-double-doors.mixins.json",
|
"fabricloader": ">=0.18.4",
|
||||||
{
|
"minecraft": ">=1.21.8 <=1.21.11",
|
||||||
"config": "smooth-double-doors.client.mixins.json",
|
"java": ">=21",
|
||||||
"environment": "client"
|
"fabric-api": "*",
|
||||||
}
|
"modmenu": "*"
|
||||||
],
|
}
|
||||||
"depends": {
|
|
||||||
"fabricloader": ">=0.18.4",
|
|
||||||
"minecraft": "~1.21.8",
|
|
||||||
"java": ">=21",
|
|
||||||
"fabric-api": "*"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"required": true,
|
"required": true,
|
||||||
"package": "com.straice.smoothdoors.mixin",
|
"package": "com.straice.smoothdoors.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"ExampleMixin"
|
"DoorBlockMixin",
|
||||||
],
|
"TrapdoorBlockMixin",
|
||||||
"injectors": {
|
"FenceGateBlockMixin"
|
||||||
"defaultRequire": 1
|
],
|
||||||
},
|
"injectors": {
|
||||||
"overwrites": {
|
"defaultRequire": 1
|
||||||
"requireAnnotations": true
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user