Compare commits
1 Commits
2.13
...
shader-ref
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f74b107d6 |
@@ -1,3 +0,0 @@
|
||||
This is the version for Minecraft 1.12.
|
||||
|
||||
1.13 can be found here: https://bitbucket.org/Requios/effortless-building-1.13/src/master/
|
||||
@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
|
||||
|
||||
|
||||
version = "1.12.2-2.13"
|
||||
version = "1.12.2-2.10"
|
||||
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "effortlessbuilding"
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BuildConfig {
|
||||
|
||||
@Comment({"Determines what blocks can be replaced in survival.",
|
||||
"-1: only blocks that can be harvested by hand (default)",
|
||||
"0: blocks that can be harvested with wooden or gold tools",
|
||||
"0: blocks that can be harvested with wooden oref gold tools",
|
||||
"1: blocks that can be harvested with stone tools",
|
||||
"2: blocks that can be harvested with iron tools",
|
||||
"3: blocks that can be harvested with diamond tools",
|
||||
|
||||
@@ -39,7 +39,7 @@ public class EffortlessBuilding
|
||||
{
|
||||
public static final String MODID = "effortlessbuilding";
|
||||
public static final String NAME = "Effortless Building";
|
||||
public static final String VERSION = "1.12.2-2.13";
|
||||
public static final String VERSION = "1.12.2-2.10";
|
||||
|
||||
@Mod.Instance(EffortlessBuilding.MODID)
|
||||
public static EffortlessBuilding instance;
|
||||
@@ -93,20 +93,11 @@ public class EffortlessBuilding
|
||||
EffortlessBuilding.packetHandler.registerMessage(BlockPlacedMessage.MessageHandler.class, BlockPlacedMessage.class, 3, Side.CLIENT);
|
||||
|
||||
EffortlessBuilding.packetHandler.registerMessage(BlockBrokenMessage.MessageHandler.class, BlockBrokenMessage.class, 4, Side.SERVER);
|
||||
EffortlessBuilding.packetHandler.registerMessage(BlockBrokenMessage.MessageHandler.class, BlockBrokenMessage.class, 4, Side.CLIENT);
|
||||
|
||||
EffortlessBuilding.packetHandler.registerMessage(CancelModeMessage.MessageHandler.class, CancelModeMessage.class, 5, Side.SERVER);
|
||||
EffortlessBuilding.packetHandler.registerMessage(CancelModeMessage.MessageHandler.class, CancelModeMessage.class, 5, Side.CLIENT);
|
||||
|
||||
EffortlessBuilding.packetHandler.registerMessage(RequestLookAtMessage.MessageHandler.class, RequestLookAtMessage.class, 6, Side.SERVER);
|
||||
EffortlessBuilding.packetHandler.registerMessage(RequestLookAtMessage.MessageHandler.class, RequestLookAtMessage.class, 6, Side.CLIENT);
|
||||
|
||||
EffortlessBuilding.packetHandler.registerMessage(AddUndoMessage.MessageHandler.class, AddUndoMessage.class, 7, Side.SERVER);
|
||||
EffortlessBuilding.packetHandler.registerMessage(AddUndoMessage.MessageHandler.class, AddUndoMessage.class, 7, Side.CLIENT);
|
||||
|
||||
EffortlessBuilding.packetHandler.registerMessage(ClearUndoMessage.MessageHandler.class, ClearUndoMessage.class, 8, Side.SERVER);
|
||||
EffortlessBuilding.packetHandler.registerMessage(ClearUndoMessage.MessageHandler.class, ClearUndoMessage.class, 8, Side.CLIENT);
|
||||
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -31,9 +30,6 @@ import nl.requios.effortlessbuilding.capability.ModeCapabilityManager;
|
||||
import nl.requios.effortlessbuilding.capability.ModifierCapabilityManager;
|
||||
import nl.requios.effortlessbuilding.helper.ReachHelper;
|
||||
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
|
||||
import nl.requios.effortlessbuilding.network.AddUndoMessage;
|
||||
import nl.requios.effortlessbuilding.network.BlockBrokenMessage;
|
||||
import nl.requios.effortlessbuilding.network.ClearUndoMessage;
|
||||
import nl.requios.effortlessbuilding.network.RequestLookAtMessage;
|
||||
import scala.actors.threadpool.Arrays;
|
||||
|
||||
@@ -95,20 +91,14 @@ public class EventHandler
|
||||
BuildModes.BuildModeEnum buildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
|
||||
|
||||
if (buildMode != BuildModes.BuildModeEnum.NORMAL) {
|
||||
if (buildMode != BuildModes.BuildModeEnum.NORMAL || modifierSettings.doQuickReplace()) {
|
||||
event.setCanceled(true);
|
||||
} else if (modifierSettings.doQuickReplace()) {
|
||||
//Cancel event and send message if QuickReplace
|
||||
event.setCanceled(true);
|
||||
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(true), (EntityPlayerMP) player);
|
||||
EffortlessBuilding.packetHandler.sendTo(new AddUndoMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
|
||||
} else {
|
||||
//NORMAL mode, let vanilla handle block placing
|
||||
//But modifiers should still work
|
||||
//But modifiers and QuickReplace should still work
|
||||
|
||||
//Send message to client, which sends message back with raytrace info
|
||||
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(false), (EntityPlayerMP) player);
|
||||
EffortlessBuilding.packetHandler.sendTo(new AddUndoMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
|
||||
EffortlessBuilding.packetHandler.sendTo(new RequestLookAtMessage(event.getPos(), event.getBlockSnapshot().getReplacedBlock(), event.getState()), (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,12 +113,9 @@ public class EventHandler
|
||||
event.setCanceled(true);
|
||||
} else {
|
||||
//NORMAL mode, let vanilla handle block breaking
|
||||
//But modifiers should still work
|
||||
//But modifiers and QuickReplace should still work
|
||||
//Dont break the original block yourself, otherwise Tinkers Hammer and Veinminer won't work
|
||||
BuildModes.onBlockBroken(event.getPlayer(), event.getPos(), false);
|
||||
|
||||
//Add to undo stack in client
|
||||
EffortlessBuilding.packetHandler.sendTo(new AddUndoMessage(event.getPos(), event.getState(), Blocks.AIR.getDefaultState()), (EntityPlayerMP) event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,11 +165,8 @@ public class EventHandler
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedOut(PlayerLoggedOutEvent event) {
|
||||
EntityPlayer player = event.player;
|
||||
if (player.getEntityWorld().isRemote) return;
|
||||
|
||||
UndoRedo.clear(player);
|
||||
EffortlessBuilding.packetHandler.sendTo(new ClearUndoMessage(), (EntityPlayerMP) player);
|
||||
UndoRedo.clear(event.player);
|
||||
//TODO call clientside
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -195,12 +179,10 @@ public class EventHandler
|
||||
@SubscribeEvent
|
||||
public static void onPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
EntityPlayer player = event.player;
|
||||
if (player.getEntityWorld().isRemote) return;
|
||||
|
||||
ModifierSettingsManager.handleNewPlayer(player);
|
||||
ModeSettingsManager.handleNewPlayer(player);
|
||||
|
||||
UndoRedo.clear(event.player);
|
||||
EffortlessBuilding.packetHandler.sendTo(new ClearUndoMessage(), (EntityPlayerMP) player);
|
||||
//TODO call clientside
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,16 +135,16 @@ public class BuildModes {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ReachHelper.canBreakFar(player)) return;
|
||||
|
||||
//If first click
|
||||
if (currentlyBreaking.get(player) == null) {
|
||||
//If startpos is null, dont do anything
|
||||
if (startPos == null) return;
|
||||
}
|
||||
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
|
||||
ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player);
|
||||
|
||||
//Get coordinates
|
||||
ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player);
|
||||
BuildModeEnum buildMode = modeSettings.getBuildMode();
|
||||
List<BlockPos> coordinates = buildMode.instance.onRightClick(player, startPos, EnumFacing.UP, Vec3d.ZERO, true);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package nl.requios.effortlessbuilding.buildmodifier;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -76,19 +75,10 @@ public class BuildModifiers {
|
||||
}
|
||||
}
|
||||
|
||||
//Set first previousBlockState to empty if in NORMAL mode, to make undo/redo work
|
||||
//(Block is placed by the time it gets here, and unplaced after this)
|
||||
if (!placeStartPos) previousBlockStates.set(0, Blocks.AIR.getDefaultState());
|
||||
|
||||
//If all new blockstates are air then no use in adding it, no block was actually placed
|
||||
//Can happen when e.g. placing one block in yourself
|
||||
if (Collections.frequency(newBlockStates, Blocks.AIR.getDefaultState()) != newBlockStates.size()) {
|
||||
//add to undo stack
|
||||
BlockPos firstPos = startCoordinates.get(0);
|
||||
BlockPos secondPos = startCoordinates.get(startCoordinates.size() - 1);
|
||||
UndoRedo.addUndo(player, new BlockSet(coordinates, previousBlockStates, newBlockStates, hitVec, firstPos, secondPos));
|
||||
}
|
||||
|
||||
//add to undo stack
|
||||
BlockPos firstPos = startCoordinates.get(0);
|
||||
BlockPos secondPos = startCoordinates.get(startCoordinates.size() - 1);
|
||||
UndoRedo.addUndo(player, new BlockSet(coordinates, previousBlockStates, newBlockStates, hitVec, firstPos, secondPos));
|
||||
}
|
||||
|
||||
public static void onBlockBroken(EntityPlayer player, List<BlockPos> startCoordinates, boolean breakStartPos) {
|
||||
@@ -110,7 +100,7 @@ public class BuildModifiers {
|
||||
|
||||
//list of air blockstates
|
||||
for (BlockPos coordinate : coordinates) {
|
||||
newBlockStates.add(Blocks.AIR.getDefaultState());
|
||||
newBlockStates.add(Block.getBlockById(0).getDefaultState());
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -135,10 +125,6 @@ public class BuildModifiers {
|
||||
}
|
||||
}
|
||||
|
||||
//Set first newBlockState to empty if in NORMAL mode, to make undo/redo work
|
||||
//(Block isn't broken yet by the time it gets here, and broken after this)
|
||||
if (!breakStartPos) newBlockStates.set(0, Blocks.AIR.getDefaultState());
|
||||
|
||||
//add to undo stack
|
||||
BlockPos firstPos = startCoordinates.get(0);
|
||||
BlockPos secondPos = startCoordinates.get(startCoordinates.size() - 1);
|
||||
|
||||
@@ -3,7 +3,6 @@ package nl.requios.effortlessbuilding.buildmodifier;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -32,36 +31,17 @@ public class UndoRedo {
|
||||
public static void addUndo(EntityPlayer player, BlockSet blockSet) {
|
||||
Map<UUID, FixedStack<BlockSet>> undoStacks = player.world.isRemote ? undoStacksClient : undoStacksServer;
|
||||
|
||||
//Assert coordinates is as long as previous and new blockstate lists
|
||||
if (blockSet.getCoordinates().size() != blockSet.getPreviousBlockStates().size() ||
|
||||
blockSet.getCoordinates().size() != blockSet.getNewBlockStates().size()) {
|
||||
EffortlessBuilding.logger.error("Coordinates and blockstate lists are not equal length. Coordinates: {}. Previous blockstates: {}. New blockstates: {}.",
|
||||
blockSet.getCoordinates().size(), blockSet.getPreviousBlockStates().size(), blockSet.getNewBlockStates().size());
|
||||
}
|
||||
|
||||
//Warn if previous and new blockstate are equal
|
||||
//Can happen in a lot of valid cases
|
||||
// for (int i = 0; i < blockSet.getCoordinates().size(); i++) {
|
||||
// if (blockSet.getPreviousBlockStates().get(i).equals(blockSet.getNewBlockStates().get(i))) {
|
||||
// EffortlessBuilding.logger.warn("Previous and new blockstates are equal at index {}. Blockstate: {}.",
|
||||
// i, blockSet.getPreviousBlockStates().get(i));
|
||||
// }
|
||||
// }
|
||||
|
||||
//If no stack exists, make one
|
||||
if (!undoStacks.containsKey(player.getUniqueID())) {
|
||||
undoStacks.put(player.getUniqueID(), new FixedStack<>(new BlockSet[BuildConfig.survivalBalancers.undoStackSize]));
|
||||
}
|
||||
|
||||
|
||||
undoStacks.get(player.getUniqueID()).push(blockSet);
|
||||
}
|
||||
|
||||
private static void addRedo(EntityPlayer player, BlockSet blockSet) {
|
||||
Map<UUID, FixedStack<BlockSet>> redoStacks = player.world.isRemote ? redoStacksClient : redoStacksServer;
|
||||
|
||||
//(No asserts necessary, it's private)
|
||||
|
||||
//If no stack exists, make one
|
||||
if (!redoStacks.containsKey(player.getUniqueID())) {
|
||||
redoStacks.put(player.getUniqueID(), new FixedStack<>(new BlockSet[BuildConfig.survivalBalancers.undoStackSize]));
|
||||
@@ -96,12 +76,10 @@ public class UndoRedo {
|
||||
BlockPos coordinate = coordinates.get(i);
|
||||
ItemStack itemStack = itemStacks.get(i);
|
||||
|
||||
if (previousBlockStates.get(i).equals(newBlockStates.get(i))) continue;
|
||||
|
||||
//get blockstate from itemstack
|
||||
IBlockState previousBlockState = Blocks.AIR.getDefaultState();
|
||||
IBlockState previousBlockState = Block.getBlockById(0).getDefaultState();
|
||||
if (itemStack.getItem() instanceof ItemBlock) {
|
||||
previousBlockState = previousBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
previousBlockState = ((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
}
|
||||
|
||||
if (player.world.isBlockLoaded(coordinate, true)) {
|
||||
@@ -110,9 +88,7 @@ public class UndoRedo {
|
||||
itemStack = findItemStackInInventory(player, previousBlockStates.get(i));
|
||||
//get blockstate from new itemstack
|
||||
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemBlock) {
|
||||
previousBlockState = previousBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
} else {
|
||||
previousBlockState = Blocks.AIR.getDefaultState();
|
||||
previousBlockState = ((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
}
|
||||
}
|
||||
if (itemStack.isEmpty()) SurvivalHelper.breakBlock(player.world, player, coordinate, true);
|
||||
@@ -139,7 +115,6 @@ public class UndoRedo {
|
||||
|
||||
BlockSet blockSet = redoStack.pop();
|
||||
List<BlockPos> coordinates = blockSet.getCoordinates();
|
||||
List<IBlockState> previousBlockStates = blockSet.getPreviousBlockStates();
|
||||
List<IBlockState> newBlockStates = blockSet.getNewBlockStates();
|
||||
Vec3d hitVec = blockSet.getHitVec();
|
||||
|
||||
@@ -152,25 +127,16 @@ public class UndoRedo {
|
||||
//place blocks
|
||||
for (int i = 0; i < coordinates.size(); i++) {
|
||||
BlockPos coordinate = coordinates.get(i);
|
||||
IBlockState newBlockState = newBlockStates.get(i);
|
||||
ItemStack itemStack = itemStacks.get(i);
|
||||
|
||||
if (previousBlockStates.get(i).equals(newBlockStates.get(i))) continue;
|
||||
|
||||
//get blockstate from itemstack
|
||||
IBlockState newBlockState = Blocks.AIR.getDefaultState();
|
||||
if (itemStack.getItem() instanceof ItemBlock) {
|
||||
newBlockState = newBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
}
|
||||
|
||||
if (player.world.isBlockLoaded(coordinate, true)) {
|
||||
//check itemstack empty
|
||||
if (itemStack.isEmpty()) {
|
||||
itemStack = findItemStackInInventory(player, newBlockStates.get(i));
|
||||
//get blockstate from new itemstack
|
||||
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemBlock) {
|
||||
newBlockState = newBlockStates.get(i);//((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
} else {
|
||||
newBlockState = Blocks.AIR.getDefaultState();
|
||||
newBlockState = ((ItemBlock) itemStack.getItem()).getBlock().getDefaultState();
|
||||
}
|
||||
}
|
||||
if (itemStack.isEmpty()) SurvivalHelper.breakBlock(player.world, player, coordinate, true);
|
||||
@@ -208,8 +174,6 @@ public class UndoRedo {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
|
||||
//First try previousBlockStates
|
||||
//TODO try to find itemstack with right blockstate first
|
||||
// then change line 103 back (get state from item)
|
||||
itemStack = InventoryHelper.findItemStackInInventory(player, blockState.getBlock());
|
||||
|
||||
//then anything it drops
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package nl.requios.effortlessbuilding.compatibility;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
@@ -65,9 +63,9 @@ public class CompatHelper {
|
||||
}
|
||||
|
||||
//Dank Null
|
||||
if (proxyItem == dankNullItem) {
|
||||
if(proxyItem == dankNullItem) {
|
||||
int index = 0;
|
||||
if (proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
|
||||
if(proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
|
||||
index = proxy.getTagCompound().getInteger("selectedIndex");
|
||||
return proxy.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
|
||||
}
|
||||
@@ -77,14 +75,14 @@ public class CompatHelper {
|
||||
|
||||
public static ItemStack getItemBlockByState(ItemStack stack, IBlockState state) {
|
||||
Item blockItem = Item.getItemFromBlock(state.getBlock());
|
||||
if (stack.getItem() instanceof ItemBlock)
|
||||
if(stack.getItem() instanceof ItemBlock)
|
||||
return stack;
|
||||
else if (stack.getItem() instanceof ItemRandomizerBag) {
|
||||
else if(stack.getItem() instanceof ItemRandomizerBag) {
|
||||
IItemHandler bagInventory = ItemRandomizerBag.getBagInventory(stack);
|
||||
return ItemRandomizerBag.findStack(bagInventory, blockItem);
|
||||
} else if (stack.getItem() == dankNullItem) {
|
||||
} else if(stack.getItem() == dankNullItem) {
|
||||
int index = itemHandlerSlotForItem(stack, blockItem);
|
||||
if (index >= 0)
|
||||
if(index >= 0)
|
||||
return stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
@@ -92,11 +90,8 @@ public class CompatHelper {
|
||||
|
||||
// Handle IItemHandler slot stacks not being modifiable. We must call IItemHandler#extractItem,
|
||||
// because the ItemStack returned by IItemHandler#getStackInSlot isn't modifiable.
|
||||
public static void shrinkStack(ItemStack origStack, ItemStack curStack, EntityPlayer player) {
|
||||
//Hacky way to get the origstack, because given origStack is itemblock stack and never a proxy
|
||||
origStack = player.getHeldItem(EnumHand.MAIN_HAND);
|
||||
|
||||
if (origStack.getItem() == dankNullItem) {
|
||||
public static void shrinkStack(ItemStack origStack, ItemStack curStack) {
|
||||
if(origStack.getItem() == dankNullItem) {
|
||||
int index = itemHandlerSlotForItem(origStack, curStack.getItem());
|
||||
origStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).extractItem(index, 1, false);
|
||||
} else
|
||||
@@ -105,10 +100,10 @@ public class CompatHelper {
|
||||
|
||||
private static int itemHandlerSlotForItem(ItemStack stack, Item blockItem) {
|
||||
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
for(int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack ref = handler.getStackInSlot(i);
|
||||
if (ref.getItem() instanceof ItemBlock)
|
||||
if (ref.getItem() == blockItem)
|
||||
if(ref.getItem() instanceof ItemBlock)
|
||||
if(ref.getItem() == blockItem)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -28,20 +28,12 @@ public class ReachHelper {
|
||||
|
||||
public static int getMaxBlocksPlacedAtOnce(EntityPlayer player) {
|
||||
if (player.isCreative()) return 1000000;
|
||||
return MathHelper.ceil(Math.pow(getMaxReach(player), 1.6));
|
||||
//Level 0: 121
|
||||
//Level 1: 523
|
||||
//Level 2: 1585
|
||||
//Level 3: 4805
|
||||
return getMaxReach(player) * 5;
|
||||
}
|
||||
|
||||
public static int getMaxBlocksPerAxis(EntityPlayer player) {
|
||||
if (player.isCreative()) return 2000;
|
||||
return MathHelper.ceil(getMaxReach(player) * 0.3);
|
||||
//Level 0: 6
|
||||
//Level 1: 15
|
||||
//Level 2: 30
|
||||
//Level 3: 60
|
||||
return MathHelper.ceil(MathHelper.sqrt(getMaxReach(player)));
|
||||
}
|
||||
|
||||
public static boolean canBreakFar(EntityPlayer player) {
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SurvivalHelper {
|
||||
}
|
||||
|
||||
if (!player.isCreative() && Block.getBlockFromItem(itemstack.getItem()) == block) {
|
||||
CompatHelper.shrinkStack(origstack, itemstack, player);
|
||||
CompatHelper.shrinkStack(origstack, itemstack);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BlockSet;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.UndoRedo;
|
||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/***
|
||||
* Sends a message to the client asking to add a block to the undo stack.
|
||||
*/
|
||||
public class AddUndoMessage implements IMessage {
|
||||
private BlockPos coordinate;
|
||||
private IBlockState previousBlockState;
|
||||
private IBlockState newBlockState;
|
||||
|
||||
public AddUndoMessage() {
|
||||
coordinate = BlockPos.ORIGIN;
|
||||
previousBlockState = null;
|
||||
newBlockState = null;
|
||||
}
|
||||
|
||||
public AddUndoMessage(BlockPos coordinate, IBlockState previousBlockState, IBlockState newBlockState) {
|
||||
this.coordinate = coordinate;
|
||||
this.previousBlockState = previousBlockState;
|
||||
this.newBlockState = newBlockState;
|
||||
}
|
||||
|
||||
public BlockPos getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
public IBlockState getPreviousBlockState() {
|
||||
return previousBlockState;
|
||||
}
|
||||
|
||||
public IBlockState getNewBlockState() {
|
||||
return newBlockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(this.coordinate.getX());
|
||||
buf.writeInt(this.coordinate.getY());
|
||||
buf.writeInt(this.coordinate.getZ());
|
||||
buf.writeInt(Block.getStateId(this.previousBlockState));
|
||||
buf.writeInt(Block.getStateId(this.newBlockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
coordinate = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
previousBlockState = Block.getStateById(buf.readInt());
|
||||
newBlockState = Block.getStateById(buf.readInt());
|
||||
}
|
||||
|
||||
// The params of the IMessageHandler are <REQ, REPLY>
|
||||
public static class MessageHandler implements IMessageHandler<AddUndoMessage, IMessage> {
|
||||
// Do note that the default constructor is required, but implicitly defined in this case
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(AddUndoMessage message, MessageContext ctx) {
|
||||
//EffortlessBuilding.log("message received on " + ctx.side + " side");
|
||||
|
||||
if (ctx.side == Side.CLIENT){
|
||||
//Received clientside
|
||||
|
||||
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
|
||||
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
|
||||
|
||||
//Add to undo stack clientside
|
||||
UndoRedo.addUndo(player, new BlockSet(
|
||||
new ArrayList<BlockPos>() {{add(message.getCoordinate());}},
|
||||
new ArrayList<IBlockState>() {{add(message.getPreviousBlockState());}},
|
||||
new ArrayList<IBlockState>() {{add(message.getNewBlockState());}},
|
||||
new Vec3d(0,0,0),
|
||||
message.getCoordinate(), message.getCoordinate()));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BlockSet;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.UndoRedo;
|
||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/***
|
||||
* Sends a message to the client asking to clear the undo and redo stacks.
|
||||
*/
|
||||
public class ClearUndoMessage implements IMessage {
|
||||
|
||||
public ClearUndoMessage() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
}
|
||||
|
||||
// The params of the IMessageHandler are <REQ, REPLY>
|
||||
public static class MessageHandler implements IMessageHandler<ClearUndoMessage, IMessage> {
|
||||
// Do note that the default constructor is required, but implicitly defined in this case
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(ClearUndoMessage message, MessageContext ctx) {
|
||||
//EffortlessBuilding.log("message received on " + ctx.side + " side");
|
||||
|
||||
if (ctx.side == Side.CLIENT){
|
||||
//Received clientside
|
||||
|
||||
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
|
||||
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
|
||||
|
||||
//Add to undo stack clientside
|
||||
UndoRedo.clear(player);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,28 +22,48 @@ import java.util.ArrayList;
|
||||
* This is then sent back with a BlockPlacedMessage.
|
||||
*/
|
||||
public class RequestLookAtMessage implements IMessage {
|
||||
private boolean placeStartPos;
|
||||
private BlockPos coordinate;
|
||||
private IBlockState previousBlockState;
|
||||
private IBlockState newBlockState;
|
||||
|
||||
public RequestLookAtMessage() {
|
||||
placeStartPos = false;
|
||||
coordinate = BlockPos.ORIGIN;
|
||||
previousBlockState = null;
|
||||
newBlockState = null;
|
||||
}
|
||||
|
||||
public RequestLookAtMessage(boolean placeStartPos) {
|
||||
this.placeStartPos = placeStartPos;
|
||||
public RequestLookAtMessage(BlockPos coordinate, IBlockState previousBlockState, IBlockState newBlockState) {
|
||||
this.coordinate = coordinate;
|
||||
this.previousBlockState = previousBlockState;
|
||||
this.newBlockState = newBlockState;
|
||||
}
|
||||
|
||||
public boolean getPlaceStartPos() {
|
||||
return placeStartPos;
|
||||
public BlockPos getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
public IBlockState getPreviousBlockState() {
|
||||
return previousBlockState;
|
||||
}
|
||||
|
||||
public IBlockState getNewBlockState() {
|
||||
return newBlockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(this.placeStartPos);
|
||||
buf.writeInt(this.coordinate.getX());
|
||||
buf.writeInt(this.coordinate.getY());
|
||||
buf.writeInt(this.coordinate.getZ());
|
||||
buf.writeInt(Block.getStateId(this.previousBlockState));
|
||||
buf.writeInt(Block.getStateId(this.newBlockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
placeStartPos = buf.readBoolean();
|
||||
coordinate = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
previousBlockState = Block.getStateById(buf.readInt());
|
||||
newBlockState = Block.getStateById(buf.readInt());
|
||||
}
|
||||
|
||||
// The params of the IMessageHandler are <REQ, REPLY>
|
||||
@@ -58,14 +78,20 @@ public class RequestLookAtMessage implements IMessage {
|
||||
//Received clientside
|
||||
//Send back your info
|
||||
|
||||
// EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
|
||||
// EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
|
||||
//
|
||||
// });
|
||||
EffortlessBuilding.proxy.getThreadListenerFromContext(ctx).addScheduledTask(() -> {
|
||||
EntityPlayer player = EffortlessBuilding.proxy.getPlayerEntityFromContext(ctx);
|
||||
|
||||
//Prevent double placing in normal mode with placeStartPos false.
|
||||
//Unless QuickReplace is on, then we do need to place start pos.
|
||||
return new BlockPlacedMessage(ClientProxy.previousLookAt, message.getPlaceStartPos());
|
||||
//Add to undo stack clientside
|
||||
UndoRedo.addUndo(player, new BlockSet(
|
||||
new ArrayList<BlockPos>() {{add(message.getCoordinate());}},
|
||||
new ArrayList<IBlockState>() {{add(message.getPreviousBlockState());}},
|
||||
new ArrayList<IBlockState>() {{add(message.getNewBlockState());}},
|
||||
new Vec3d(0,0,0),
|
||||
message.getCoordinate(), message.getCoordinate()));
|
||||
});
|
||||
|
||||
//Prevent double placing in normal mode with placeStartPos false
|
||||
return new BlockPlacedMessage(ClientProxy.previousLookAt, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ClientProxy implements IProxy {
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
// register key bindings
|
||||
keyBindings = new KeyBinding[6];
|
||||
keyBindings = new KeyBinding[7];
|
||||
|
||||
// instantiate the key bindings
|
||||
keyBindings[0] = new KeyBinding("key.effortlessbuilding.hud.desc", KeyConflictContext.UNIVERSAL, Keyboard.KEY_ADD, "key.effortlessbuilding.category");
|
||||
@@ -97,7 +97,7 @@ public class ClientProxy implements IProxy {
|
||||
};
|
||||
keyBindings[4] = new KeyBinding("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_Z, "key.effortlessbuilding.category");
|
||||
keyBindings[5] = new KeyBinding("key.effortlessbuilding.redo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_Y, "key.effortlessbuilding.category");
|
||||
// keyBindings[6] = new KeyBinding("Reload shaders", Keyboard.KEY_TAB, "key.effortlessbuilding.category");
|
||||
keyBindings[6] = new KeyBinding("Reload shaders", Keyboard.KEY_TAB, "key.effortlessbuilding.category");
|
||||
|
||||
// register all the key bindings
|
||||
for (int i = 0; i < keyBindings.length; ++i) {
|
||||
@@ -261,11 +261,6 @@ public class ClientProxy implements IProxy {
|
||||
//Break block in distance in creative (or survival if enabled in config)
|
||||
if (breakCooldown <= 0) {
|
||||
breakCooldown = 4;
|
||||
|
||||
//Early out if cant break far, coming from own mouse event (not block broken event)
|
||||
//To make breaking blocks in survival possible without breaking instantly
|
||||
if (!ReachHelper.canBreakFar(player)) return;
|
||||
|
||||
RayTraceResult lookingAt = getLookingAt(player);
|
||||
|
||||
BuildModes.onBlockBrokenMessage(player, lookingAt == null ? new BlockBrokenMessage() : new BlockBrokenMessage(lookingAt));
|
||||
|
||||
@@ -5,13 +5,11 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -26,14 +24,13 @@ import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.ModifierSettingsManager.ModifierSettings;
|
||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||
import nl.requios.effortlessbuilding.helper.InventoryHelper;
|
||||
import nl.requios.effortlessbuilding.helper.ReachHelper;
|
||||
import nl.requios.effortlessbuilding.helper.SurvivalHelper;
|
||||
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
|
||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||
import org.lwjgl.opengl.ARBMultitexture;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -73,7 +70,7 @@ public class BlockPreviewRenderer {
|
||||
private static List<PlacedData> placedDataList = new ArrayList<>();
|
||||
|
||||
private static final int primaryTextureUnit = 0;
|
||||
private static final int secondaryTextureUnit = 2;
|
||||
private static final int secondaryTextureUnit = 1;
|
||||
|
||||
public static void render(EntityPlayer player, ModifierSettings modifierSettings, ModeSettings modeSettings) {
|
||||
|
||||
@@ -373,39 +370,40 @@ public class BlockPreviewRenderer {
|
||||
final boolean highlight, final boolean red) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
return (Integer shader) -> {
|
||||
int percentileUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "dissolve");
|
||||
int highlightUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "highlight");
|
||||
int redUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "red");
|
||||
int blockposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "blockpos");
|
||||
int firstposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "firstpos");
|
||||
int secondposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "secondpos");
|
||||
int imageUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "image");
|
||||
int maskUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "mask");
|
||||
int percentileUniform = GL20.glGetUniformLocation(shader, "dissolve");
|
||||
int highlightUniform = GL20.glGetUniformLocation(shader, "highlight");
|
||||
int redUniform = GL20.glGetUniformLocation(shader, "red");
|
||||
int blockposUniform = GL20.glGetUniformLocation(shader, "blockpos");
|
||||
int firstposUniform = GL20.glGetUniformLocation(shader, "firstpos");
|
||||
int secondposUniform = GL20.glGetUniformLocation(shader, "secondpos");
|
||||
int imageUniform = GL20.glGetUniformLocation(shader, "image");
|
||||
int maskUniform = GL20.glGetUniformLocation(shader, "mask");
|
||||
|
||||
GlStateManager.enableTexture2D();
|
||||
GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
|
||||
//image
|
||||
GL20.glUniform1i(imageUniform, primaryTextureUnit);
|
||||
OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + primaryTextureUnit);
|
||||
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).getGlTextureId());
|
||||
|
||||
// GlStateManager.enableTexture2D();
|
||||
// GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
|
||||
|
||||
//mask
|
||||
ARBShaderObjects.glUniform1iARB(maskUniform, secondaryTextureUnit);
|
||||
GL20.glUniform1i(maskUniform, secondaryTextureUnit);
|
||||
OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + secondaryTextureUnit);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(ShaderHandler.shaderMaskTextureLocation).getGlTextureId());
|
||||
|
||||
//image
|
||||
ARBShaderObjects.glUniform1iARB(imageUniform, primaryTextureUnit);
|
||||
OpenGlHelper.setActiveTexture(ARBMultitexture.GL_TEXTURE0_ARB + primaryTextureUnit);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).getGlTextureId());
|
||||
|
||||
//blockpos
|
||||
ARBShaderObjects.glUniform3fARB(blockposUniform, (float) blockpos.x, (float) blockpos.y, (float) blockpos.z);
|
||||
ARBShaderObjects.glUniform3fARB(firstposUniform, (float) firstpos.x, (float) firstpos.y, (float) firstpos.z);
|
||||
ARBShaderObjects.glUniform3fARB(secondposUniform, (float) secondpos.x, (float) secondpos.y, (float) secondpos.z);
|
||||
GL20.glUniform3f(blockposUniform, (float) blockpos.x, (float) blockpos.y, (float) blockpos.z);
|
||||
GL20.glUniform3f(firstposUniform, (float) firstpos.x, (float) firstpos.y, (float) firstpos.z);
|
||||
GL20.glUniform3f(secondposUniform, (float) secondpos.x, (float) secondpos.y, (float) secondpos.z);
|
||||
|
||||
//dissolve
|
||||
ARBShaderObjects.glUniform1fARB(percentileUniform, dissolve);
|
||||
GL20.glUniform1f(percentileUniform, dissolve);
|
||||
//highlight
|
||||
ARBShaderObjects.glUniform1iARB(highlightUniform, highlight ? 1 : 0);
|
||||
GL20.glUniform1i(highlightUniform, highlight ? 1 : 0);
|
||||
//red
|
||||
ARBShaderObjects.glUniform1iARB(redUniform, red ? 1 : 0);
|
||||
GL20.glUniform1i(redUniform, red ? 1 : 0);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ public class RenderHandler implements IWorldEventListener {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
// Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(ShaderHandler.shaderMaskTextureLocation);
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
@@ -28,8 +28,9 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class ShaderHandler {
|
||||
|
||||
private static final int VERT_ST = ARBVertexShader.GL_VERTEX_SHADER_ARB;
|
||||
private static final int FRAG_ST = ARBFragmentShader.GL_FRAGMENT_SHADER_ARB;
|
||||
|
||||
private static final int VERT_ST = GL20.GL_VERTEX_SHADER;
|
||||
private static final int FRAG_ST = GL20.GL_FRAGMENT_SHADER;
|
||||
|
||||
private static final int VERT = 1;
|
||||
private static final int FRAG = 2;
|
||||
@@ -54,11 +55,11 @@ public final class ShaderHandler {
|
||||
if(!doUseShaders())
|
||||
return;
|
||||
|
||||
ARBShaderObjects.glUseProgramObjectARB(shader);
|
||||
GL20.glUseProgram(shader);
|
||||
|
||||
if(shader != 0) {
|
||||
int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time");
|
||||
ARBShaderObjects.glUniform1iARB(time, ClientProxy.ticksInGame);
|
||||
int time = GL20.glGetUniformLocation(shader, "time");
|
||||
GL20.glUniform1i(time, ClientProxy.ticksInGame);
|
||||
|
||||
if(callback != null)
|
||||
callback.accept(shader);
|
||||
@@ -74,7 +75,7 @@ public final class ShaderHandler {
|
||||
}
|
||||
|
||||
public static boolean doUseShaders() {
|
||||
return BuildConfig.visuals.useShaders && OpenGlHelper.shadersSupported;
|
||||
return BuildConfig.visuals.useShaders && OpenGlHelper.shadersSupported && OpenGlHelper.openGL21; //Only GL2.1 shaders
|
||||
}
|
||||
|
||||
private static int createProgram(String s, int sides) {
|
||||
@@ -94,24 +95,24 @@ public final class ShaderHandler {
|
||||
if(frag != null)
|
||||
fragId = createShader(frag, FRAG_ST);
|
||||
|
||||
program = ARBShaderObjects.glCreateProgramObjectARB();
|
||||
program = GL20.glCreateProgram();
|
||||
if(program == 0)
|
||||
return 0;
|
||||
|
||||
if(vert != null)
|
||||
ARBShaderObjects.glAttachObjectARB(program, vertId);
|
||||
GL20.glAttachShader(program, vertId);
|
||||
if(frag != null)
|
||||
ARBShaderObjects.glAttachObjectARB(program, fragId);
|
||||
GL20.glAttachShader(program, fragId);
|
||||
|
||||
ARBShaderObjects.glLinkProgramARB(program);
|
||||
if(ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE) {
|
||||
EffortlessBuilding.logger.log(Level.ERROR, getLogInfo(program));
|
||||
GL20.glLinkProgram(program);
|
||||
if(GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
|
||||
EffortlessBuilding.logger.log(Level.ERROR, getProgramLogInfo(program));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ARBShaderObjects.glValidateProgramARB(program);
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB) == GL11.GL_FALSE) {
|
||||
EffortlessBuilding.logger.log(Level.ERROR, getLogInfo(program));
|
||||
GL20.glValidateProgram(program);
|
||||
if (GL20.glGetProgrami(program, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) {
|
||||
EffortlessBuilding.logger.log(Level.ERROR, getProgramLogInfo(program));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -121,28 +122,32 @@ public final class ShaderHandler {
|
||||
private static int createShader(String filename, int shaderType){
|
||||
int shader = 0;
|
||||
try {
|
||||
shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
|
||||
shader = GL20.glCreateShader(shaderType);
|
||||
|
||||
if(shader == 0)
|
||||
return 0;
|
||||
|
||||
ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
|
||||
ARBShaderObjects.glCompileShaderARB(shader);
|
||||
GL20.glShaderSource(shader, readFileAsString(filename));
|
||||
GL20.glCompileShader(shader);
|
||||
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
|
||||
throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
|
||||
if (GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE)
|
||||
throw new RuntimeException("Error creating shader: " + getShaderLogInfo(shader));
|
||||
|
||||
return shader;
|
||||
}
|
||||
catch(Exception e) {
|
||||
ARBShaderObjects.glDeleteObjectARB(shader);
|
||||
GL20.glDeleteShader(shader);
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLogInfo(int obj) {
|
||||
return ARBShaderObjects.glGetInfoLogARB(obj, ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
|
||||
private static String getProgramLogInfo(int program) {
|
||||
return GL20.glGetProgramInfoLog(program, GL20.glGetProgrami(program, GL20.GL_INFO_LOG_LENGTH));
|
||||
}
|
||||
|
||||
private static String getShaderLogInfo(int shader) {
|
||||
return GL20.glGetShaderInfoLog(shader, GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH));
|
||||
}
|
||||
|
||||
private static String readFileAsString(String filename) throws Exception {
|
||||
|
||||
@@ -31,7 +31,9 @@ void main() {
|
||||
float placeFromFirst = length(worldpos - firstposc) / firstToSecond;
|
||||
float placeFromSecond = length(worldpos - secondposc) / firstToSecond;
|
||||
place = (placeFromFirst + (1.0 - placeFromSecond)) / 2.0;
|
||||
} //else only one block
|
||||
} else {
|
||||
//only one block
|
||||
}
|
||||
|
||||
//find 2d texture coordinate for noise texture based on world position
|
||||
vec2 maskcoord = vec2(worldpos.y, worldpos.z);
|
||||
@@ -78,8 +80,8 @@ void main() {
|
||||
// color.rgb += vec3(0.5 - smoothstep(0, 0.5, distToEdge)) * 0.5;
|
||||
|
||||
//add flat shading
|
||||
// if (abs(normal.x) > 0.5)
|
||||
// color.rgb -= 0.0;
|
||||
if (abs(normal.x) > 0.5)
|
||||
color.rgb -= 0.0;
|
||||
if (abs(normal.y) > 0.5)
|
||||
color.rgb += 0.05;
|
||||
if (abs(normal.z) > 0.5)
|
||||
|
||||
Reference in New Issue
Block a user