Skip to content

Commit

Permalink
Update to use official minecraft mappings provided by Mojang
Browse files Browse the repository at this point in the history
  • Loading branch information
fr1kin committed Aug 17, 2021
1 parent 3161eb5 commit eca8932
Show file tree
Hide file tree
Showing 150 changed files with 1,635 additions and 1,658 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ ext {
forgehaxVersion = "${forgehaxTag}-${forgehaxCommit}"

minecraftVersion = '1.16.5'
forgeVersion = '36.0.13'
forgeVersion = '36.2.2'

fmlVersion = '2.0.0-milestone.1'
lombokVersion = '1.18.16'

mcpVersion = '1.16.3'
mcpChannel = 'snapshot'
mcpVersion = '1.16.5'
mcpChannel = 'official'
mcpMapping = '20201028'
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/dev/fiki/forgehax/api/BlockHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static List<BlockPos> getBlocksInRadius(Vector3d pos, double radius) {
@Deprecated
public static float getBlockHardness(BlockPos pos) {
BlockState state = getWorld().getBlockState(pos);
return state.getBlockHardness(getWorld(), pos);
return state.getDestroySpeed(getWorld(), pos);
}

public static boolean isBlockReplaceable(BlockPos pos) {
Expand All @@ -89,8 +89,8 @@ public static boolean isTraceClear(Vector3d start, Vector3d end, BlockPos target
RayTraceContext ctx = new RayTraceContext(start, end,
RayTraceContext.BlockMode.OUTLINE,
RayTraceContext.FluidMode.NONE, getLocalPlayer());
BlockRayTraceResult tr = getWorld().rayTraceBlocks(ctx);
return tr.getPos().equals(target);
BlockRayTraceResult tr = getWorld().clip(ctx);
return tr.getBlockPos().equals(target);
}

public static boolean doesTraceHitBlockSide(Vector3d start, Vector3d end, BlockPos target, Direction direction) {
Expand All @@ -99,16 +99,16 @@ public static boolean doesTraceHitBlockSide(Vector3d start, Vector3d end, BlockP
RayTraceContext ctx = new RayTraceContext(start, end.add(dir.scale(2)),
RayTraceContext.BlockMode.OUTLINE,
RayTraceContext.FluidMode.NONE, getLocalPlayer());
BlockRayTraceResult tr = getWorld().rayTraceBlocks(ctx);
return tr.getPos().equals(target)
&& tr.getFace().equals(direction);
BlockRayTraceResult tr = getWorld().clip(ctx);
return tr.getBlockPos().equals(target)
&& tr.getDirection().equals(direction);
}

public static Vector3d getOBBCenter(BlockPos pos) {
BlockState state = getWorld().getBlockState(pos);
VoxelShape shape = state.getCollisionShape(getWorld(), pos);
if (!shape.isEmpty()) {
AxisAlignedBB bb = shape.getBoundingBox();
AxisAlignedBB bb = shape.bounds();
return new Vector3d(
bb.minX + ((bb.maxX - bb.minX) / 2.D),
bb.minY + ((bb.maxY - bb.minY) / 2.D),
Expand All @@ -125,15 +125,15 @@ public static boolean isBlockPlaceable(BlockPos pos) {
public static boolean isItemBlockPlaceable(Item item) {
if (item instanceof BlockItem) {
BlockItem blockItem = (BlockItem) item;
return blockItem.getBlock().getDefaultState().isOpaqueCube(getWorld(), BlockPos.ZERO);
return blockItem.getBlock().defaultBlockState().isCollisionShapeFullBlock(getWorld(), BlockPos.ZERO);
}
return false;
}

private static BlockTraceInfo getPlaceableBlockSideTrace(Vector3d eyes, Vector3d normal,
Stream<Direction> stream, BlockPos pos) {
return stream
.map(side -> new BlockTraceInfo(pos.offset(side), side))
.map(side -> new BlockTraceInfo(pos.relative(side), side))
.filter(info -> isBlockPlaceable(info.getPos()))
.filter(info -> LocalPlayerEx.isInReach(null, eyes, info.getHitVec()))
.filter(info -> BlockHelper.doesTraceHitBlockSide(eyes, info.getHitVec(), info.getPos(), info.getOppositeSide()))
Expand Down Expand Up @@ -178,7 +178,7 @@ private BlockTraceInfo(BlockPos pos, Direction side) {
this.side = side;
Vector3d obb = BlockHelper.getOBBCenter(pos);
this.centerPos = VectorUtil.toFPIVector(pos).add(obb);
this.hitVec = this.centerPos.add(obb.mul(VectorUtil.toFPIVector(getOppositeSide().getDirectionVec())));
this.hitVec = this.centerPos.add(obb.multiply(VectorUtil.toFPIVector(getOppositeSide().getNormal())));
}

public Direction getOppositeSide() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/fiki/forgehax/api/TextComponentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ private Style style() {
}

public TextComponentBuilder color(TextFormatting color) {
style().setColor(Color.fromTextFormatting(color));
style().withColor(Color.fromLegacyFormat(color));
return this;
}

public TextComponentBuilder bold(boolean bold) {
style().setBold(bold);
style().withBold(bold);
return this;
}

public TextComponentBuilder italic(boolean italic) {
style().setItalic(italic);
style().withItalic(italic);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,27 @@ public void bind(int keyCode) {
}

public void unbind() {
bind(INPUT_INVALID);
bind(UNKNOWN);
}

public int getKeyCode() {
return getKeyBinding().getKey().getKeyCode();
return getKeyBinding().getKey().getValue();
}

public boolean isKeyDown() {
return getKeyBinding().isKeyDown();
return getKeyBinding().isDown();
}

public boolean isKeyDownUnchecked() {
return getKeyBinding().isKeyDownUnchecked();
}

public boolean isPressed() {
return getKeyBinding().isPressed();
return getKeyBinding().consumeClick();
}

public boolean isUnbound() {
return INPUT_INVALID.equals(getKeyBinding().getKey());
return UNKNOWN.equals(getKeyBinding().getKey());
}

public int getKeyPressedTime() {
Expand All @@ -148,7 +148,7 @@ public String getKeyName() {

@Override
public KeyInput getValue() {
return KeyInput.getKeyInputByCode(getKeyBinding().getKey().getKeyCode());
return KeyInput.getKeyInputByCode(getKeyBinding().getKey().getValue());
}

@Override
Expand All @@ -163,7 +163,7 @@ public boolean setValueRaw(String value) {

@Override
public KeyInput getDefaultValue() {
return KeyInput.getKeyInputByCode(getKeyBinding().getKey().getKeyCode());
return KeyInput.getKeyInputByCode(getKeyBinding().getKey().getValue());
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/fiki/forgehax/api/draw/BufferProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
public class BufferProvider {
private final IRenderTypeBuffer.Impl bufferSource;
private final BufferBuilder defaultBuffer = Tessellator.getInstance().getBuffer();
private final BufferBuilder defaultBuffer = Tessellator.getInstance().getBuilder();

public BufferProvider() {
BufferMap buffers = new BufferMap()
Expand All @@ -21,11 +21,11 @@ public BufferProvider() {
.add(RenderTypeEx.glQuads())
.add(RenderTypeEx.blockTranslucentCull())
.add(RenderTypeEx.blockCutout())
.add(RenderType.getGlint())
.add(RenderType.getEntityGlint())
.add(RenderType.glint())
.add(RenderType.entityGlint())
;

this.bufferSource = IRenderTypeBuffer.getImpl(buffers.build(), defaultBuffer);
this.bufferSource = IRenderTypeBuffer.immediateWithBuffers(buffers.build(), defaultBuffer);
}

public BufferBuilder getBuffer(RenderType renderType) {
Expand All @@ -36,7 +36,7 @@ private static class BufferMap {
Map<RenderType, BufferBuilder> buffers = new Object2ObjectLinkedOpenHashMap<>();

public BufferMap add(RenderType type) {
buffers.put(type, new BufferBuilder(type.getBufferSize()));
buffers.put(type, new BufferBuilder(type.bufferSize()));
return this;
}

Expand Down
88 changes: 44 additions & 44 deletions src/main/java/dev/fiki/forgehax/api/draw/RenderTypeEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,45 @@
import java.util.OptionalDouble;

public class RenderTypeEx extends RenderType {
private static final RenderType GL_LINES = RenderType.makeType("fh_lines",
private static final RenderType GL_LINES = RenderType.create("fh_lines",
DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINES, 256,
RenderType.State.getBuilder()
.line(new RenderState.LineState(OptionalDouble.of(1.f)))
.cull(RenderState.CULL_DISABLED)
.depthTest(DEPTH_ALWAYS)
.transparency(RenderState.TRANSLUCENT_TRANSPARENCY)
.fog(RenderState.NO_FOG)
.build(false)
RenderType.State.builder()
.setLineState(new RenderState.LineState(OptionalDouble.of(1.f)))
.setCullState(RenderState.NO_CULL)
.setDepthTestState(RenderState.NO_DEPTH_TEST)
.setTransparencyState(RenderState.TRANSLUCENT_TRANSPARENCY)
.setFogState(RenderState.NO_FOG)
.createCompositeState(false)
);

private static final RenderType GL_LINE_LOOP = RenderType.makeType("fh_line_loop",
private static final RenderType GL_LINE_LOOP = RenderType.create("fh_line_loop",
DefaultVertexFormats.POSITION_COLOR, GL11.GL_LINE_LOOP, 256,
RenderType.State.getBuilder()
.line(new RenderState.LineState(OptionalDouble.empty()))
.transparency(RenderState.TRANSLUCENT_TRANSPARENCY)
.fog(RenderState.NO_FOG)
.build(false)
RenderType.State.builder()
.setLineState(new RenderState.LineState(OptionalDouble.empty()))
.setTransparencyState(RenderState.TRANSLUCENT_TRANSPARENCY)
.setFogState(RenderState.NO_FOG)
.createCompositeState(false)
);

private static final RenderType GL_TRIANGLES = RenderType.makeType("fh_triangles",
private static final RenderType GL_TRIANGLES = RenderType.create("fh_triangles",
DefaultVertexFormats.POSITION_COLOR, GL11.GL_TRIANGLES, 256,
RenderType.State.getBuilder()
.transparency(RenderState.TRANSLUCENT_TRANSPARENCY)
.fog(RenderState.NO_FOG)
.build(false)
RenderType.State.builder()
.setTransparencyState(RenderState.TRANSLUCENT_TRANSPARENCY)
.setFogState(RenderState.NO_FOG)
.createCompositeState(false)
);

private static final RenderType GL_QUADS = RenderType.makeType("fh_quads",
private static final RenderType GL_QUADS = RenderType.create("fh_quads",
DefaultVertexFormats.POSITION_COLOR, GL11.GL_QUADS, 256,
RenderType.State.getBuilder()
.transparency(RenderState.TRANSLUCENT_TRANSPARENCY)
.fog(RenderState.NO_FOG)
.build(false)
RenderType.State.builder()
.setTransparencyState(RenderState.TRANSLUCENT_TRANSPARENCY)
.setFogState(RenderState.NO_FOG)
.createCompositeState(false)
);

private static final RenderType BLOCK_TRANSLUCENT_CULL = entityTranslucentCull(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
private static final RenderType BLOCK_TRANSLUCENT_CULL = entityTranslucentCull(PlayerContainer.BLOCK_ATLAS);

private static final RenderType BLOCK_CUTOUT = entityCutout(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
private static final RenderType BLOCK_CUTOUT = entityCutout(PlayerContainer.BLOCK_ATLAS);

public static RenderType glLines() {
return GL_LINES;
Expand All @@ -76,28 +76,28 @@ public static RenderType blockCutout() {
}

public static RenderType entityTranslucentCull(ResourceLocation texture) {
RenderType.State state = RenderType.State.getBuilder()
.texture(new RenderState.TextureState(texture, false, false))
.transparency(TRANSLUCENT_TRANSPARENCY)
.diffuseLighting(DIFFUSE_LIGHTING_DISABLED)
.alpha(DEFAULT_ALPHA)
.lightmap(LIGHTMAP_DISABLED)
.overlay(OVERLAY_ENABLED)
.build(true);
return makeType("fh_entity_translucent_cull", DefaultVertexFormats.ENTITY,
RenderType.State state = RenderType.State.builder()
.setTextureState(new RenderState.TextureState(texture, false, false))
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setDiffuseLightingState(RenderState.NO_DIFFUSE_LIGHTING)
.setAlphaState(DEFAULT_ALPHA)
.setLightmapState(RenderState.NO_LIGHTMAP)
.setOverlayState(RenderState.OVERLAY)
.createCompositeState(true);
return create("fh_entity_translucent_cull", DefaultVertexFormats.NEW_ENTITY,
GL11.GL_QUADS, 256, true, true, state);
}

public static RenderType entityCutout(ResourceLocation texture) {
RenderType.State state = RenderType.State.getBuilder()
.texture(new RenderState.TextureState(texture, false, false))
.transparency(NO_TRANSPARENCY)
.diffuseLighting(DIFFUSE_LIGHTING_DISABLED)
.alpha(DEFAULT_ALPHA)
.lightmap(LIGHTMAP_DISABLED)
.overlay(OVERLAY_ENABLED)
.build(true);
return makeType("fh_entity_cutout", DefaultVertexFormats.ENTITY,
RenderType.State state = RenderType.State.builder()
.setTextureState(new RenderState.TextureState(texture, false, false))
.setTransparencyState(NO_TRANSPARENCY)
.setDiffuseLightingState(RenderState.NO_DIFFUSE_LIGHTING)
.setAlphaState(DEFAULT_ALPHA)
.setLightmapState(RenderState.NO_LIGHTMAP)
.setOverlayState(RenderState.OVERLAY)
.createCompositeState(true);
return create("fh_entity_cutout", DefaultVertexFormats.NEW_ENTITY,
GL11.GL_QUADS, 256, true, false, state);
}

Expand Down
Loading

0 comments on commit eca8932

Please sign in to comment.