Skip to content

Commit

Permalink
Merge pull request #25 from Theta-Dev/update_1.5
Browse files Browse the repository at this point in the history
Update 1.5 -> 1.16.1
  • Loading branch information
Theta-Dev authored Sep 29, 2020
2 parents 3aee962 + b848742 commit c16d1d2
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 199 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mcp_mappings=20200723-1.16.1
botania=1.16-398

version_major=1
version_minor=4
version_minor=5
6 changes: 3 additions & 3 deletions src/main/java/thetadev/constructionwand/ConstructionWand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import thetadev.constructionwand.containers.ContainerManager;
import thetadev.constructionwand.containers.ContainerRegistrar;
import thetadev.constructionwand.items.ModItems;
import thetadev.constructionwand.job.JobHistory;
import thetadev.constructionwand.job.UndoHistory;
import thetadev.constructionwand.network.PacketQueryUndo;
import thetadev.constructionwand.network.PacketUndoBlocks;
import thetadev.constructionwand.network.PacketWandOption;
Expand All @@ -36,14 +36,14 @@ public class ConstructionWand
public SimpleChannel HANDLER;

public ContainerManager containerManager;
public JobHistory jobHistory;
public UndoHistory undoHistory;
public RenderBlockPreview renderBlockPreview;

public ConstructionWand() {
instance = this;

containerManager = new ContainerManager();
jobHistory = new JobHistory();
undoHistory = new UndoHistory();

// Register setup methods for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class CommonEvents
public static void logOut(PlayerEvent.PlayerLoggedOutEvent e) {
PlayerEntity player = e.getPlayer();
if(player.getEntityWorld().isRemote) return;
ConstructionWand.instance.jobHistory.removePlayer(player);
ConstructionWand.instance.undoHistory.removePlayer(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ public class ConfigClient
{
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();

public static final ForgeConfigSpec.BooleanValue SHIFTCTRL;
public static final ForgeConfigSpec.BooleanValue SHIFTCTRL_MODE;
public static final ForgeConfigSpec.BooleanValue SHIFTCTRL_GUI;

static {
BUILDER.push("keys");
BUILDER.comment("Press SHIFT+CTRL instead of SHIFT for changing wand mode/direction lock");
SHIFTCTRL = BUILDER.define("ShiftCtrl", false);
SHIFTCTRL_MODE = BUILDER.define("ShiftCtrl", false);
BUILDER.comment("Press SHIFT+CTRL instead of SHIFT for opening wand GUI");
SHIFTCTRL_GUI = BUILDER.define("ShiftCtrlGUI", false);
BUILDER.pop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ConfigServer
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();

public static final ForgeConfigSpec.IntValue LIMIT_CREATIVE;
public static final ForgeConfigSpec.IntValue MAX_RANGE;
public static final ForgeConfigSpec.IntValue UNDO_HISTORY;
public static final ForgeConfigSpec.BooleanValue ANGEL_FALLING;

Expand Down Expand Up @@ -80,6 +81,8 @@ public int getAngel() {
BUILDER.push("misc");
BUILDER.comment("Block limit for Infinity Wand used in creative mode");
LIMIT_CREATIVE = BUILDER.defineInRange("InfinityWandCreative", 2048, 1, Integer.MAX_VALUE);
BUILDER.comment("Maximum placement range (0: unlimited). Affects all wands and is meant for lag prevention, not game balancing.");
MAX_RANGE = BUILDER.defineInRange("MaxRange", 256, 0, Integer.MAX_VALUE);
BUILDER.comment("Number of operations that can be undone");
UNDO_HISTORY = BUILDER.defineInRange("UndoHistory", 3, 0, Integer.MAX_VALUE);
BUILDER.comment("Place blocks below you while falling > 10 blocks with angel mode (Can be used to save you from drops/the void)");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/thetadev/constructionwand/basics/WandUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ public static List<ItemStack> getFullInv(PlayerEntity player) {
inventory.addAll(player.inventory.mainInventory);
return inventory;
}

public static int maxRange(BlockPos p1, BlockPos p2) {
return Math.max(Math.abs(p1.getX() - p2.getX()), Math.abs(p1.getZ() - p2.getZ()));
}
}
11 changes: 11 additions & 0 deletions src/main/java/thetadev/constructionwand/basics/pool/IPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package thetadev.constructionwand.basics.pool;

import javax.annotation.Nullable;

public interface IPool<T>
{
void add(T element);
@Nullable
T draw();
void reset();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package thetadev.constructionwand.basics.pool;

import javax.annotation.Nullable;
import java.util.ArrayList;

public class OrderedPool<T> implements IPool<T>
{
private final ArrayList<T> elements;
private int index;

public OrderedPool() {
elements = new ArrayList<>();
reset();
}

@Override
public void add(T element) {
elements.add(element);
}

@Nullable
@Override
public T draw() {
if(index >= elements.size()) return null;
T e = elements.get(index);
index++;
return e;
}

@Override
public void reset() {
index = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package thetadev.constructionwand.basics.pool;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;

public class RandomPool<T> implements IPool<T>
{
private final Random rng;
private final HashMap<T, Integer> elements;
private HashSet<T> pool;

public RandomPool(Random rng) {
this.rng = rng;
elements = new HashMap<>();
reset();
}

@Override
public void add(T element) {
addWithWeight(element, 1);
}

public void addWithWeight(T element, int weight) {
if(weight < 1) return;
elements.merge(element, weight, Integer::sum);
pool.add(element);
}

@Nullable
@Override
public T draw() {
int allWeights = pool.stream().reduce(0, (partialRes, e) -> partialRes + elements.get(e), Integer::sum);
if(allWeights < 1) return null;

int random = rng.nextInt(allWeights);
int accWeight = 0;

for(T e : pool) {
accWeight += elements.get(e);
if(random < accWeight) {
pool.remove(e);
return e;
}
}
return null;
}

@Override
public void reset() {
pool = new HashSet<>(elements.keySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void MouseScrollEvent(InputEvent.MouseScrollEvent event) {
PlayerEntity player = Minecraft.getInstance().player;
double scroll = event.getScrollDelta();

if(player == null || !player.isSneaking() || (!Screen.hasControlDown() && ConfigClient.SHIFTCTRL.get()) || scroll == 0) return;
if(player == null || !player.isSneaking() || (!Screen.hasControlDown() && ConfigClient.SHIFTCTRL_MODE.get()) || scroll == 0) return;

ItemStack wand = WandUtil.holdingWand(player);
if(wand == null) return;
Expand All @@ -59,7 +59,7 @@ public static void MouseScrollEvent(InputEvent.MouseScrollEvent event) {
public static void onLeftClickEmpty(PlayerInteractEvent.LeftClickEmpty event) {
PlayerEntity player = event.getPlayer();

if(player == null || !player.isSneaking() || (!Screen.hasControlDown() && ConfigClient.SHIFTCTRL.get())) return;
if(player == null || !player.isSneaking() || (!Screen.hasControlDown() && ConfigClient.SHIFTCTRL_MODE.get())) return;

ItemStack wand = event.getItemStack();
if(!(wand.getItem() instanceof ItemWand)) return;
Expand All @@ -73,7 +73,7 @@ public static void onLeftClickEmpty(PlayerInteractEvent.LeftClickEmpty event) {
@SubscribeEvent
public static void onRightClickItem(PlayerInteractEvent.RightClickItem event) {
PlayerEntity player = event.getPlayer();
if(player == null || !player.isSneaking()) return;
if(player == null || !player.isSneaking() || (!Screen.hasControlDown() && ConfigClient.SHIFTCTRL_GUI.get())) return;

ItemStack wand = event.getItemStack();
if(!(wand.getItem() instanceof ItemWand)) return;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/thetadev/constructionwand/items/ItemWand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package thetadev.constructionwand.items;

import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -47,11 +46,8 @@ public ActionResultType onItemUse(ItemUseContext context)

ItemStack stack = player.getHeldItem(hand);

if(player.isSneaking() && ConstructionWand.instance.jobHistory.isUndoActive(player)) {
WandJob job = ConstructionWand.instance.jobHistory.getForUndo(player, world, context.getPos());
if(job == null) return ActionResultType.FAIL;
//ConstructionWand.LOGGER.debug("Starting Undo");
return job.undo() ? ActionResultType.SUCCESS : ActionResultType.FAIL;
if(player.isSneaking() && ConstructionWand.instance.undoHistory.isUndoActive(player)) {
return ConstructionWand.instance.undoHistory.undo(player, world, context.getPos()) ? ActionResultType.SUCCESS : ActionResultType.FAIL;
}
else {
WandJob job = WandJob.getJob(player, world, new BlockRayTraceResult(context.getHitVec(), context.getFace(), context.getPos(), false), stack);
Expand Down
98 changes: 0 additions & 98 deletions src/main/java/thetadev/constructionwand/job/JobHistory.java

This file was deleted.

Loading

0 comments on commit c16d1d2

Please sign in to comment.