Skip to content

Commit

Permalink
Made paint brush and bucket go in reverse when sneaking
Browse files Browse the repository at this point in the history
Visually fixes #45
  • Loading branch information
TechPizzaDev committed Aug 8, 2023
1 parent 9635b10 commit 9fa596b
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public AC_BlockColor(int var1, int var2, Material var3) {

@Override
public int getColorMultiplier(BlockView view, int x, int y, int z) {
int meta = this.getColorMetaData(view, x, y, z);
int meta = this.getColorMeta(view, x, y, z);
if (meta == 1) {
meta = 16775065;
} else if (meta == 2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.adventurecraft.awakening.common;

import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.material.Material;
import net.minecraft.world.BlockView;

public abstract class AC_BlockColorWithEntity extends BlockWithEntity implements AC_IBlockColor {

protected AC_BlockColorWithEntity(int i, int j, Material arg) {
super(i, j, arg);
}

@Override
public int getColorMultiplier(BlockView view, int x, int y, int z) {
int meta = this.getColorMeta(view, x, y, z);
if (meta == 1) {
meta = 16775065;
} else if (meta == 2) {
meta = 16767663;
} else if (meta == 3) {
meta = 10736540;
} else if (meta == 4) {
meta = 9755639;
} else if (meta == 5) {
meta = 8880573;
} else if (meta == 6) {
meta = 15539236;
} else {
meta = defaultColor;
}
return meta;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,63 @@
import net.minecraft.world.World;

public class AC_BlockLadderSubtypes extends LadderBlock implements AC_IBlockColor {

protected AC_BlockLadderSubtypes(int var1, int var2) {
super(var1, var2);
}

@Override
public int getTextureForSide(int var1, int var2) {
var2 /= 4;
return this.texture + var2;
public int getTextureForSide(int var1, int meta) {
meta /= 4;
return this.texture + meta;
}

@Override
public void onBlockPlaced(World world, int x, int y, int z, int side) {
int var6 = world.getBlockMeta(x, y, z);
int var7 = 0;
if (var7 == 0 && ExLadderBlock.isLadderID(world.getBlockId(x, y - 1, z))) {
var7 = world.getBlockMeta(x, y - 1, z) % 4 + 2;
int coreMeta = world.getBlockMeta(x, y, z);
int meta = 0;
if (meta == 0 && ExLadderBlock.isLadderID(world.getBlockId(x, y - 1, z))) {
meta = world.getBlockMeta(x, y - 1, z) % 4 + 2;
}

if (var7 == 0 && ExLadderBlock.isLadderID(world.getBlockId(x, y + 1, z))) {
var7 = world.getBlockMeta(x, y + 1, z) % 4 + 2;
if (meta == 0 && ExLadderBlock.isLadderID(world.getBlockId(x, y + 1, z))) {
meta = world.getBlockMeta(x, y + 1, z) % 4 + 2;
}

if ((var7 == 0 || side == 2) && world.method_1783(x, y, z + 1)) {
var7 = 2;
if ((meta == 0 || side == 2) && world.method_1783(x, y, z + 1)) {
meta = 2;
}

if ((var7 == 0 || side == 3) && world.method_1783(x, y, z - 1)) {
var7 = 3;
if ((meta == 0 || side == 3) && world.method_1783(x, y, z - 1)) {
meta = 3;
}

if ((var7 == 0 || side == 4) && world.method_1783(x + 1, y, z)) {
var7 = 4;
if ((meta == 0 || side == 4) && world.method_1783(x + 1, y, z)) {
meta = 4;
}

if ((var7 == 0 || side == 5) && world.method_1783(x - 1, y, z)) {
var7 = 5;
if ((meta == 0 || side == 5) && world.method_1783(x - 1, y, z)) {
meta = 5;
}

var6 += Math.max(var7 - 2, 0) % 4;
world.setBlockMeta(x, y, z, var6);
coreMeta += Math.max(meta - 2, 0) % 4;
world.setBlockMeta(x, y, z, coreMeta);
}

@Override
public void onAdjacentBlockUpdate(World world, int x, int y, int z, int id) {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int var5 = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (var5 + 4) % 16);
public int getMaxColorMeta() {
return 4;
}

@Override
public void incrementColor(World world, int x, int y, int z, int amount) {
int meta = this.getColorMeta(world, x, y, z);
int maxMeta = this.getMaxColorMeta();
int clampedMeta = Integer.remainderUnsigned(meta + amount * 4, maxMeta * 4);
world.setBlockMeta(x, y, z, clampedMeta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public int getRenderType() {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int meta = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (meta + 1) % ExBlock.subTypes[this.id]);
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ public AC_BlockPillar(int var1, int var2) {
}

@Override
public int getTextureForSide(int var1, int var2) {
return var1 == 1 ? this.texture - 16 + var2 : (var1 == 0 ? this.texture + 16 + var2 : this.texture + var2);
public int getTextureForSide(int var1, int meta) {
return var1 == 1 ? this.texture - 16 + meta : (var1 == 0 ? this.texture + 16 + meta : this.texture + meta);
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int var5 = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (var5 + 1) % ExBlock.subTypes[this.id]);
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public int getRenderType() {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int var5 = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (var5 + 1) % ExBlock.subTypes[this.id]);
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public int getTextureForSide(int var1, int var2) {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int var5 = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (var5 + 1) % ExBlock.subTypes[this.id]);
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,23 @@ public void afterPlaced(World world, int x, int y, int z, LivingEntity placer) {
}
}

@Override
public int getMaxColorMeta() {
return 16;
}

@Override
public int getColorMultiplier(BlockView view, int x, int y, int z) {
return 0xFFFFFF;
}

@Override
public int getColorMetaData(BlockView view, int x, int y, int z) {
public int getColorMeta(BlockView view, int x, int y, int z) {
return view.getBlockMeta(x, y, z) >> 2;
}

@Override
public void setColorMetaData(World world, int x, int y, int z, int meta) {
public void setColorMeta(World world, int x, int y, int z, int meta) {
world.setBlockMeta(x, y, z, world.getBlockMeta(x, y, z) & 3 | meta << 2);
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int meta = (this.getColorMetaData(world, x, y, z) + 1) % 16;
this.setColorMetaData(world, x, y, z, meta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public boolean canUse(World world, int x, int y, int z, PlayerEntity player) {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int var5 = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (var5 + 1) % ExBlock.subTypes[this.id]);
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import dev.adventurecraft.awakening.extension.block.ExBlock;
import dev.adventurecraft.awakening.extension.world.ExWorld;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.material.Material;
import net.minecraft.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class AC_BlockTriggerPushable extends BlockWithEntity implements AC_IBlockColor {
public class AC_BlockTriggerPushable extends AC_BlockColorWithEntity {

protected AC_BlockTriggerPushable(int var1, int var2) {
super(var1, var2, Material.STONE);
Expand Down Expand Up @@ -46,7 +45,6 @@ public void onAdjacentBlockUpdate(World world, int x, int y, int z, int id) {
ExBlock.resetArea(world, entity.minX, entity.minY, entity.minZ, entity.maxX, entity.maxY, entity.maxZ);
}
}

}

public void setTriggerToSelection(World world, int x, int y, int z) {
Expand All @@ -71,8 +69,8 @@ public boolean canUse(World world, int x, int y, int z, PlayerEntity player) {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
AC_IBlockColor.super.incrementColor(world, x, y, z);
public void incrementColor(World world, int x, int y, int z, int amount) {
super.incrementColor(world, x, y, z, amount);
this.onAdjacentBlockUpdate(world, x, y, z, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@

public interface AC_IBlockColor {

int numColors = 7;
int defaultColor = 13421772;

default int getColorMetaData(BlockView view, int x, int y, int z) {
default int getMaxColorMeta() {
return 7;
}

default int getColorMeta(BlockView view, int x, int y, int z) {
return view.getBlockMeta(x, y, z);
}

default void setColorMetaData(World world, int x, int y, int z, int meta) {
default void setColorMeta(World world, int x, int y, int z, int meta) {
world.setBlockMeta(x, y, z, meta);
}

default void incrementColor(World world, int x, int y, int z) {
int meta = (this.getColorMetaData(world, x, y, z) + 1) % numColors;
this.setColorMetaData(world, x, y, z, meta);
default void incrementColor(World world, int x, int y, int z, int amount) {
int maxMeta = this.getMaxColorMeta();
if (maxMeta == 0) {
return;
}

int meta = this.getColorMeta(world, x, y, z);
int clampedMeta = Integer.remainderUnsigned(meta + amount, maxMeta);
this.setColorMeta(world, x, y, z, clampedMeta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ protected AC_ItemBrush(int var1) {
public boolean useOnBlock(ItemStack stack, PlayerEntity player, World world, int x, int y, int z, int side) {
Block block = Block.BY_ID[world.getBlockId(x, y, z)];
if (block instanceof AC_IBlockColor) {
((AC_IBlockColor) block).incrementColor(world, x, y, z);
int amount = player.method_1373() ? -1 : 1;
((AC_IBlockColor) block).incrementColor(world, x, y, z, amount);
world.notifyListeners(x, y, z);
} else {
Minecraft.instance.overlay.addChatMessage("Doesn't implement Color :(");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@
import net.minecraft.world.World;

public class AC_ItemPaintBucket extends Item {

protected AC_ItemPaintBucket(int var1) {
super(var1);
}

public boolean useOnBlock(ItemStack var1, PlayerEntity var2, World var3, int var4, int var5, int var6, int var7) {
// TODO: use on singular block
public boolean useOnBlock(ItemStack item, PlayerEntity player, World world, int x, int y, int z, int meta) {
// TODO: use on singular block?
if (!AC_ItemCursor.bothSet) {
return false;
}

if (AC_ItemCursor.bothSet) {
int var8 = Math.min(AC_ItemCursor.oneX, AC_ItemCursor.twoX);
int var9 = Math.max(AC_ItemCursor.oneX, AC_ItemCursor.twoX);
int var10 = Math.min(AC_ItemCursor.oneY, AC_ItemCursor.twoY);
int var11 = Math.max(AC_ItemCursor.oneY, AC_ItemCursor.twoY);
int var12 = Math.min(AC_ItemCursor.oneZ, AC_ItemCursor.twoZ);
int var13 = Math.max(AC_ItemCursor.oneZ, AC_ItemCursor.twoZ);
int minX = Math.min(AC_ItemCursor.oneX, AC_ItemCursor.twoX);
int maxX = Math.max(AC_ItemCursor.oneX, AC_ItemCursor.twoX);
int minY = Math.min(AC_ItemCursor.oneY, AC_ItemCursor.twoY);
int maxY = Math.max(AC_ItemCursor.oneY, AC_ItemCursor.twoY);
int minZ = Math.min(AC_ItemCursor.oneZ, AC_ItemCursor.twoZ);
int maxZ = Math.max(AC_ItemCursor.oneZ, AC_ItemCursor.twoZ);
int amount = player.method_1373() ? -1 : 1;

for (int var14 = var8; var14 <= var9; ++var14) {
for (int var15 = var10; var15 <= var11; ++var15) {
for (int var16 = var12; var16 <= var13; ++var16) {
Block var17 = Block.BY_ID[var3.getBlockId(var14, var15, var16)];
if (var17 instanceof AC_IBlockColor colorBlock) {
colorBlock.incrementColor(var3, var14, var15, var16);
var3.notifyListeners(var14, var15, var16);
}
for (int bX = minX; bX <= maxX; ++bX) {
for (int bY = minY; bY <= maxY; ++bY) {
for (int bZ = minZ; bZ <= maxZ; ++bZ) {
Block block = Block.BY_ID[world.getBlockId(bX, bY, bZ)];
if (block instanceof AC_IBlockColor colorBlock) {
colorBlock.incrementColor(world, bX, bY, bZ, amount);
world.notifyListeners(bX, bY, bZ);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ private void setMetaOnEntity(
}

@Override
public int getTextureForSide(int var1, int var2) {
return var2 == 0 ? this.texture : 228 + var2 - 1;
public int getTextureForSide(int var1, int meta) {
return meta == 0 ? this.texture : 228 + meta - 1;
}

@Override
public void incrementColor(World world, int x, int y, int z) {
if (ExBlock.subTypes[this.id] > 0) {
int var5 = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (var5 + 1) % ExBlock.subTypes[this.id]);
}
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ public int getRenderType() {
}

@Override
public void incrementColor(World world, int x, int y, int z) {
int meta = world.getBlockMeta(x, y, z);
world.setBlockMeta(x, y, z, (meta + 1) % ExBlock.subTypes[this.id]);
public int getMaxColorMeta() {
return ExBlock.subTypes[this.id];
}

@Override
Expand Down
Loading

0 comments on commit 9fa596b

Please sign in to comment.