Update to 19w03c

This commit is contained in:
Shadowfacts 2019-01-19 11:59:58 -05:00
parent 126b5b7482
commit 9d3a80ddf5
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
10 changed files with 60 additions and 36 deletions

View File

@ -7,7 +7,7 @@ targetCompatibility = 1.8
archivesBaseName = "SimpleMultipart"
group = "net.shadowfacts.simplemultipart"
version = "0.1.2"
version = "0.1.3"
apply from: "https://raw.githubusercontent.com/shadowfacts/maven/master/maven.gradle"
@ -19,12 +19,12 @@ repositories {
}
dependencies {
minecraft "com.mojang:minecraft:19w02a"
mappings "net.fabricmc:yarn:19w02a.12"
modCompile "net.fabricmc:fabric-loader:0.3.2.92"
minecraft "com.mojang:minecraft:19w03c"
mappings "net.fabricmc:yarn:19w03c.1"
modCompile "net.fabricmc:fabric-loader:0.3.2.96"
// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc:fabric:0.1.4.71"
modCompile "net.fabricmc:fabric:0.1.4.77"
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task

View File

@ -53,7 +53,7 @@ public class SimpleMultipart implements ModInitializer {
private static <T extends BlockEntity> BlockEntityType<T> createBlockEntityType(String name, Supplier<T> supplier) {
BlockEntityType.Builder<T> builder = BlockEntityType.Builder.create(supplier);
return Registry.register(Registry.BLOCK_ENTITY, new Identifier(MODID, name), builder.method_11034(null));
return Registry.register(Registry.BLOCK_ENTITY, new Identifier(MODID, name), builder.build(null));
}
@Deprecated

View File

@ -2,7 +2,9 @@ package net.shadowfacts.simplemultipart.container;
import net.fabricmc.fabric.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.entity.VerticalEntityPosition;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.BlockHitResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
@ -29,7 +31,7 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
if (container == null) {
return false;
@ -40,7 +42,7 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
return false;
}
return hit.view.getState().activate(hit.view, hit.side, player, hand);
return hit.view.getState().activate(hit.view, hit.getSide(), player, hand);
}
@Override
@ -54,9 +56,7 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
return new ContainerBlockState(state, parts);
}
@Override
@Deprecated
public VoxelShape getBoundingShape(BlockState state, BlockView world, BlockPos pos) {
private VoxelShape getCombinedShape(BlockView world, BlockPos pos) {
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
if (container == null) {
return VoxelShapes.empty();
@ -70,6 +70,22 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
return shape == null ? VoxelShapes.empty() : shape;
}
@Override
@Deprecated
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, VerticalEntityPosition verticalEntityPosition) {
return getCombinedShape(world, pos);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, VerticalEntityPosition verticalEntityPosition) {
return getCombinedShape(world, pos);
}
@Override
public VoxelShape getRayTraceShape(BlockState state, BlockView world, BlockPos pos) {
return getCombinedShape(world, pos);
}
@Override
@Deprecated
public boolean hasSolidTopSurface(BlockState state, BlockView world, BlockPos pos) {

View File

@ -5,6 +5,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.BlockHitResult;
import net.shadowfacts.simplemultipart.SimpleMultipart;
import net.shadowfacts.simplemultipart.container.AbstractContainerBlockEntity;
import net.shadowfacts.simplemultipart.container.MultipartContainer;
@ -68,7 +69,8 @@ public class MultipartItem extends Item {
}
// Otherwise, get or create a new container and try inserting into that
ItemUsageContext offsetContext = new ItemUsageContext(context.getPlayer(), context.getItemStack(), context.getPos().offset(context.getFacing()), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
BlockHitResult offsetHitResult = new BlockHitResult(context.method_17698(), context.getFacing(), context.getPos().offset(context.getFacing()), context.method_17699());
ItemUsageContext offsetContext = new ItemUsageContext(context.getPlayer(), context.getItemStack(), offsetHitResult);
MultipartContainer offsetContainer = getOrCreateContainer(offsetContext);
if (offsetContainer != null) {
if (tryPlace(new MultipartPlacementContext(offsetContainer, true, offsetContext))) {

View File

@ -4,6 +4,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.state.property.Property;
import net.minecraft.util.BlockHitResult;
import net.minecraft.util.HitResult;
import net.shadowfacts.simplemultipart.SimpleMultipart;
import net.shadowfacts.simplemultipart.container.MultipartContainer;
@ -35,12 +36,13 @@ public abstract class MixinDebugHud {
public abstract String method_1845(Map.Entry<Property<?>, Comparable<?>> map$Entry_1);
@Inject(method = "getRightText", at = @At("RETURN"))
public void method_1839(CallbackInfoReturnable<List<String>> info) {
if (!client.hasReducedDebugInfo() && blockHit != null && blockHit.type == HitResult.Type.BLOCK) {
BlockEntity entity = client.world.getBlockEntity(blockHit.getBlockPos());
public void getRightText(CallbackInfoReturnable<List<String>> info) {
if (!client.hasReducedDebugInfo() && blockHit != null && blockHit.getType() == HitResult.Type.BLOCK) {
BlockHitResult hitResult = (BlockHitResult)blockHit;
BlockEntity entity = client.world.getBlockEntity(hitResult.getBlockPos());
if (entity instanceof MultipartContainer) {
MultipartContainer container = (MultipartContainer)entity;
MultipartHitResult result = MultipartHelper.rayTrace(container, client.world, blockHit.getBlockPos(), client.player);
MultipartHitResult result = MultipartHelper.rayTrace(container, client.world, hitResult.getBlockPos(), client.player);
if (result != null && result.view != null) {
info.getReturnValue().add("");
info.getReturnValue().add("Targeted Multipart");

View File

@ -3,6 +3,7 @@ package net.shadowfacts.simplemultipart.mixin.client;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.entity.VerticalEntityPosition;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
@ -20,8 +21,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(WorldRenderer.class)
public class MixinWorldRenderer {
@Redirect(method = "drawHighlightedBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getBoundingShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/shape/VoxelShape;"))
public VoxelShape getHighlightShape(BlockState state, BlockView world, BlockPos pos) {
@Redirect(method = "drawHighlightedBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getOutlineShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/VerticalEntityPosition;)Lnet/minecraft/util/shape/VoxelShape;"))
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, VerticalEntityPosition verticalEntityPosition) {
if (state.getBlock() == SimpleMultipart.containerBlock || state.getBlock() == SimpleMultipart.tickableContainerBlock) {
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
MultipartHitResult result = MultipartHelper.rayTrace(container, world, pos, MinecraftClient.getInstance().player);
@ -30,7 +31,7 @@ public class MixinWorldRenderer {
}
}
return state.getBoundingShape(world, pos);
return state.getOutlineShape(world, pos);
}
}

View File

@ -6,6 +6,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.state.PropertyContainer;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.Property;
import net.minecraft.util.BlockHitResult;
import net.minecraft.util.HitResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -72,11 +73,11 @@ public class MultipartHelper {
return container.getParts().stream()
.map(view -> {
VoxelShape shape = view.getState().getBoundingShape(view);
HitResult result = shape.rayTrace(start, end, pos);
BlockHitResult result = shape.rayTrace(start, end, pos);
return result == null ? null : new MultipartHitResult(result, view);
})
.filter(Objects::nonNull)
.min(Comparator.comparingDouble(hit -> hit.pos.subtract(start).lengthSquared()))
.min(Comparator.comparingDouble(hit -> hit.getPos().subtract(start).lengthSquared()))
.orElse(null);
}

View File

@ -1,6 +1,7 @@
package net.shadowfacts.simplemultipart.util;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.BlockHitResult;
import net.minecraft.util.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
@ -8,15 +9,16 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.shadowfacts.simplemultipart.container.MultipartContainer;
import net.shadowfacts.simplemultipart.multipart.MultipartView;
import sun.jvm.hotspot.opto.Block;
/**
* A raytrace result for a multipart.
*
* @author shadowfacts
* @since 0.1.0
* @see MultipartHelper#rayTrace(MultipartContainer, World, BlockPos, PlayerEntity)
* @see MultipartHelper#rayTrace(MultipartContainer, net.minecraft.world.BlockView, BlockPos, PlayerEntity)
*/
public class MultipartHitResult extends HitResult {
public class MultipartHitResult extends BlockHitResult {
/**
* The view of the hit multipart.
@ -24,19 +26,16 @@ public class MultipartHitResult extends HitResult {
public MultipartView view;
public MultipartHitResult(Vec3d pos, Direction side, BlockPos blockPos, MultipartView view) {
super(pos, side, blockPos);
super(pos, side, blockPos, false); // TODO: what does this boolean do?
this.view = view;
}
public MultipartHitResult(HitResult result, MultipartView view) {
this(result.pos, result.side, result.getBlockPos(), view);
if (result.type != Type.BLOCK) {
throw new IllegalArgumentException("Can't create a MultipartHitResult from a non BLOCK-type HitResult");
}
public MultipartHitResult(BlockHitResult result, MultipartView view) {
this(result.getPos(), result.getSide(), result.getBlockPos(), view);
}
@Override
public String toString() {
return "HitResult{type=" + type + ", blockpos=" + getBlockPos() + ", f=" + side + ", pos=" + pos + ", view=" + view + '}';
return "HitResult{type=" + getType() + ", blockpos=" + getBlockPos() + ", f=" + getSide() + ", pos=" + pos + ", view=" + view + '}';
}
}

View File

@ -3,6 +3,7 @@ package net.shadowfacts.simplemultipart.util;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.shadowfacts.simplemultipart.container.MultipartContainer;
@ -20,14 +21,14 @@ public class MultipartPlacementContext extends ItemUsageContext {
private final MultipartContainer container;
private final boolean isOffset;
public MultipartPlacementContext(MultipartContainer container, boolean isOffset, PlayerEntity player, ItemStack stack, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) {
super(player, stack, pos, side, hitX, hitY, hitZ);
public MultipartPlacementContext(MultipartContainer container, boolean isOffset, PlayerEntity player, ItemStack stack, BlockHitResult hitResult) {
super(player, stack, hitResult);
this.container = container;
this.isOffset = isOffset;
}
public MultipartPlacementContext(MultipartContainer container, boolean isOffset, ItemUsageContext context) {
this(container, isOffset, context.getPlayer(), context.getItemStack(), context.getPos(), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
this(container, isOffset, context.getPlayer(), context.getItemStack(), new BlockHitResult(context.method_17698(), context.getFacing(), context.getPos(), context.method_17699()));
}
/**

View File

@ -36,12 +36,14 @@ public class SlabMultipart extends Multipart {
Direction hitSide = context.getFacing();
BlockHalf half;
double absoluteHitY = context.method_17698().y; // method_17698 returns an absolutely position vector (i.e. in the world's coordinate space)
double relativeHitY = absoluteHitY - Math.floor(absoluteHitY); // this converts it to the block's coordinate space (e.g. 4.5 - Math.floor(4.5) = 0.5)
if (hitSide == Direction.DOWN) {
half = context.getHitY() >= 0.5f ? BlockHalf.BOTTOM : BlockHalf.TOP;
half = relativeHitY >= 0.5f ? BlockHalf.BOTTOM : BlockHalf.TOP;
} else if (hitSide == Direction.UP) {
half = 0.5f <= context.getHitY() && context.getHitY() < 1 ? BlockHalf.TOP : BlockHalf.BOTTOM;
half = 0.5f <= relativeHitY && relativeHitY < 1 ? BlockHalf.TOP : BlockHalf.BOTTOM;
} else {
half = context.getHitY() >= 0.5f ? BlockHalf.TOP : BlockHalf.BOTTOM;
half = relativeHitY >= 0.5f ? BlockHalf.TOP : BlockHalf.BOTTOM;
}
return getDefaultState().with(HALF, half);