Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Juuxel 2019-01-11 20:43:20 +02:00
commit 50d47ad7c9
7 changed files with 34 additions and 19 deletions

View File

@ -7,7 +7,7 @@ targetCompatibility = 1.8
archivesBaseName = "SimpleMultipart"
group = "net.shadowfacts.simplemultipart"
version = "0.1.1"
version = "0.1.2"
apply from: "https://raw.githubusercontent.com/shadowfacts/maven/master/maven.gradle"
@ -19,13 +19,12 @@ repositories {
}
dependencies {
minecraft "com.mojang:minecraft:18w50a"
// mappings "net.fabricmc:yarn:18w50a.80"
mappings "net.fabricmc:yarn:18w50a.local" // temporary until yarn #369
modCompile "net.fabricmc:fabric-loader:0.3.1.80"
minecraft "com.mojang:minecraft:19w02a"
mappings "net.fabricmc:yarn:19w02a.12"
modCompile "net.fabricmc:fabric-loader:0.3.2.92"
// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc:fabric:0.1.3.68"
modCompile "net.fabricmc:fabric:0.1.4.71"
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
@ -34,4 +33,4 @@ dependencies {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
}

View File

@ -8,6 +8,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@ -151,17 +152,16 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
}
@Override
public boolean breakPart(MultipartView view) {
public boolean breakPart(MultipartView view, PlayerEntity player) {
if (view.getContainer() != this || !(view instanceof Entry)) {
return false;
}
Entry e = (Entry)view;
if (world instanceof ServerWorld) {
if (world instanceof ServerWorld && !player.isCreative()) {
List<ItemStack> drops = getDroppedStacks(e, (ServerWorld)world, pos);
drops.forEach(stack -> Block.dropStack(world, pos, stack));
// TODO: don't drop if player is creative
}
remove(e);
@ -193,6 +193,11 @@ public abstract class AbstractContainerBlockEntity extends BlockEntity implement
world.scheduleBlockRender(pos);
BlockState blockState = world.getBlockState(pos);
world.updateListeners(pos, blockState, blockState, 3);
// both of these are required, some blocks (e.g. torch) use getStateForNeighborUpdate (used by updateNeighborStates)
// to update themselves, and some (e.g. redstone dust) use neighborUpdate to do so
blockState.updateNeighborStates(world, pos, 3); // updates the blockstates of the neighbors in the world
world.updateNeighbors(pos, blockState.getBlock()); // calls neighborUpdate on the neighbor blocks
}
private List<ItemStack> getDroppedStacks(Entry e, ServerWorld world, BlockPos pos) {

View File

@ -41,7 +41,7 @@ public class ContainerEventHandler {
return ActionResult.FAILURE;
}
boolean success = container.breakPart(hit.view);
boolean success = container.breakPart(hit.view, player);
return success ? ActionResult.SUCCESS : ActionResult.FAILURE;
}

View File

@ -1,5 +1,6 @@
package net.shadowfacts.simplemultipart.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
@ -99,7 +100,7 @@ public interface MultipartContainer {
* @param view The part to break.
* @return If the part has been successfully broken.
*/
boolean breakPart(MultipartView view);
boolean breakPart(MultipartView view, PlayerEntity player);
/**
* Indicates that something about a multipart in this container has changed and it should be saved to disk.

View File

@ -55,6 +55,7 @@ public class MultipartItem extends Item {
*
* If the player clicked an existing multipart container, it will attempt to insert into that one, falling back on
* creating a new container.
* Which container the placement is being attempted in can be determined from {@link MultipartPlacementContext#isOffset()}.
*
* @param context The item usage context.
* @return The result of the placement.
@ -62,7 +63,7 @@ public class MultipartItem extends Item {
protected ActionResult tryPlace(ItemUsageContext context) {
// If a multipart inside an existing container was clicked, try inserting into that
MultipartContainer hitContainer = getContainer(context);
if (hitContainer != null && tryPlace(new MultipartPlacementContext(hitContainer, context))) {
if (hitContainer != null && tryPlace(new MultipartPlacementContext(hitContainer, false, context))) {
return ActionResult.SUCCESS;
}
@ -70,7 +71,7 @@ public class MultipartItem extends Item {
ItemUsageContext offsetContext = new ItemUsageContext(context.getPlayer(), context.getItemStack(), context.getPos().offset(context.getFacing()), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
MultipartContainer offsetContainer = getOrCreateContainer(offsetContext);
if (offsetContainer != null) {
if (tryPlace(new MultipartPlacementContext(offsetContainer, offsetContext))) {
if (tryPlace(new MultipartPlacementContext(offsetContainer, true, offsetContext))) {
return ActionResult.SUCCESS;
} else {
// if the a new container was created, and no part was inserted, remove the empty container
@ -115,7 +116,7 @@ public class MultipartItem extends Item {
if (context.getContainer().canInsert(placementState)) {
context.getContainer().insert(placementState);
context.getItemStack().addAmount(-1);
context.getItemStack().subtractAmount(1);
return true;
}
return false;

View File

@ -34,7 +34,7 @@ public abstract class MixinDebugHud {
@Shadow
public abstract String method_1845(Map.Entry<Property<?>, Comparable<?>> map$Entry_1);
@Inject(method = "method_1839", at = @At("RETURN"))
@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());

View File

@ -18,14 +18,16 @@ import net.shadowfacts.simplemultipart.container.MultipartContainer;
public class MultipartPlacementContext extends ItemUsageContext {
private final MultipartContainer container;
private final boolean isOffset;
public MultipartPlacementContext(MultipartContainer container, PlayerEntity player, ItemStack stack, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) {
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);
this.container = container;
this.isOffset = isOffset;
}
public MultipartPlacementContext(MultipartContainer container, ItemUsageContext context) {
this(container, context.getPlayer(), context.getItemStack(), context.getPos(), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
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());
}
/**
@ -35,4 +37,11 @@ public class MultipartPlacementContext extends ItemUsageContext {
return container;
}
/**
* @return {@code false} if this container is the one clicked, {@code true} if this container is a newly created one offset from the block clicked.
* @since 0.1.2
*/
public boolean isOffset() {
return isOffset;
}
}