Skip to content

Instantly share code, notes, and snippets.

View mayant15's full-sized avatar
😶

Mayant Mukul mayant15

😶
View GitHub Profile
private MarketItem buy(MarketItem item) {
if (!walletSystem.isValidTransaction(-1 * item.cost)) {
logger.warn("Insufficient funds");
return item;
} else {
if (!createItemOrBlock(item.name)) {
logger.warn("Failed to create entity");
return item;
}
Iterable<EntityRef> storageBuildings = entityManager.getEntitiesWith(MultiInvStorageComponent.class, SettlementRefComponent.class);
private boolean isValidSpawnPosition(Vector3i pos) {
if (!settlementEntityManager.checkOutsideAllSettlements(new Vector2i(pos.x, pos.z))) {
return false;
}
Vector3i below = new Vector3i(pos.x, pos.y - 1, pos.z);
Block blockBelow = worldProvider.getBlock(below);
if (!blockBelow.equals(sand)) {
return false;
}
Block blockAtPosition = worldProvider.getBlock(pos);
private Block getClosestMatch(byte connections, Side topSide) {
EnumSet<Side> sides = SideBitFlag.getSides(connections);
// Indices represent priorities, 0 being the highest and 6 being the lowest
String[] keys = new String[baseSideBitMap.size()];
keys[0] = FOUR_CONNECTIONS_CROSS;
keys[1] = THREE_CONNECTIONS_T;
keys[2] = ONE_CONNECTIONS_SLOPE;
keys[3] = TWO_CONNECTIONS_CORNER;
keys[4] = TWO_CONNECTIONS_LINE;
keys[5] = ONE_CONNECTION;
private Vector2i clamp(Vector2f point, Rect2f box) {
float x;
float y;
Rect2f iconRegion = Rect2f.createFromMinAndSize(point, iconSize);
if (box.contains(iconRegion)) {
return new Vector2i(point.x, point.y);
} else {
if (iconRegion.maxX() >= box.maxX()) {
x = (int) box.maxX() - iconSize.x;
} else if (iconRegion.minX() <= box.minX()) {
@mayant15
mayant15 / CartRidableAction.java
Last active August 25, 2019 02:00
mounting rails
private void mount(EntityRef cart, EntityRef rider){
CartRidableComponent cartRidableComponent = cart.getComponent(CartRidableComponent.class);
RigidBodyComponent railVehicleRigidBody = cart.getComponent(RigidBodyComponent.class);
if(rider.getComponent(RidingCartComponent.class) != null){
return;
}
if(cartRidableComponent.rider != null){
return;
}
rider.send(new SetMovementModeEvent(MovementMode.NONE));
<?php
/**
* credit to http://99webtools.com/blog/php-simple-captcha-script/
*/
session_start();
$code=sprintf('%04d',rand(0,9999));
$_SESSION["code"]=$code;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 192, 212); // background color cyan
$fg = imagecolorallocate($im, 55, 55, 55); // text color gray
#include <iostream>
class Node {
public:
int data;
Node* parent = NULL;
Node* left = NULL;
Node* right = NULL;
#include <iostream>
#include <string>
#include <vector>
class Node {
public:
int key;
Node* next;
Node(int k, Node* n) {
@mayant15
mayant15 / stacks_queues_template.cpp
Last active September 10, 2018 17:01
An implementation of stacks and queues in C++ with basic pop, push, enqueue, dequeue, size and print
#include <iostream>
class Node {
public:
int key;
Node* next;
Node(int k, Node* n) {
key = k;
@mayant15
mayant15 / .vimrc
Last active December 13, 2018 08:08
My vim config
set exrc
set secure
set nocompatible
filetype off
"set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path were Vundle should install plugins