use of org.spongepowered.asm.mixin.Overwrite in project Almura by AlmuraDev.
the class MixinBlockTallGrass method getDrops.
/**
* @author Zidane - Chris Sanders
* @reason Add in content seeds to drop list for Tall Grass
*/
@Overwrite(remap = false)
public void getDrops(final NonNullList<ItemStack> drops, final IBlockAccess access, final BlockPos pos, final IBlockState state, final int fortune) {
World world;
if (access instanceof ChunkCache) {
world = ((ChunkCache) access).world;
} else if (access instanceof World) {
world = (World) access;
} else {
return;
}
final Random random = world.rand;
// Roll 1 is Vanilla's 1/8 chance to drop a seed
final int roll1 = random.nextInt(8);
if (roll1 == 0) {
// Forge Start - Lookup seed each time and then do random check. Almura handles its own chance code
final ItemStack modSeed = net.minecraftforge.common.ForgeHooks.getGrassSeed(random, fortune);
if (!modSeed.isEmpty()) {
drops.add(modSeed);
// Don't double up with Vanilla/mod drops
return;
}
final Biome biome = world.getBiome(pos);
// Roll 2 is shuffling Almura seeds and picking the first one after shuffling
registry.getAllOf(ItemType.class).stream().filter(itemType -> itemType instanceof SeedItem && ((SeedItem) itemType).getGrass() != null).collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
Collections.shuffle(collected);
return collected.stream();
})).findFirst().ifPresent((itemType) -> {
final SeedItem seed = (SeedItem) itemType;
final IntRange amountRange = seed.getGrass().getOrLoadAmountRequiredRangeForBiome(biome);
if (amountRange != null) {
final int stackSize = amountRange.random(random);
final DoubleRange chanceRange = seed.getGrass().getOrLoadChanceRangeForBiome(biome);
if (chanceRange != null) {
final double chance = chanceRange.random(random);
// Roll 3 is allowing the seed configuration to determine the chance for the drop
if (random.nextDouble() <= (chance / 100)) {
drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
}
} else {
drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
}
}
});
}
// Almura End
}
use of org.spongepowered.asm.mixin.Overwrite in project Almura by AlmuraDev.
the class MixinTileEntitySignRenderer method render.
/**
* @author Grinch - Steven Downer
* @reason Do not render signposts past a configurable length. Fairly decent client optimization.
*/
@Overwrite
public void render(TileEntitySign te, double x, double y, double z, float partialTicks, int destroyStage, float val) {
final ClientConfiguration config = StaticAccess.config.get();
Block block = te.getBlockType();
GlStateManager.pushMatrix();
float f = 0.6666667F;
if (block == Blocks.STANDING_SIGN) {
GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
float f1 = (float) (te.getBlockMetadata() * 360) / 16.0F;
GlStateManager.rotate(-f1, 0.0F, 1.0F, 0.0F);
this.model.signStick.showModel = true;
} else {
int k = te.getBlockMetadata();
float f2 = 0.0F;
if (k == 2) {
f2 = 180.0F;
}
if (k == 4) {
f2 = 90.0F;
}
if (k == 5) {
f2 = -90.0F;
}
GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
GlStateManager.rotate(-f2, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(0.0F, -0.3125F, -0.4375F);
this.model.signStick.showModel = false;
}
if (destroyStage >= 0) {
this.bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 2.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888);
} else {
this.bindTexture(SIGN_TEXTURE);
}
GlStateManager.enableRescaleNormal();
GlStateManager.pushMatrix();
GlStateManager.scale(0.6666667F, -0.6666667F, -0.6666667F);
this.model.renderSign();
GlStateManager.popMatrix();
FontRenderer fontrenderer = this.getFontRenderer();
float f3 = 0.010416667F;
GlStateManager.translate(0.0F, 0.33333334F, 0.046666667F);
GlStateManager.scale(0.010416667F, -0.010416667F, 0.010416667F);
GlStateManager.glNormal3f(0.0F, 0.0F, -0.010416667F);
GlStateManager.depthMask(false);
int i = 0;
// Almura start
boolean renderText = te.signText.length > 0;
if (renderText) {
// Greater than 0 means the client has selected a non-Vanilla render distance
if (config.client.signTextRenderDistance > 0) {
EntityLivingBase viewer = (EntityLivingBase) Minecraft.getMinecraft().getRenderViewEntity();
if (viewer == null) {
viewer = Minecraft.getMinecraft().player;
}
if (viewer == null || !te.hasWorld() || te.getDistanceSq(viewer.posX, viewer.posY, viewer.posZ) > (config.client.signTextRenderDistance * 16)) {
renderText = false;
}
}
}
if (renderText && destroyStage < 0) {
// Almura End
for (int j = 0; j < te.signText.length; ++j) {
if (te.signText[j] != null) {
ITextComponent itextcomponent = te.signText[j];
List<ITextComponent> list = GuiUtilRenderComponents.splitText(itextcomponent, 90, fontrenderer, false, true);
String s = list != null && !list.isEmpty() ? ((ITextComponent) list.get(0)).getFormattedText() : "";
if (j == te.lineBeingEdited) {
s = "> " + s + " <";
fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, 0);
} else {
fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, 0);
}
}
}
}
GlStateManager.depthMask(true);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
if (destroyStage >= 0) {
GlStateManager.matrixMode(5890);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
}
}
use of org.spongepowered.asm.mixin.Overwrite in project Almura by AlmuraDev.
the class MixinBiomeColorHelper method getColorAtPos.
/**
* @author Zidane - Chris Sanders
* @reason Have water respect our config
*/
@Overwrite
private static int getColorAtPos(IBlockAccess blockAccess, BlockPos pos, BiomeColorHelper.ColorResolver colorResolver) {
int i = 0;
int j = 0;
int k = 0;
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-1, 0, -1), pos.add(1, 0, 1))) {
final Biome biome = blockAccess.getBiome(blockpos$mutableblockpos);
int l;
if (colorResolver == BiomeColorHelper.WATER_COLOR) {
final BiomeChunk biomeChunk = BiomeUtil.getChunk(blockpos$mutableblockpos);
if (biomeChunk == null) {
l = colorResolver.getColorAtPos(biome, blockpos$mutableblockpos);
} else {
l = biomeChunk.getWaterColor(pos, biome);
}
} else {
l = colorResolver.getColorAtPos(biome, blockpos$mutableblockpos);
}
i += (l & 16711680) >> 16;
j += (l & 65280) >> 8;
k += l & 255;
}
return (i / 9 & 255) << 16 | (j / 9 & 255) << 8 | k / 9 & 255;
}
use of org.spongepowered.asm.mixin.Overwrite in project Almura by AlmuraDev.
the class MixinBlockFarmland method updateTick.
/**
* @author Dockter - Mike Howe
* @reason Prevent farmland "decay" into dirt based on property
*/
@Override
@Overwrite
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
final Random random = new Random();
int soilMoisture = ((Integer) state.getValue(MOISTURE)).intValue();
int revertChance = random.nextInt(25);
if (!this.hasWater(worldIn, pos) && !worldIn.isRainingAt(pos.up()) && !(worldIn.getBiomeForCoordsBody(pos).getRainfall() > 0.5)) {
// Add Biome rainfall.
if (soilMoisture > 0 && revertChance == 1) {
// Slow down the revert to account for longer lasting rain.
worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(soilMoisture - 1)), 2);
} else if (!this.hasCrops(worldIn, pos)) {
// ToDo: We need a hook into GP for a Soil Flag like we did with Res-Protect.
// turnToDirt(worldIn, pos);
}
} else if (soilMoisture < 7) {
worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(7)), 2);
}
}
use of org.spongepowered.asm.mixin.Overwrite in project Almura by AlmuraDev.
the class MixinBlockVine method updateTick.
/**
* @author Dockter - Mike Howe
* @reason Don't tick vines in Orilla
*/
// TODO: There must be a better way to do this.
@Overwrite
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
if (!worldIn.isRemote) {
if (// Specifically for Orilla only at the moment.
worldIn.rand.nextInt(4) == 0 && !worldIn.getWorldInfo().getWorldName().equalsIgnoreCase("orilla")) {
int i = 4;
int j = 5;
boolean flag = false;
label181: for (int k = -4; k <= 4; ++k) {
for (int l = -4; l <= 4; ++l) {
for (int i1 = -1; i1 <= 1; ++i1) {
if (worldIn.getBlockState(pos.add(k, i1, l)).getBlock() == this) {
--j;
if (j <= 0) {
flag = true;
break label181;
}
}
}
}
}
EnumFacing enumfacing1 = EnumFacing.random(rand);
BlockPos blockpos2 = pos.up();
if (enumfacing1 == EnumFacing.UP && pos.getY() < 255 && worldIn.isAirBlock(blockpos2)) {
IBlockState iblockstate2 = state;
for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL) {
if (rand.nextBoolean() && this.canAttachTo(worldIn, blockpos2, enumfacing2.getOpposite())) {
iblockstate2 = iblockstate2.withProperty(getPropertyFor(enumfacing2), Boolean.valueOf(true));
} else {
iblockstate2 = iblockstate2.withProperty(getPropertyFor(enumfacing2), Boolean.valueOf(false));
}
}
if (((Boolean) iblockstate2.getValue(NORTH)).booleanValue() || ((Boolean) iblockstate2.getValue(EAST)).booleanValue() || ((Boolean) iblockstate2.getValue(SOUTH)).booleanValue() || ((Boolean) iblockstate2.getValue(WEST)).booleanValue()) {
worldIn.setBlockState(blockpos2, iblockstate2, 2);
}
} else if (enumfacing1.getAxis().isHorizontal() && !((Boolean) state.getValue(getPropertyFor(enumfacing1))).booleanValue()) {
if (!flag) {
BlockPos blockpos4 = pos.offset(enumfacing1);
IBlockState iblockstate3 = worldIn.getBlockState(blockpos4);
Block block1 = iblockstate3.getBlock();
if (block1.getMaterial(iblockstate3) == Material.AIR) {
EnumFacing enumfacing3 = enumfacing1.rotateY();
EnumFacing enumfacing4 = enumfacing1.rotateYCCW();
boolean flag1 = ((Boolean) state.getValue(getPropertyFor(enumfacing3))).booleanValue();
boolean flag2 = ((Boolean) state.getValue(getPropertyFor(enumfacing4))).booleanValue();
BlockPos blockpos = blockpos4.offset(enumfacing3);
BlockPos blockpos1 = blockpos4.offset(enumfacing4);
if (flag1 && this.canAttachTo(worldIn, blockpos.offset(enumfacing3), enumfacing3)) {
worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing3), Boolean.valueOf(true)), 2);
} else if (flag2 && this.canAttachTo(worldIn, blockpos1.offset(enumfacing4), enumfacing4)) {
worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing4), Boolean.valueOf(true)), 2);
} else if (flag1 && worldIn.isAirBlock(blockpos) && this.canAttachTo(worldIn, blockpos, enumfacing1)) {
worldIn.setBlockState(blockpos, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
} else if (flag2 && worldIn.isAirBlock(blockpos1) && this.canAttachTo(worldIn, blockpos1, enumfacing1)) {
worldIn.setBlockState(blockpos1, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
}
} else if (iblockstate3.getBlockFaceShape(worldIn, blockpos4, enumfacing1) == BlockFaceShape.SOLID) {
worldIn.setBlockState(pos, state.withProperty(getPropertyFor(enumfacing1), Boolean.valueOf(true)), 2);
}
}
} else {
if (pos.getY() > 1) {
BlockPos blockpos3 = pos.down();
IBlockState iblockstate = worldIn.getBlockState(blockpos3);
Block block = iblockstate.getBlock();
if (block.getMaterial(iblockstate) == Material.AIR) {
IBlockState iblockstate1 = state;
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) {
if (rand.nextBoolean()) {
iblockstate1 = iblockstate1.withProperty(getPropertyFor(enumfacing), Boolean.valueOf(false));
}
}
if (((Boolean) iblockstate1.getValue(NORTH)).booleanValue() || ((Boolean) iblockstate1.getValue(EAST)).booleanValue() || ((Boolean) iblockstate1.getValue(SOUTH)).booleanValue() || ((Boolean) iblockstate1.getValue(WEST)).booleanValue()) {
worldIn.setBlockState(blockpos3, iblockstate1, 2);
}
} else if (block == this) {
IBlockState iblockstate4 = iblockstate;
for (EnumFacing enumfacing5 : EnumFacing.Plane.HORIZONTAL) {
PropertyBool propertybool = getPropertyFor(enumfacing5);
if (rand.nextBoolean() && ((Boolean) state.getValue(propertybool)).booleanValue()) {
iblockstate4 = iblockstate4.withProperty(propertybool, Boolean.valueOf(true));
}
}
if (((Boolean) iblockstate4.getValue(NORTH)).booleanValue() || ((Boolean) iblockstate4.getValue(EAST)).booleanValue() || ((Boolean) iblockstate4.getValue(SOUTH)).booleanValue() || ((Boolean) iblockstate4.getValue(WEST)).booleanValue()) {
worldIn.setBlockState(blockpos3, iblockstate4, 2);
}
}
}
}
}
}
}
Aggregations