Overhaul continues.
Updated build modes, determining blockstates. Everything compiles and runs.
This commit is contained in:
@@ -263,7 +263,7 @@ public class ClientEvents {
|
|||||||
public static boolean isKeybindDown(int keybindIndex) {
|
public static boolean isKeybindDown(int keybindIndex) {
|
||||||
return InputConstants.isKeyDown(
|
return InputConstants.isKeyDown(
|
||||||
Minecraft.getInstance().getWindow().getWindow(),
|
Minecraft.getInstance().getWindow().getWindow(),
|
||||||
keyBindings[2].getKey().getValue());
|
keyBindings[keybindIndex].getKey().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockHitResult getLookingAt(Player player) {
|
public static BlockHitResult getLookingAt(Player player) {
|
||||||
|
|||||||
@@ -22,14 +22,4 @@ public abstract class BaseBuildMode implements IBuildMode {
|
|||||||
clicks++;
|
clicks++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @Deprecated
|
|
||||||
public Direction getSideHit(Player player) {
|
|
||||||
return Direction.UP;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override @Deprecated
|
|
||||||
public Vec3 getHitVec(Player player) {
|
|
||||||
return new Vec3(0.5, 0.5, 0.5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,26 +10,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface IBuildMode {
|
public interface IBuildMode {
|
||||||
|
|
||||||
//Fired when a player selects a buildmode and when it needs to initializeMode
|
//Reset values here, start over
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
//Fired when a block would be placed
|
|
||||||
//Return a list of coordinates where you want to place blocks
|
|
||||||
@Deprecated
|
|
||||||
List<BlockPos> onRightClick(Player player, BlockPos blockPos, Direction sideHit, Vec3 hitVec, boolean skipRaytrace);
|
|
||||||
|
|
||||||
//Returns if we should place blocks now
|
//Returns if we should place blocks now
|
||||||
boolean onClick(List<BlockEntry> blocks);
|
boolean onClick(List<BlockEntry> blocks);
|
||||||
|
|
||||||
//Fired continuously for visualization purposes
|
|
||||||
@Deprecated
|
|
||||||
List<BlockPos> findCoordinates(Player player, BlockPos blockPos, boolean skipRaytrace);
|
|
||||||
|
|
||||||
void findCoordinates(List<BlockEntry> blocks);
|
void findCoordinates(List<BlockEntry> blocks);
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Direction getSideHit(Player player);
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Vec3 getHitVec(Player player);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +1,73 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode;
|
package nl.requios.effortlessbuilding.buildmode;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
||||||
protected Dictionary<UUID, BlockPos> secondPosTable = new Hashtable<>();
|
protected BlockEntry firstBlockEntry;
|
||||||
|
protected BlockEntry secondBlockEntry;
|
||||||
|
|
||||||
//Finds height after floor has been chosen in buildmodes with 3 clicks
|
//Finds height after floor has been chosen in buildmodes with 3 clicks
|
||||||
@Override
|
@Override
|
||||||
public void initialize(Player player) {
|
public void initialize() {
|
||||||
super.initialize(player);
|
super.initialize();
|
||||||
secondPosTable.put(player.getUUID(), BlockPos.ZERO);
|
firstBlockEntry = null;
|
||||||
|
secondBlockEntry = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> onRightClick(Player player, BlockPos blockPos, Direction sideHit, Vec3 hitVec, boolean skipRaytrace) {
|
public boolean onClick(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
super.onClick(blocks);
|
||||||
|
|
||||||
Dictionary<UUID, Integer> rightClickTable = player.level.isClientSide ? rightClickClientTable : rightClickServerTable;
|
|
||||||
int rightClickNr = rightClickTable.get(player.getUUID());
|
|
||||||
rightClickNr++;
|
|
||||||
rightClickTable.put(player.getUUID(), rightClickNr);
|
|
||||||
|
|
||||||
if (rightClickNr == 1) {
|
|
||||||
//If clicking in air, reset and try again
|
|
||||||
if (blockPos == null) {
|
|
||||||
rightClickTable.put(player.getUUID(), 0);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (clicks == 1) {
|
||||||
//First click, remember starting position
|
//First click, remember starting position
|
||||||
firstPosTable.put(player.getUUID(), blockPos);
|
|
||||||
sideHitTable.put(player.getUUID(), sideHit);
|
|
||||||
hitVecTable.put(player.getUUID(), hitVec);
|
|
||||||
//Keep list empty, dont place any blocks yet
|
|
||||||
} else if (rightClickNr == 2) {
|
|
||||||
//Second click, find other floor point
|
|
||||||
BlockPos firstPos = firstPosTable.get(player.getUUID());
|
|
||||||
BlockPos secondPos = findSecondPos(player, firstPos, true);
|
|
||||||
|
|
||||||
if (secondPos == null) {
|
//If clicking in air, reset and try again
|
||||||
rightClickTable.put(player.getUUID(), 1);
|
if (blocks.size() == 0) {
|
||||||
return list;
|
clicks = 0;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
secondPosTable.put(player.getUUID(), secondPos);
|
firstBlockEntry = blocks.get(0);
|
||||||
|
} else if (clicks == 2) {
|
||||||
|
//Second click, find second position
|
||||||
|
|
||||||
|
//If clicking in air, reset and try again
|
||||||
|
if (blocks.size() == 0) {
|
||||||
|
clicks = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var player = Minecraft.getInstance().player;
|
||||||
|
var secondPos = findSecondPos(player, firstBlockEntry.blockPos, true);
|
||||||
|
secondBlockEntry = new BlockEntry(secondPos);
|
||||||
} else {
|
} else {
|
||||||
//Third click, place diagonal wall with height
|
//Third click, place blocks
|
||||||
list = findCoordinates(player, blockPos, skipRaytrace);
|
clicks = 0;
|
||||||
rightClickTable.put(player.getUUID(), 0);
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> findCoordinates(Player player, BlockPos blockPos, boolean skipRaytrace) {
|
public void findCoordinates(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
if (clicks == 0) return;
|
||||||
Dictionary<UUID, Integer> rightClickTable = player.level.isClientSide ? rightClickClientTable : rightClickServerTable;
|
|
||||||
int rightClickNr = rightClickTable.get(player.getUUID());
|
|
||||||
|
|
||||||
if (rightClickNr == 0) {
|
if (clicks == 1) {
|
||||||
if (blockPos != null)
|
var player = Minecraft.getInstance().player;
|
||||||
list.add(blockPos);
|
var firstPos = firstBlockEntry.blockPos;
|
||||||
} else if (rightClickNr == 1) {
|
var secondPos = findSecondPos(player, firstBlockEntry.blockPos, true);
|
||||||
BlockPos firstPos = firstPosTable.get(player.getUUID());
|
if (secondPos == null) return;
|
||||||
|
|
||||||
BlockPos secondPos = findSecondPos(player, firstPos, true);
|
//Limit amount of blocks we can place per row
|
||||||
if (secondPos == null) return list;
|
|
||||||
|
|
||||||
//Limit amount of blocks you can place per row
|
|
||||||
int axisLimit = ReachHelper.getMaxBlocksPerAxis(player);
|
int axisLimit = ReachHelper.getMaxBlocksPerAxis(player);
|
||||||
|
|
||||||
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
||||||
@@ -90,15 +82,16 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
if (z2 - z1 >= axisLimit) z2 = z1 + axisLimit - 1;
|
if (z2 - z1 >= axisLimit) z2 = z1 + axisLimit - 1;
|
||||||
if (z1 - z2 >= axisLimit) z2 = z1 - axisLimit + 1;
|
if (z1 - z2 >= axisLimit) z2 = z1 - axisLimit + 1;
|
||||||
|
|
||||||
//Add diagonal line from first to second
|
blocks.clear();
|
||||||
list.addAll(getIntermediateBlocks(player, x1, y1, z1, x2, y2, z2));
|
for (BlockPos pos : getIntermediateBlocks(player, x1, y1, z1, x2, y2, z2)) {
|
||||||
|
blocks.add(new BlockEntry(pos));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
BlockPos firstPos = firstPosTable.get(player.getUUID());
|
var player = Minecraft.getInstance().player;
|
||||||
BlockPos secondPos = secondPosTable.get(player.getUUID());
|
BlockPos firstPos = firstBlockEntry.blockPos;
|
||||||
|
BlockPos secondPos = secondBlockEntry.blockPos;
|
||||||
BlockPos thirdPos = findThirdPos(player, firstPos, secondPos, skipRaytrace);
|
BlockPos thirdPos = findThirdPos(player, firstPos, secondPos, true);
|
||||||
if (thirdPos == null) return list;
|
if (thirdPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks you can place per row
|
//Limit amount of blocks you can place per row
|
||||||
int axisLimit = ReachHelper.getMaxBlocksPerAxis(player);
|
int axisLimit = ReachHelper.getMaxBlocksPerAxis(player);
|
||||||
@@ -122,11 +115,11 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
if (z3 - z1 >= axisLimit) z3 = z1 + axisLimit - 1;
|
if (z3 - z1 >= axisLimit) z3 = z1 + axisLimit - 1;
|
||||||
if (z1 - z3 >= axisLimit) z3 = z1 - axisLimit + 1;
|
if (z1 - z3 >= axisLimit) z3 = z1 - axisLimit + 1;
|
||||||
|
|
||||||
//Add diagonal line from first to third
|
blocks.clear();
|
||||||
list.addAll(getFinalBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3));
|
for (BlockPos pos : getFinalBlocks(player, x1, y1, z1, x2, y2, z2, x3, y3, z3)) {
|
||||||
|
blocks.add(new BlockEntry(pos));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockPos findHeight(Player player, BlockPos secondPos, boolean skipRaytrace) {
|
public static BlockPos findHeight(Player player, BlockPos secondPos, boolean skipRaytrace) {
|
||||||
@@ -172,7 +165,10 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
return new BlockPos(selected.lineBound);
|
return new BlockPos(selected.lineBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// protected abstract BlockEntry findSecondPos(List<BlockEntry> blocks);
|
||||||
|
|
||||||
//Finds the place of the second block pos
|
//Finds the place of the second block pos
|
||||||
|
// @Deprecated
|
||||||
protected abstract BlockPos findSecondPos(Player player, BlockPos firstPos, boolean skipRaytrace);
|
protected abstract BlockPos findSecondPos(Player player, BlockPos firstPos, boolean skipRaytrace);
|
||||||
|
|
||||||
//Finds the place of the third block pos
|
//Finds the place of the third block pos
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode;
|
package nl.requios.effortlessbuilding.buildmode;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -16,6 +18,12 @@ public abstract class TwoClicksBuildMode extends BaseBuildMode {
|
|||||||
|
|
||||||
protected BlockEntry firstBlockEntry;
|
protected BlockEntry firstBlockEntry;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
super.initialize();
|
||||||
|
firstBlockEntry = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(List<BlockEntry> blocks) {
|
public boolean onClick(List<BlockEntry> blocks) {
|
||||||
super.onClick(blocks);
|
super.onClick(blocks);
|
||||||
@@ -39,18 +47,13 @@ public abstract class TwoClicksBuildMode extends BaseBuildMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> findCoordinates(Player player, BlockPos blockPos, boolean skipRaytrace) {
|
public void findCoordinates(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
if (clicks == 0) return;
|
||||||
Dictionary<UUID, Integer> rightClickTable = player.level.isClientSide ? rightClickClientTable : rightClickServerTable;
|
|
||||||
int rightClickNr = rightClickTable.get(player.getUUID());
|
|
||||||
BlockPos firstPos = firstPosTable.get(player.getUUID());
|
|
||||||
|
|
||||||
if (rightClickNr == 0) {
|
var player = Minecraft.getInstance().player;
|
||||||
if (blockPos != null)
|
var firstPos = firstBlockEntry.blockPos;
|
||||||
list.add(blockPos);
|
var secondPos = findSecondPos(player, firstBlockEntry.blockPos, true);
|
||||||
} else {
|
if (secondPos == null) return;
|
||||||
BlockPos secondPos = findSecondPos(player, firstPos, skipRaytrace);
|
|
||||||
if (secondPos == null) return list;
|
|
||||||
|
|
||||||
//Limit amount of blocks we can place per row
|
//Limit amount of blocks we can place per row
|
||||||
int axisLimit = ReachHelper.getMaxBlocksPerAxis(player);
|
int axisLimit = ReachHelper.getMaxBlocksPerAxis(player);
|
||||||
@@ -67,10 +70,10 @@ public abstract class TwoClicksBuildMode extends BaseBuildMode {
|
|||||||
if (z2 - z1 >= axisLimit) z2 = z1 + axisLimit - 1;
|
if (z2 - z1 >= axisLimit) z2 = z1 + axisLimit - 1;
|
||||||
if (z1 - z2 >= axisLimit) z2 = z1 - axisLimit + 1;
|
if (z1 - z2 >= axisLimit) z2 = z1 - axisLimit + 1;
|
||||||
|
|
||||||
list.addAll(getAllBlocks(player, x1, y1, z1, x2, y2, z2));
|
blocks.clear();
|
||||||
|
for (BlockPos pos : getAllBlocks(player, x1, y1, z1, x2, y2, z2)) {
|
||||||
|
blocks.add(new BlockEntry(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Finds the place of the second block pos based on criteria (floor must be on same height as first click, wall on same plane etc)
|
//Finds the place of the second block pos based on criteria (floor must be on same height as first click, wall on same plane etc)
|
||||||
|
|||||||
@@ -5,37 +5,25 @@ import net.minecraft.core.Direction;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
|
||||||
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Disabled implements IBuildMode {
|
public class Disabled implements IBuildMode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(Player player) {
|
public void initialize() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> onRightClick(Player player, BlockPos blockPos, Direction sideHit, Vec3 hitVec, boolean skipRaytrace) {
|
public boolean onClick(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
return true;
|
||||||
if (blockPos != null) list.add(blockPos);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> findCoordinates(Player player, BlockPos blockPos, boolean skipRaytrace) {
|
public void findCoordinates(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
//Do nothing
|
||||||
if (blockPos != null) list.add(blockPos);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Direction getSideHit(Player player) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vec3 getHitVec(Player player) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,37 +5,25 @@ import net.minecraft.core.Direction;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
|
||||||
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Single implements IBuildMode {
|
public class Single implements IBuildMode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(Player player) {
|
public void initialize() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> onRightClick(Player player, BlockPos blockPos, Direction sideHit, Vec3 hitVec, boolean skipRaytrace) {
|
public boolean onClick(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
return true;
|
||||||
if (blockPos != null) list.add(blockPos);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> findCoordinates(Player player, BlockPos blockPos, boolean skipRaytrace) {
|
public void findCoordinates(List<BlockEntry> blocks) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
//Do nothing
|
||||||
if (blockPos != null) list.add(blockPos);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Direction getSideHit(Player player) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vec3 getHitVec(Player player) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,16 @@ public class CompatHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isItemBlockProxy(ItemStack stack) {
|
||||||
|
return isItemBlockProxy(stack, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the item given is a proxy for blocks. For now, we check for the randomizer bag,
|
// Check if the item given is a proxy for blocks. For now, we check for the randomizer bag,
|
||||||
// /dank/null, or plain old blocks.
|
// /dank/null, or plain old blocks.
|
||||||
public static boolean isItemBlockProxy(ItemStack stack) {
|
public static boolean isItemBlockProxy(ItemStack stack, boolean seeBlockItemsAsProxies) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if (item instanceof BlockItem)
|
if (item instanceof BlockItem)
|
||||||
return true;
|
return seeBlockItemsAsProxies;
|
||||||
return item instanceof AbstractRandomizerBagItem;
|
return item instanceof AbstractRandomizerBagItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class ServerPlaceBlocksMessage {
|
|||||||
public static ServerPlaceBlocksMessage decode(FriendlyByteBuf buf) {
|
public static ServerPlaceBlocksMessage decode(FriendlyByteBuf buf) {
|
||||||
ServerPlaceBlocksMessage message = new ServerPlaceBlocksMessage();
|
ServerPlaceBlocksMessage message = new ServerPlaceBlocksMessage();
|
||||||
message.blocks = buf.readList(BlockEntry::decode);
|
message.blocks = buf.readList(BlockEntry::decode);
|
||||||
return new ServerPlaceBlocksMessage();
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import nl.requios.effortlessbuilding.CommonConfig;
|
|||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||||
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.IBuildMode;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
|
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.ModifierSettings;
|
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.ModifierSettings;
|
||||||
@@ -71,148 +72,148 @@ public class BlockPreviews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void drawLookAtPreview(Player player, ModeSettings modeSettings, ModifierSettings modifierSettings, BlockPos startPos, Direction sideHit, Vec3 hitVec) {
|
public static void drawLookAtPreview(Player player, ModeSettings modeSettings, ModifierSettings modifierSettings, BlockPos startPos, Direction sideHit, Vec3 hitVec) {
|
||||||
if (!doShowBlockPreviews(modifierSettings, modeSettings, startPos)) return;
|
// if (!doShowBlockPreviews(modifierSettings, modeSettings, startPos)) return;
|
||||||
|
//
|
||||||
//Keep blockstate the same for every block in the buildmode
|
// //Keep blockstate the same for every block in the buildmode
|
||||||
//So dont rotate blocks when in the middle of placing wall etc.
|
// //So dont rotate blocks when in the middle of placing wall etc.
|
||||||
if (BuildModes.isActive(player)) {
|
// if (BuildModes.isActive(player)) {
|
||||||
IBuildMode buildModeInstance = modeSettings.getBuildMode().instance;
|
// IBuildMode buildModeInstance = modeSettings.getBuildMode().instance;
|
||||||
if (buildModeInstance.getSideHit(player) != null) sideHit = buildModeInstance.getSideHit(player);
|
// if (buildModeInstance.getSideHit(player) != null) sideHit = buildModeInstance.getSideHit(player);
|
||||||
if (buildModeInstance.getHitVec(player) != null) hitVec = buildModeInstance.getHitVec(player);
|
// if (buildModeInstance.getHitVec(player) != null) hitVec = buildModeInstance.getHitVec(player);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (sideHit == null) return;
|
// if (sideHit == null) return;
|
||||||
|
//
|
||||||
//Should be red?
|
// //Should be red?
|
||||||
boolean breaking = BuildModes.currentlyBreakingClient.get(player) != null && BuildModes.currentlyBreakingClient.get(player);
|
// boolean breaking = BuildModes.currentlyBreakingClient.get(player) != null && BuildModes.currentlyBreakingClient.get(player);
|
||||||
|
//
|
||||||
//get coordinates
|
// //get coordinates
|
||||||
List<BlockPos> startCoordinates = BuildModes.findCoordinates(player, startPos, breaking || modifierSettings.doQuickReplace());
|
// List<BlockPos> startCoordinates = BuildModes.findCoordinates(player, startPos, breaking || modifierSettings.doQuickReplace());
|
||||||
|
//
|
||||||
//Remember first and last point for the shader
|
// //Remember first and last point for the shader
|
||||||
BlockPos firstPos = BlockPos.ZERO, secondPos = BlockPos.ZERO;
|
// BlockPos firstPos = BlockPos.ZERO, secondPos = BlockPos.ZERO;
|
||||||
if (!startCoordinates.isEmpty()) {
|
// if (!startCoordinates.isEmpty()) {
|
||||||
firstPos = startCoordinates.get(0);
|
// firstPos = startCoordinates.get(0);
|
||||||
secondPos = startCoordinates.get(startCoordinates.size() - 1);
|
// secondPos = startCoordinates.get(startCoordinates.size() - 1);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//Limit number of blocks you can place
|
// //Limit number of blocks you can place
|
||||||
int limit = ReachHelper.getMaxBlocksPlacedAtOnce(player);
|
// int limit = ReachHelper.getMaxBlocksPlacedAtOnce(player);
|
||||||
if (startCoordinates.size() > limit) {
|
// if (startCoordinates.size() > limit) {
|
||||||
startCoordinates = startCoordinates.subList(0, limit);
|
// startCoordinates = startCoordinates.subList(0, limit);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
List<BlockPos> newCoordinates = BuildModifiers.findCoordinates(player, startCoordinates);
|
// List<BlockPos> newCoordinates = BuildModifiers.findCoordinates(player, startCoordinates);
|
||||||
|
//
|
||||||
sortOnDistanceToPlayer(newCoordinates, player);
|
// sortOnDistanceToPlayer(newCoordinates, player);
|
||||||
|
//
|
||||||
hitVec = new Vec3(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)),
|
// hitVec = new Vec3(Math.abs(hitVec.x - ((int) hitVec.x)), Math.abs(hitVec.y - ((int) hitVec.y)),
|
||||||
Math.abs(hitVec.z - ((int) hitVec.z)));
|
// Math.abs(hitVec.z - ((int) hitVec.z)));
|
||||||
|
//
|
||||||
//Get blockstates
|
// //Get blockstates
|
||||||
List<ItemStack> itemStacks = new ArrayList<>();
|
// List<ItemStack> itemStacks = new ArrayList<>();
|
||||||
List<BlockState> blockStates = new ArrayList<>();
|
// List<BlockState> blockStates = new ArrayList<>();
|
||||||
if (breaking) {
|
// if (breaking) {
|
||||||
//Find blockstate of world
|
// //Find blockstate of world
|
||||||
for (BlockPos coordinate : newCoordinates) {
|
// for (BlockPos coordinate : newCoordinates) {
|
||||||
blockStates.add(player.level.getBlockState(coordinate));
|
// blockStates.add(player.level.getBlockState(coordinate));
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
blockStates = BuildModifiers.findBlockStates(player, startCoordinates, hitVec, sideHit, itemStacks);
|
// blockStates = BuildModifiers.findBlockStates(player, startCoordinates, hitVec, sideHit, itemStacks);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
//Check if they are different from previous
|
// //Check if they are different from previous
|
||||||
//TODO fix triggering when moving player
|
// //TODO fix triggering when moving player
|
||||||
if (!BuildModifiers.compareCoordinates(previousCoordinates, newCoordinates)) {
|
// if (!BuildModifiers.compareCoordinates(previousCoordinates, newCoordinates)) {
|
||||||
previousCoordinates = newCoordinates;
|
// previousCoordinates = newCoordinates;
|
||||||
//remember the rest for placed blocks
|
// //remember the rest for placed blocks
|
||||||
previousBlockStates = blockStates;
|
// previousBlockStates = blockStates;
|
||||||
previousItemStacks = itemStacks;
|
// previousItemStacks = itemStacks;
|
||||||
previousFirstPos = firstPos;
|
// previousFirstPos = firstPos;
|
||||||
previousSecondPos = secondPos;
|
// previousSecondPos = secondPos;
|
||||||
|
//
|
||||||
//if so, renew randomness of randomizer bag
|
// //if so, renew randomness of randomizer bag
|
||||||
AbstractRandomizerBagItem.renewRandomness();
|
// AbstractRandomizerBagItem.renewRandomness();
|
||||||
//and play sound (max once every tick)
|
// //and play sound (max once every tick)
|
||||||
if (newCoordinates.size() > 1 && blockStates.size() > 1 && soundTime < ClientEvents.ticksInGame - 0) {
|
// if (newCoordinates.size() > 1 && blockStates.size() > 1 && soundTime < ClientEvents.ticksInGame - 0) {
|
||||||
soundTime = ClientEvents.ticksInGame;
|
// soundTime = ClientEvents.ticksInGame;
|
||||||
|
//
|
||||||
if (blockStates.get(0) != null) {
|
// if (blockStates.get(0) != null) {
|
||||||
SoundType soundType = blockStates.get(0).getBlock().getSoundType(blockStates.get(0), player.level,
|
// SoundType soundType = blockStates.get(0).getBlock().getSoundType(blockStates.get(0), player.level,
|
||||||
newCoordinates.get(0), player);
|
// newCoordinates.get(0), player);
|
||||||
player.level.playSound(player, player.blockPosition(), breaking ? soundType.getBreakSound() : soundType.getPlaceSound(),
|
// player.level.playSound(player, player.blockPosition(), breaking ? soundType.getBreakSound() : soundType.getPlaceSound(),
|
||||||
SoundSource.BLOCKS, 0.3f, 0.8f);
|
// SoundSource.BLOCKS, 0.3f, 0.8f);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (blockStates.size() == 0 || newCoordinates.size() != blockStates.size()) return;
|
// if (blockStates.size() == 0 || newCoordinates.size() != blockStates.size()) return;
|
||||||
|
//
|
||||||
int blockCount;
|
// int blockCount;
|
||||||
|
//
|
||||||
Object outlineID = firstPos;
|
// Object outlineID = firstPos;
|
||||||
//Dont fade out the outline if we are still determining where to place
|
// //Dont fade out the outline if we are still determining where to place
|
||||||
//Every outline with same ID will not fade out (because it gets replaced)
|
// //Every outline with same ID will not fade out (because it gets replaced)
|
||||||
if (newCoordinates.size() == 1 || BuildModifiers.isEnabled(modifierSettings, firstPos)) outlineID = "single";
|
// if (newCoordinates.size() == 1 || BuildModifiers.isEnabled(modifierSettings, firstPos)) outlineID = "single";
|
||||||
|
//
|
||||||
if (!breaking) {
|
// if (!breaking) {
|
||||||
//Use fancy shader if config allows, otherwise outlines
|
// //Use fancy shader if config allows, otherwise outlines
|
||||||
if (ClientConfig.visuals.showBlockPreviews.get() && newCoordinates.size() < ClientConfig.visuals.maxBlockPreviews.get()) {
|
// if (ClientConfig.visuals.showBlockPreviews.get() && newCoordinates.size() < ClientConfig.visuals.maxBlockPreviews.get()) {
|
||||||
blockCount = renderBlockPreviews(player, modifierSettings, newCoordinates, blockStates, itemStacks, 0f, firstPos, secondPos, !breaking, breaking);
|
// blockCount = renderBlockPreviews(player, modifierSettings, newCoordinates, blockStates, itemStacks, 0f, firstPos, secondPos, !breaking, breaking);
|
||||||
|
//
|
||||||
CreateClient.OUTLINER.showCluster(outlineID, newCoordinates)
|
// CreateClient.OUTLINER.showCluster(outlineID, newCoordinates)
|
||||||
.withFaceTexture(AllSpecialTextures.CHECKERED)
|
// .withFaceTexture(AllSpecialTextures.CHECKERED)
|
||||||
.disableNormals()
|
// .disableNormals()
|
||||||
.lineWidth(1 / 32f)
|
// .lineWidth(1 / 32f)
|
||||||
.colored(new Color(1f, 1f, 1f, 1f));
|
// .colored(new Color(1f, 1f, 1f, 1f));
|
||||||
} else {
|
// } else {
|
||||||
//Thicker outline without block previews
|
// //Thicker outline without block previews
|
||||||
CreateClient.OUTLINER.showCluster(outlineID, newCoordinates)
|
// CreateClient.OUTLINER.showCluster(outlineID, newCoordinates)
|
||||||
.withFaceTexture(AllSpecialTextures.HIGHLIGHT_CHECKERED)
|
// .withFaceTexture(AllSpecialTextures.HIGHLIGHT_CHECKERED)
|
||||||
.disableNormals()
|
// .disableNormals()
|
||||||
.lineWidth(1 / 16f)
|
// .lineWidth(1 / 16f)
|
||||||
.colored(new Color(1f, 1f, 1f, 1f));
|
// .colored(new Color(1f, 1f, 1f, 1f));
|
||||||
|
//
|
||||||
blockCount = newCoordinates.size();
|
// blockCount = newCoordinates.size();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
} else {
|
// } else {
|
||||||
//Breaking
|
// //Breaking
|
||||||
CreateClient.OUTLINER.showCluster(outlineID, newCoordinates)
|
// CreateClient.OUTLINER.showCluster(outlineID, newCoordinates)
|
||||||
.withFaceTexture(AllSpecialTextures.THIN_CHECKERED)
|
// .withFaceTexture(AllSpecialTextures.THIN_CHECKERED)
|
||||||
.disableNormals()
|
// .disableNormals()
|
||||||
.lineWidth(1 / 16f)
|
// .lineWidth(1 / 16f)
|
||||||
.colored(new Color(0.8f, 0.1f, 0.1f, 1f));
|
// .colored(new Color(0.8f, 0.1f, 0.1f, 1f));
|
||||||
blockCount = newCoordinates.size();
|
// blockCount = newCoordinates.size();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//Display block count and dimensions in actionbar
|
// //Display block count and dimensions in actionbar
|
||||||
if (BuildModes.isActive(player)) {
|
// if (BuildModes.isActive(player)) {
|
||||||
|
//
|
||||||
//Find min and max values (not simply firstPos and secondPos because that doesn't work with circles)
|
// //Find min and max values (not simply firstPos and secondPos because that doesn't work with circles)
|
||||||
int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
|
// int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
|
||||||
int minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE;
|
// int minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE;
|
||||||
int minZ = Integer.MAX_VALUE, maxZ = Integer.MIN_VALUE;
|
// int minZ = Integer.MAX_VALUE, maxZ = Integer.MIN_VALUE;
|
||||||
for (BlockPos pos : startCoordinates) {
|
// for (BlockPos pos : startCoordinates) {
|
||||||
if (pos.getX() < minX) minX = pos.getX();
|
// if (pos.getX() < minX) minX = pos.getX();
|
||||||
if (pos.getX() > maxX) maxX = pos.getX();
|
// if (pos.getX() > maxX) maxX = pos.getX();
|
||||||
if (pos.getY() < minY) minY = pos.getY();
|
// if (pos.getY() < minY) minY = pos.getY();
|
||||||
if (pos.getY() > maxY) maxY = pos.getY();
|
// if (pos.getY() > maxY) maxY = pos.getY();
|
||||||
if (pos.getZ() < minZ) minZ = pos.getZ();
|
// if (pos.getZ() < minZ) minZ = pos.getZ();
|
||||||
if (pos.getZ() > maxZ) maxZ = pos.getZ();
|
// if (pos.getZ() > maxZ) maxZ = pos.getZ();
|
||||||
}
|
// }
|
||||||
BlockPos dim = new BlockPos(maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1);
|
// BlockPos dim = new BlockPos(maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1);
|
||||||
|
//
|
||||||
String dimensions = "(";
|
// String dimensions = "(";
|
||||||
if (dim.getX() > 1) dimensions += dim.getX() + "x";
|
// if (dim.getX() > 1) dimensions += dim.getX() + "x";
|
||||||
if (dim.getZ() > 1) dimensions += dim.getZ() + "x";
|
// if (dim.getZ() > 1) dimensions += dim.getZ() + "x";
|
||||||
if (dim.getY() > 1) dimensions += dim.getY() + "x";
|
// if (dim.getY() > 1) dimensions += dim.getY() + "x";
|
||||||
dimensions = dimensions.substring(0, dimensions.length() - 1);
|
// dimensions = dimensions.substring(0, dimensions.length() - 1);
|
||||||
if (dimensions.length() > 1) dimensions += ")";
|
// if (dimensions.length() > 1) dimensions += ")";
|
||||||
|
//
|
||||||
EffortlessBuilding.log(player, blockCount + " blocks " + dimensions, true);
|
// EffortlessBuilding.log(player, blockCount + " blocks " + dimensions, true);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawOutlinesIfNoBlockInHand(Player player, HitResult lookingAt) {
|
public static void drawOutlinesIfNoBlockInHand(Player player, HitResult lookingAt) {
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package nl.requios.effortlessbuilding.systems;
|
|||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.SoundType;
|
import net.minecraft.world.level.block.SoundType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
@@ -45,20 +49,29 @@ public class BuilderChain {
|
|||||||
|
|
||||||
|
|
||||||
public void onRightClick() {
|
public void onRightClick() {
|
||||||
|
var player = Minecraft.getInstance().player;
|
||||||
|
|
||||||
if (state == State.BREAKING) {
|
if (state == State.BREAKING) {
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check if we have a BlockItem in hand
|
||||||
|
var itemStack = player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||||
|
boolean blockInHand = CompatHelper.isItemBlockProxy(itemStack);
|
||||||
|
if (!blockInHand) {
|
||||||
|
if (state == State.PLACING) cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (state == State.IDLE) {
|
if (state == State.IDLE) {
|
||||||
state = State.PLACING;
|
state = State.PLACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
var player = Minecraft.getInstance().player;
|
|
||||||
var buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
|
var buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
|
||||||
|
|
||||||
//Find out if we should place blocks now
|
//Find out if we should place blocks now
|
||||||
if (buildMode.instance.onClick()) {
|
if (buildMode.instance.onClick(blocks)) {
|
||||||
state = State.IDLE;
|
state = State.IDLE;
|
||||||
PacketHandler.INSTANCE.sendToServer(new ServerPlaceBlocksMessage(blocks));
|
PacketHandler.INSTANCE.sendToServer(new ServerPlaceBlocksMessage(blocks));
|
||||||
}
|
}
|
||||||
@@ -76,12 +89,15 @@ public class BuilderChain {
|
|||||||
|
|
||||||
if (state == State.IDLE){
|
if (state == State.IDLE){
|
||||||
state = State.BREAKING;
|
state = State.BREAKING;
|
||||||
|
|
||||||
|
//Recalculate block positions, because start position has changed
|
||||||
|
onTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
|
var buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
|
||||||
|
|
||||||
//Find out if we should break blocks now
|
//Find out if we should break blocks now
|
||||||
if (buildMode.instance.onClick()) {
|
if (buildMode.instance.onClick(blocks)) {
|
||||||
state = State.IDLE;
|
state = State.IDLE;
|
||||||
PacketHandler.INSTANCE.sendToServer(new ServerPlaceBlocksMessage(blocks));
|
PacketHandler.INSTANCE.sendToServer(new ServerPlaceBlocksMessage(blocks));
|
||||||
}
|
}
|
||||||
@@ -115,8 +131,23 @@ public class BuilderChain {
|
|||||||
EffortlessBuildingClient.BUILD_MODES.findCoordinates(blocks, player, buildMode);
|
EffortlessBuildingClient.BUILD_MODES.findCoordinates(blocks, player, buildMode);
|
||||||
EffortlessBuildingClient.BUILD_MODIFIERS.findCoordinates(blocks, player, modifierSettings);
|
EffortlessBuildingClient.BUILD_MODIFIERS.findCoordinates(blocks, player, modifierSettings);
|
||||||
|
|
||||||
if (state == State.PLACING) {
|
if (blockInHand && state != State.BREAKING) {
|
||||||
//TODO find block states
|
//find block states
|
||||||
|
|
||||||
|
if (itemStack.getItem() instanceof BlockItem) {
|
||||||
|
|
||||||
|
for (BlockEntry blockEntry : blocks) {
|
||||||
|
blockEntry.blockState = getBlockState(player, InteractionHand.MAIN_HAND, itemStack, blockEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (CompatHelper.isItemBlockProxy(itemStack, false)) {
|
||||||
|
|
||||||
|
for (BlockEntry blockEntry : blocks) {
|
||||||
|
ItemStack itemBlockStack = CompatHelper.getItemBlockFromStack(itemStack);
|
||||||
|
if (itemBlockStack == null || itemBlockStack.isEmpty()) continue;
|
||||||
|
blockEntry.blockState = getBlockState(player, InteractionHand.MAIN_HAND, itemBlockStack, blockEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +167,7 @@ public class BuilderChain {
|
|||||||
int maxReach = ReachHelper.getMaxReach(player);
|
int maxReach = ReachHelper.getMaxReach(player);
|
||||||
if (player.blockPosition().distSqr(startPos) > maxReach * maxReach) return null;
|
if (player.blockPosition().distSqr(startPos) > maxReach * maxReach) return null;
|
||||||
|
|
||||||
|
if (state != State.BREAKING) {
|
||||||
//Offset in direction of sidehit if not quickreplace and not replaceable
|
//Offset in direction of sidehit if not quickreplace and not replaceable
|
||||||
boolean replaceable = player.level.getBlockState(startPos).getMaterial().isReplaceable();
|
boolean replaceable = player.level.getBlockState(startPos).getMaterial().isReplaceable();
|
||||||
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos);
|
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos);
|
||||||
@@ -147,6 +179,7 @@ public class BuilderChain {
|
|||||||
if (doingQuickReplace && replaceable) {
|
if (doingQuickReplace && replaceable) {
|
||||||
startPos = startPos.below();
|
startPos = startPos.below();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var blockEntry = new BlockEntry(startPos);
|
var blockEntry = new BlockEntry(startPos);
|
||||||
|
|
||||||
@@ -161,6 +194,13 @@ public class BuilderChain {
|
|||||||
return blockEntry;
|
return blockEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockState getBlockState(Player player, InteractionHand hand, ItemStack blockItemStack, BlockEntry blockEntry) {
|
||||||
|
Block block = Block.byItem(blockItemStack.getItem());
|
||||||
|
//TODO convert lookingAt hitvec to relative hitvec
|
||||||
|
var blockHitResult = new BlockHitResult(Vec3.ZERO, Direction.UP, blockEntry.blockPos, false);
|
||||||
|
return block.getStateForPlacement(new BlockPlaceContext(player, hand, blockItemStack, blockHitResult));
|
||||||
|
}
|
||||||
|
|
||||||
private void playPlacingSoundIfFurtherThanNormal(Player player, Vec3 location, BlockItem blockItem) {
|
private void playPlacingSoundIfFurtherThanNormal(Player player, Vec3 location, BlockItem blockItem) {
|
||||||
|
|
||||||
if ((location.subtract(player.getEyePosition(1f))).lengthSqr() > 25f) {
|
if ((location.subtract(player.getEyePosition(1f))).lengthSqr() > 25f) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -15,6 +16,8 @@ import java.util.List;
|
|||||||
public class ServerBlockPlacer {
|
public class ServerBlockPlacer {
|
||||||
|
|
||||||
public void placeBlocks(Player player, List<BlockEntry> blocks) {
|
public void placeBlocks(Player player, List<BlockEntry> blocks) {
|
||||||
|
EffortlessBuilding.log(player, "Placing " + blocks.size() + " blocks");
|
||||||
|
|
||||||
for (BlockEntry block : blocks) {
|
for (BlockEntry block : blocks) {
|
||||||
placeBlock(player, block);
|
placeBlock(player, block);
|
||||||
}
|
}
|
||||||
@@ -26,6 +29,7 @@ public class ServerBlockPlacer {
|
|||||||
|
|
||||||
if (block.meansBreakBlock()) {
|
if (block.meansBreakBlock()) {
|
||||||
breakBlock(player, block.blockPos);
|
breakBlock(player, block.blockPos);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean success = world.setBlock(block.blockPos, block.blockState, 3);
|
boolean success = world.setBlock(block.blockPos, block.blockState, 3);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.block.Rotation;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
@@ -13,12 +14,18 @@ public class BlockEntry {
|
|||||||
public boolean mirrorX;
|
public boolean mirrorX;
|
||||||
public boolean mirrorY;
|
public boolean mirrorY;
|
||||||
public boolean mirrorZ;
|
public boolean mirrorZ;
|
||||||
|
public Rotation rotation;
|
||||||
public BlockState blockState;
|
public BlockState blockState;
|
||||||
|
public ItemStack itemStack = ItemStack.EMPTY;
|
||||||
|
|
||||||
public BlockEntry(BlockPos blockPos) {
|
public BlockEntry(BlockPos blockPos) {
|
||||||
this.blockPos = blockPos;
|
this.blockPos = blockPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean meansBreakBlock() {
|
||||||
|
return blockState == null || blockState.isAir();
|
||||||
|
}
|
||||||
|
|
||||||
public BitSet getMirrorBitSet() {
|
public BitSet getMirrorBitSet() {
|
||||||
BitSet bitSet = new BitSet(3);
|
BitSet bitSet = new BitSet(3);
|
||||||
bitSet.set(0, mirrorX);
|
bitSet.set(0, mirrorX);
|
||||||
@@ -33,20 +40,20 @@ public class BlockEntry {
|
|||||||
mirrorZ = bitSet.get(2);
|
mirrorZ = bitSet.get(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean meansBreakBlock() {
|
|
||||||
return blockState == null || blockState.isAir();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void encode(FriendlyByteBuf buf, BlockEntry block) {
|
public static void encode(FriendlyByteBuf buf, BlockEntry block) {
|
||||||
buf.writeBlockPos(block.blockPos);
|
buf.writeBlockPos(block.blockPos);
|
||||||
buf.writeBitSet(block.getMirrorBitSet());
|
buf.writeNullable(block.blockState, (buffer, blockState) -> buffer.writeNbt(NbtUtils.writeBlockState(blockState)));
|
||||||
buf.writeNbt(NbtUtils.writeBlockState(block.blockState));
|
buf.writeItem(block.itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockEntry decode(FriendlyByteBuf buf) {
|
public static BlockEntry decode(FriendlyByteBuf buf) {
|
||||||
BlockEntry block = new BlockEntry(buf.readBlockPos());
|
BlockEntry block = new BlockEntry(buf.readBlockPos());
|
||||||
block.setMirrorBitSet(buf.readBitSet());
|
block.blockState = buf.readNullable(buffer -> {
|
||||||
block.blockState = NbtUtils.readBlockState(buf.readNbt());
|
var nbt = buf.readNbt();
|
||||||
|
if (nbt == null) return null;
|
||||||
|
return NbtUtils.readBlockState(nbt);
|
||||||
|
});
|
||||||
|
block.itemStack = buf.readItem();
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user