use of net.minecraft.util.NonNullList in project Skree by Skelril.
the class GoldRushListener method onPlayerInteractEvent.
@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
GoldRushInstance inst = optInst.get();
BlockSnapshot snapshot = event.getTargetBlock();
BlockState state = snapshot.getState();
if (!snapshot.getLocation().isPresent()) {
return;
}
Location<World> targetBlock = snapshot.getLocation().get();
if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
if (!optTileEnt.isPresent()) {
return;
}
TileEntity tileEntity = optTileEnt.get();
Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
if (!optTexts.isPresent()) {
return;
}
List<Text> texts = optTexts.get();
boolean unlocked = false;
String text = texts.get(1).toPlain().toLowerCase();
NonNullList<ItemStack> itemStacks = tf(player).inventory.mainInventory;
for (int i = 0; i < itemStacks.size(); ++i) {
ItemStack is = itemStacks.get(i);
if (is == ItemStack.EMPTY || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
continue;
}
if (text.contains("blue")) {
if (is.getItemDamage() != 1) {
continue;
}
} else if (text.contains("red")) {
if (is.getItemDamage() != 0) {
continue;
}
} else {
continue;
}
unlocked = true;
itemStacks.set(i, ItemStack.EMPTY);
break;
}
if (unlocked) {
tf(player).inventoryContainer.detectAndSendChanges();
texts.set(2, Text.of("Locked"));
texts.set(3, Text.of("- Unlocked -"));
tileEntity.offer(Keys.SIGN_LINES, texts);
}
} else if (state.getType() == BlockTypes.LEVER) {
Task.builder().execute(() -> {
if (inst.checkLevers()) {
inst.completeGame();
}
}).delayTicks(1).submit(SkreePlugin.inst());
} else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
event.setUseItemResult(Tristate.FALSE);
event.setUseBlockResult(Tristate.FALSE);
player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
inst.payPlayer(player);
} else if (!inst.isLocked()) {
if (state.getType() == BlockTypes.STONE_BUTTON) {
inst.tryToStart();
}
}
}
use of net.minecraft.util.NonNullList in project ForestryMC by ForestryMC.
the class ItemStackUtil method containsSets.
/**
* Counts how many full sets are contained in the passed stock
*/
public static int containsSets(NonNullList<ItemStack> set, NonNullList<ItemStack> stock, NonNullList<String> oreDicts, boolean craftingTools) {
int totalSets = 0;
Pair<NonNullList<ItemStack>, NonNullList<String>> condensedRequired = ItemStackUtil.condenseStacks(set, oreDicts);
NonNullList<String> condensedRequiredDicts = condensedRequired.getRight();
NonNullList<ItemStack> condensedRequiredStacks = condensedRequired.getLeft();
NonNullList<ItemStack> condensedOfferedStacks = ItemStackUtil.condenseStacks(stock);
for (int y = 0; y < condensedRequiredStacks.size(); y++) {
ItemStack req = condensedRequiredStacks.get(y);
String offerDict = condensedRequiredDicts.get(y);
int reqCount = 0;
for (int i = 0; i < condensedOfferedStacks.size(); i++) {
ItemStack offer = condensedOfferedStacks.get(i);
if (isCraftingEquivalent(req, offer, offerDict, craftingTools)) {
int stackCount = (int) Math.floor(offer.getCount() / req.getCount());
reqCount = Math.max(reqCount, stackCount);
}
}
if (reqCount == 0) {
return 0;
} else if (totalSets == 0) {
totalSets = reqCount;
} else if (totalSets > reqCount) {
totalSets = reqCount;
}
}
return totalSets;
}
use of net.minecraft.util.NonNullList in project ForestryMC by ForestryMC.
the class TileCocoon method onBlockTick.
public void onBlockTick() {
maturationTime++;
IButterflyGenome caterpillarGenome = caterpillar.getGenome();
int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
if (maturationTime >= caterpillarMatureTime) {
if (age < 2) {
age++;
maturationTime = 0;
IBlockState blockState = world.getBlockState(pos);
world.notifyBlockUpdate(pos, blockState, blockState, 0);
} else if (caterpillar.canTakeFlight(world, getPos().getX(), getPos().getY(), getPos().getZ())) {
NonNullList<ItemStack> cocoonDrops = caterpillar.getCocoonDrop(this);
for (ItemStack drop : cocoonDrops) {
ItemStackUtil.dropItemStackAsEntity(drop, world, pos);
}
world.setBlockToAir(getPos());
attemptButterflySpawn(world, caterpillar, getPos());
}
}
}
use of net.minecraft.util.NonNullList in project Cavern2 by kegare.
the class MiningAssistEventHooks method onBlockBreak.
@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
World world = event.getWorld();
if (world.isRemote) {
return;
}
EntityPlayer player = event.getPlayer();
if (player == null || player instanceof FakePlayer) {
return;
}
BlockPos pos = event.getPos();
MiningAssistUnit assist = MiningAssistUnit.get(player);
if (assist.addExperience(pos, event.getExpToDrop())) {
event.setExpToDrop(0);
}
if (breaking) {
return;
}
if (!(player instanceof EntityPlayerMP)) {
return;
}
IBlockState state = event.getState();
if (!isActive(player, state)) {
return;
}
MiningAssist type = MiningAssist.byPlayer(player);
MiningSnapshot snapshot = assist.getSnapshot(type, pos, state);
if (snapshot.isEmpty()) {
return;
}
PlayerInteractionManager im = ((EntityPlayerMP) player).interactionManager;
assist.captureDrops(MiningAssistConfig.collectDrops);
assist.captureExperiences(MiningAssistConfig.collectExps);
breaking = true;
for (BlockPos target : snapshot.getTargets()) {
if (snapshot.validTarget(target) && !harvestBlock(im, target)) {
break;
}
}
breaking = false;
Map<BlockPos, NonNullList<ItemStack>> drops = assist.captureDrops(false);
if (drops != null && !drops.isEmpty()) {
for (NonNullList<ItemStack> items : drops.values()) {
for (ItemStack stack : items) {
Block.spawnAsEntity(world, pos, stack);
}
}
}
Map<BlockPos, Integer> experiences = assist.captureExperiences(false);
if (experiences != null && !experiences.isEmpty() && !im.isCreative() && world.getGameRules().getBoolean("doTileDrops")) {
int exp = experiences.values().stream().mapToInt(Integer::intValue).sum();
while (exp > 0) {
int i = EntityXPOrb.getXPSplit(exp);
exp -= i;
world.spawnEntity(new EntityXPOrb(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, i));
}
}
}
use of net.minecraft.util.NonNullList in project Binnie by ForestryMC.
the class ItemSerum method getSubItems.
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (this.isInCreativeTab(tab)) {
for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
Map<IChromosomeType, List<IAllele>> chromosomeMap = Binnie.GENETICS.getChromosomeMap(root);
if (chromosomeMap != null) {
for (Map.Entry<IChromosomeType, List<IAllele>> entry : chromosomeMap.entrySet()) {
IChromosomeType chromosome = entry.getKey();
for (final IAllele allele : entry.getValue()) {
Gene gene = Gene.create(allele, chromosome, root);
IGeneItem geneItem = new GeneItem(gene);
ItemStack stack = new ItemStack(this);
geneItem.writeToItem(stack);
items.add(stack);
}
}
}
}
}
}
Aggregations