This commit is contained in:
parent
4ebd156bdc
commit
8164f8f8b9
@ -13,9 +13,11 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
|||||||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||||
import net.fabricmc.fabric.api.tag.TagRegistry;
|
import net.fabricmc.fabric.api.tag.TagRegistry;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
|
||||||
import net.minecraft.screen.ScreenHandlerType;
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
import net.minecraft.tag.Tag;
|
import net.minecraft.tag.Tag;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
@ -18,7 +18,8 @@ public class ChestBoatCriterion extends AbstractCriterion<AbstractCriterionCondi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
|
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
|
||||||
return new AbstractCriterionConditions(ID, playerPredicate) {};
|
return new AbstractCriterionConditions(ID, playerPredicate) {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,8 @@ public class EnderChestBoatCriterion extends AbstractCriterion<AbstractCriterion
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
|
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
|
||||||
return new AbstractCriterionConditions(ID, playerPredicate) {};
|
return new AbstractCriterionConditions(ID, playerPredicate) {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.thebrokenrail.twine.block;
|
package com.thebrokenrail.twine.block;
|
||||||
|
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.DispenserBlock;
|
||||||
|
import net.minecraft.block.Material;
|
||||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||||
import net.minecraft.block.dispenser.ItemDispenserBehavior;
|
import net.minecraft.block.dispenser.ItemDispenserBehavior;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
@ -3,7 +3,6 @@ package com.thebrokenrail.twine.block;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.Material;
|
import net.minecraft.block.Material;
|
||||||
import net.minecraft.block.MaterialColor;
|
import net.minecraft.block.MaterialColor;
|
||||||
import net.minecraft.entity.AreaEffectCloudEntity;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
|
@ -36,19 +36,19 @@ import java.util.List;
|
|||||||
public class MixinBoatEntity implements BoatUtil {
|
public class MixinBoatEntity implements BoatUtil {
|
||||||
@Inject(at = @At("RETURN"), method = "initDataTracker")
|
@Inject(at = @At("RETURN"), method = "initDataTracker")
|
||||||
public void initDataTracker(CallbackInfo info) {
|
public void initDataTracker(CallbackInfo info) {
|
||||||
((BoatEntity) (Object) this).getDataTracker().startTracking(BoatUtil.HAS_CHEST, BoatChestMode.NONE.name());
|
((BoatEntity) (Object) this).getDataTracker().startTracking(BoatUtil.HAS_CHEST, ChestMode.NONE.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "canAddPassenger", cancellable = true)
|
@Inject(at = @At("HEAD"), method = "canAddPassenger", cancellable = true)
|
||||||
public void canAddPassenger(Entity passenger, CallbackInfoReturnable<Boolean> info) {
|
public void canAddPassenger(Entity passenger, CallbackInfoReturnable<Boolean> info) {
|
||||||
if (((BoatEntity) (Object) this).getPassengerList().size() > 0 && getChestMode() != BoatChestMode.NONE) {
|
if (((BoatEntity) (Object) this).getPassengerList().size() > 0 && getChestMode() != ChestMode.NONE) {
|
||||||
info.setReturnValue(false);
|
info.setReturnValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"), method = "updatePassengerPosition", allow = 2, require = 2)
|
@Redirect(at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"), method = "updatePassengerPosition", allow = 2, require = 2)
|
||||||
public int updatePassengerPosition(List<Entity> list) {
|
public int updatePassengerPosition(List<Entity> list) {
|
||||||
if (getChestMode() != BoatChestMode.NONE) {
|
if (getChestMode() != ChestMode.NONE) {
|
||||||
return list.size() + 1;
|
return list.size() + 1;
|
||||||
} else {
|
} else {
|
||||||
return list.size();
|
return list.size();
|
||||||
@ -57,10 +57,10 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "interact", cancellable = true)
|
@Inject(at = @At("HEAD"), method = "interact", cancellable = true)
|
||||||
public void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> info) {
|
public void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> info) {
|
||||||
BoatChestMode hasChest = getChestMode();
|
ChestMode hasChest = getChestMode();
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
BoatChestMode newMode = BoatChestMode.valueOF(stack.getItem());
|
ChestMode newMode = ChestMode.valueOF(stack.getItem());
|
||||||
if (newMode != BoatChestMode.NONE && hasChest == BoatChestMode.NONE) {
|
if (newMode != ChestMode.NONE && hasChest == ChestMode.NONE) {
|
||||||
List<Entity> passengers = ((BoatEntity) (Object) this).getPassengerList();
|
List<Entity> passengers = ((BoatEntity) (Object) this).getPassengerList();
|
||||||
for (int i = 1; i < passengers.size(); i++) {
|
for (int i = 1; i < passengers.size(); i++) {
|
||||||
passengers.get(i).stopRiding();
|
passengers.get(i).stopRiding();
|
||||||
@ -68,7 +68,7 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
if (!player.getEntityWorld().isClient()) {
|
if (!player.getEntityWorld().isClient()) {
|
||||||
if (newMode.hasItems()) {
|
if (newMode.hasItems()) {
|
||||||
Twine.CHEST_BOAT_CRITERION.trigger((ServerPlayerEntity) player);
|
Twine.CHEST_BOAT_CRITERION.trigger((ServerPlayerEntity) player);
|
||||||
} else if (newMode == BoatChestMode.ENDER_CHEST) {
|
} else if (newMode == ChestMode.ENDER_CHEST) {
|
||||||
Twine.ENDER_CHEST_BOAT_CRITERION.trigger((ServerPlayerEntity) player);
|
Twine.ENDER_CHEST_BOAT_CRITERION.trigger((ServerPlayerEntity) player);
|
||||||
}
|
}
|
||||||
setChestMode(newMode);
|
setChestMode(newMode);
|
||||||
@ -87,7 +87,7 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private void setChestMode(BoatChestMode mode) {
|
private void setChestMode(ChestMode mode) {
|
||||||
((BoatEntity) (Object) this).getDataTracker().set(BoatUtil.HAS_CHEST, mode.name());
|
((BoatEntity) (Object) this).getDataTracker().set(BoatUtil.HAS_CHEST, mode.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
|
|
||||||
@Inject(at = @At("RETURN"), method = "writeCustomDataToTag")
|
@Inject(at = @At("RETURN"), method = "writeCustomDataToTag")
|
||||||
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
|
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
|
||||||
BoatChestMode hasChest = getChestMode();
|
ChestMode hasChest = getChestMode();
|
||||||
tag.putString("HasChest", hasChest.name());
|
tag.putString("HasChest", hasChest.name());
|
||||||
if (hasChest.hasItems()) {
|
if (hasChest.hasItems()) {
|
||||||
ListTag listTag = new ListTag();
|
ListTag listTag = new ListTag();
|
||||||
@ -154,11 +154,11 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
|
|
||||||
@Inject(at = @At("RETURN"), method = "readCustomDataFromTag")
|
@Inject(at = @At("RETURN"), method = "readCustomDataFromTag")
|
||||||
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
||||||
BoatChestMode hasChest;
|
ChestMode hasChest;
|
||||||
try {
|
try {
|
||||||
hasChest = BoatChestMode.valueOf(tag.getString("HasChest"));
|
hasChest = ChestMode.valueOf(tag.getString("HasChest"));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
hasChest = BoatChestMode.NONE;
|
hasChest = ChestMode.NONE;
|
||||||
}
|
}
|
||||||
setChestMode(hasChest);
|
setChestMode(hasChest);
|
||||||
updateInventory();
|
updateInventory();
|
||||||
@ -176,11 +176,11 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BoatChestMode getChestMode() {
|
public ChestMode getChestMode() {
|
||||||
try {
|
try {
|
||||||
return BoatChestMode.valueOf(((BoatEntity) (Object) this).getDataTracker().get(BoatUtil.HAS_CHEST));
|
return ChestMode.valueOf(((BoatEntity) (Object) this).getDataTracker().get(BoatUtil.HAS_CHEST));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return BoatChestMode.NONE;
|
return ChestMode.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ public class MixinBoatEntity implements BoatUtil {
|
|||||||
public void openInventory(PlayerEntity player) {
|
public void openInventory(PlayerEntity player) {
|
||||||
if (getChestMode().hasItems()) {
|
if (getChestMode().hasItems()) {
|
||||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, getChestInventory()), ((BoatEntity) (Object) this).getDisplayName()));
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, getChestInventory()), ((BoatEntity) (Object) this).getDisplayName()));
|
||||||
} else {
|
} else if (getChestMode() == ChestMode.ENDER_CHEST) {
|
||||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, new EnderChestInventoryWrapper((BoatEntity) (Object) this, player.getEnderChestInventory())), EnderChestBlock.CONTAINER_NAME));
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, new EnderChestInventoryWrapper((BoatEntity) (Object) this, player.getEnderChestInventory())), EnderChestBlock.CONTAINER_NAME));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class MixinClientPlayerInteractionManager {
|
|||||||
@Inject(at = @At("HEAD"), method = "hasRidingInventory", cancellable = true)
|
@Inject(at = @At("HEAD"), method = "hasRidingInventory", cancellable = true)
|
||||||
public void hasRidingInventory(CallbackInfoReturnable<Boolean> info) {
|
public void hasRidingInventory(CallbackInfoReturnable<Boolean> info) {
|
||||||
assert client.player != null;
|
assert client.player != null;
|
||||||
if (client.player.hasVehicle() && client.player.getVehicle() instanceof BoatEntity && ((BoatUtil) client.player.getVehicle()).getChestMode() != BoatUtil.BoatChestMode.NONE) {
|
if (client.player.hasVehicle() && client.player.getVehicle() instanceof BoatEntity && ((BoatUtil) client.player.getVehicle()).getChestMode() != BoatUtil.ChestMode.NONE) {
|
||||||
info.setReturnValue(true);
|
info.setReturnValue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,10 @@ import com.thebrokenrail.twine.util.StageUtil;
|
|||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.ai.goal.FollowTargetGoal;
|
import net.minecraft.entity.ai.goal.FollowTargetGoal;
|
||||||
import net.minecraft.entity.ai.goal.GoalSelector;
|
import net.minecraft.entity.ai.goal.GoalSelector;
|
||||||
import net.minecraft.entity.mob.*;
|
import net.minecraft.entity.mob.CreeperEntity;
|
||||||
|
import net.minecraft.entity.mob.MobEntity;
|
||||||
|
import net.minecraft.entity.mob.MobEntityWithAi;
|
||||||
|
import net.minecraft.entity.mob.Monster;
|
||||||
import net.minecraft.entity.passive.IronGolemEntity;
|
import net.minecraft.entity.passive.IronGolemEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
@ -18,7 +18,7 @@ public class MixinServerPlayNetworkHandler {
|
|||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "onClientCommand")
|
@Inject(at = @At("TAIL"), method = "onClientCommand")
|
||||||
public void onClientCommand(ClientCommandC2SPacket packet, CallbackInfo info) {
|
public void onClientCommand(ClientCommandC2SPacket packet, CallbackInfo info) {
|
||||||
if (packet.getMode() == ClientCommandC2SPacket.Mode.OPEN_INVENTORY && player.hasVehicle() && player.getVehicle() instanceof BoatEntity && ((BoatUtil) player.getVehicle()).getChestMode() != BoatUtil.BoatChestMode.NONE) {
|
if (packet.getMode() == ClientCommandC2SPacket.Mode.OPEN_INVENTORY && player.hasVehicle() && player.getVehicle() instanceof BoatEntity && ((BoatUtil) player.getVehicle()).getChestMode() != BoatUtil.ChestMode.NONE) {
|
||||||
((BoatUtil) player.getVehicle()).openInventory(player);
|
((BoatUtil) player.getVehicle()).openInventory(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class BoatInventory extends SimpleInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayerUse(PlayerEntity player) {
|
public boolean canPlayerUse(PlayerEntity player) {
|
||||||
return BoatUtil.canReachEntity(player, entity) && entity.isAlive() && ((BoatUtil) entity).getChestMode() == BoatUtil.BoatChestMode.CHEST && super.canPlayerUse(player);
|
return BoatUtil.canReachEntity(player, entity) && entity.isAlive() && ((BoatUtil) entity).getChestMode() == BoatUtil.ChestMode.CHEST && super.canPlayerUse(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,7 +16,7 @@ import net.minecraft.util.math.Vec3d;
|
|||||||
public interface BoatUtil {
|
public interface BoatUtil {
|
||||||
TrackedData<String> HAS_CHEST = DataTracker.registerData(BoatEntity.class, TrackedDataHandlerRegistry.STRING);
|
TrackedData<String> HAS_CHEST = DataTracker.registerData(BoatEntity.class, TrackedDataHandlerRegistry.STRING);
|
||||||
|
|
||||||
BoatChestMode getChestMode();
|
ChestMode getChestMode();
|
||||||
|
|
||||||
Inventory getChestInventory();
|
Inventory getChestInventory();
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ public interface BoatUtil {
|
|||||||
return player.squaredDistanceTo(entity.getPos().getX(), entity.getPos().getY(), entity.getPos().getZ()) <= 64d;
|
return player.squaredDistanceTo(entity.getPos().getX(), entity.getPos().getY(), entity.getPos().getZ()) <= 64d;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BoatChestMode {
|
enum ChestMode {
|
||||||
ENDER_CHEST(Items.ENDER_CHEST, false),
|
ENDER_CHEST(Items.ENDER_CHEST, false),
|
||||||
CHEST(Items.CHEST, true),
|
CHEST(Items.CHEST, true),
|
||||||
TRAPPED_CHEST(Items.TRAPPED_CHEST, true),
|
TRAPPED_CHEST(Items.TRAPPED_CHEST, true),
|
||||||
@ -35,7 +35,7 @@ public interface BoatUtil {
|
|||||||
private final Item item;
|
private final Item item;
|
||||||
private final boolean hasItems;
|
private final boolean hasItems;
|
||||||
|
|
||||||
BoatChestMode(Item item, boolean hasItems) {
|
ChestMode(Item item, boolean hasItems) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.hasItems = hasItems;
|
this.hasItems = hasItems;
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ public interface BoatUtil {
|
|||||||
return hasItems;
|
return hasItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BoatChestMode valueOF(Item item) {
|
public static ChestMode valueOF(Item item) {
|
||||||
for (BoatChestMode mode : values()) {
|
for (ChestMode mode : values()) {
|
||||||
if (mode.getItem() == item) {
|
if (mode.getItem() == item) {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class EnderChestInventoryWrapper implements Inventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayerUse(PlayerEntity player) {
|
public boolean canPlayerUse(PlayerEntity player) {
|
||||||
return BoatUtil.canReachEntity(player, entity) && entity.isAlive() && ((BoatUtil) entity).getChestMode() == BoatUtil.BoatChestMode.ENDER_CHEST;
|
return BoatUtil.canReachEntity(player, entity) && entity.isAlive() && ((BoatUtil) entity).getChestMode() == BoatUtil.ChestMode.ENDER_CHEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user